1 | initial version |
To remove all markers and layers from a Leaflet map, you can use the following steps:
Example code:
var map = L.map('map');
map.clearLayers(); //Remove all existing layers and markers
// Create new layers and markers
var marker = L.marker([51.5, -0.09]).addTo(map);
var polyline = L.polyline([[51.5, -0.09], [51.3, -0.1]]).addTo(map);
Note: If you have multiple layers and markers that you want to remove, you can use the getLayers() method on the map object to retrieve all existing layers, and then remove them one by one using the removeLayer() method.