How to remove markers if they clustered? Because if they are grouped, you cannot delete. But as soon as the grouping disappears, then everything is fine.
Before trying to delete:
After successful deletion:
Code for add markers:
var markers = L.markerClusterGroup();
map.addLayer(markers);
L.geoJSON(data, {
pointToLayer: pointToLayer,
onEachFeature: onEachFeature,
})
.on('click', markerOnClick)
.addTo(markers);
Code for delete markers:
$.each(markers._map._layers, function (ml) {
if (markers._map._layers[ml].feature) {
if(markers._map._layers[ml].feature.properties.obj == 2 && markers._map._layers[ml].feature.properties.type == 1){
markers.removeLayer(this);
}
}
});

