Reputation: 33
I'm struggling with making my GeoJSON points to show up on leaflet map.
The codes for the javascript where I tried to add in the GeoJSON:
var coniferous = L.layerGroup();
var geojsondata = new L.GeoJSON.AJAX("treedata2.geojson", {
pointToLayer: function(geoJsonPoint, latlng) {return L.marker(latlng);}}).addTo(coniferous);
I have already referenced the ajax plugin in the head section of the html file
<script src="leaflet.ajax.js"></script>
The GeoJSON file code is as follow
{
"type": "FeatureCollection",
"name": "Significant Trees",
"features": [
{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-79.484593, 43.696533, 0.0]}, "properties": {"What_is_the_species_name": "Maple"}},
{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-79.433099, 43.846487, 0.0]}, "properties": {"What_is_the_species_name": "Pine"}}
]
}
I have also tried to coordsToLatLng but it doesn't seem to be the problem as the markers don't still show up at all, not even in the wrong locations.
Upvotes: 2
Views: 1016
Reputation: 11338
You need to add the LayerGroup to the map: var coniferous = L.layerGroup().addTo(map);
Upvotes: 2