I'd like to click on a button in a sidebar outside a Leaflet map and remove a marker associated with that button. But when I bulk add data through L.geoJSON
, the function appears to not create individual variables for markers, making it impossible to simply use .remove(map)
on that variable / marker.
The geoJSON looks like this:
var places = {"type": "FeatureCollection", "features": [{"id": "0", "type": "Feature", "properties": {"WIKIPEDIA": "Beni Department"}, "geometry": {"type": "Point", "coordinates": [-65.683972, -15.43334]}}, {"id": "1", "type": "Feature", "properties": {"WIKIPEDIA": "Bluefish Caves"}, "geometry": {"type": "Point", "coordinates": [-140.518611, 64.135278]}}]}
I've tried dynamically associating a variable with each marker by doing this:
geojson = L.geoJSON(places, {
pointToLayer: function (feature, latlng) {
var "_" + String(feature.id) + "_" = L.circleMarker(latlng, geojsonMarkerOptions);
return L.circleMarker(latlng, geojsonMarkerOptions);
}
}).addTo(map);
But that gives me a SyntaxError: missing variable name
.