I'm still new to Leaflet and have been trying to add a GeoJSON file to a Leaflet map. I've checked the GeoJSON file using geojson.io and it loads there but not in my Leaflet map. I've looked at the answers here: (Adding local GeoJSON files to Leaflet web page) with no success. I have no idea where I'm going wrong!
Here's the link to my map: http://www.huskey.gisdenver.co/map6.html
1st problem code:
var mydata;
$.getJSON("classes_4326.geojson", function(data) {mydata = data;});
var landcov = L.geoJSON(mydata,
{style: function(feature) {
switch (feature.properties.landcover) {
case 'agriculture': return {color: "#32CD32"};
case 'grassland': return {color: "#C51C0F"};
case 'water': return {color: "#1E90FF"};
case 'wetlands': return {color: "#314004"};
}
}, onEachFeature: onEachFeature
}).addTo(map);
As @TomazicM commented, it should have been formatted like this:
$.getJSON("classes_4326.geojson", function(data) {
var landcov = L.geoJSON(data,
{style: function(feature) {
switch (feature.properties.landcover) {
case 'agriculture': return {color: "#32CD32"};
case 'grassland': return {color: "#C51C0F"};
case 'water': return {color: "#1E90FF"};
case 'wetlands': return {color: "#314004"};
}
}, onEachFeature: onEachFeature
}).addTo(map);
@TomazicM's sharp eyes spotted that I was missing the closing
});
for the
$(document).ready
function at the end of the code.
});
for$(document).ready
function at the and of the code.