To remove a marker from a LeafletJS map, you can use the marker.remove()
function. For example, the following code removes a marker from the map:
1 | var marker = L.marker([51.505, -0.09]); |
You can also remove a marker from a LeafletJS map by removing the layer that contains the marker. For example, the following code removes a marker from the map by removing the layer that contains the marker:
1 | var markerLayer = L.marker([51.505, -0.09]); |
Which method you use to remove a marker from the map depends on how you added the marker to the map. If you added the marker directly to the map, you should use the marker.remove()
function. If you added the marker to a layer, you should remove the layer from the map.
You can learn more about removing markers from LeafletJS maps from the LeafletJS documentation.