In my leaflet map when a user clicks on a marker it populates a table elsewhere in the page with a table of attribute fields. I want to also have a button that would allow the user to delete the marker from the map. To do this I am aiming to write the current feature id and layer name to global variables whenever a scheme is clicked. This will then be used by the button to remove the selected feature from the map.
How do I retrieve these meta attributes from a marker click event? I can retrieve the attribute information easily as shown below:
layer.on('click', function (e) {
globalVariable = e.feature.properties.name
}
Save the marker object on click:
layer.on('click', function(e) {
clickedMarker = e.target;
});
Then you can simply use
clickedMarker.removeFrom(map);
or one if its variants after checking that clickedMarker
is actually a marker and is currently on the map.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.