I use markercluster
var markers = L.markerClusterGroup()
/* delete method */
map.eachLayer(function(layer) {
if (layer instanceof L.MarkerClusterGroup)
{
map.removeLayer(layer)
}
})
dataset.forEach(function(item)
{
var marker = L.marker(item.coordinates, {
icon: L.divIcon({
html: `<div><span>1</span></div>`,
className: 'leaflet-div-icon'
})
})
markers.addLayer(marker)
})
map.addLayer(markers)
There is an easier way:
markers.clearLayers()