如果它们聚集在一起,如何删除标记?因为如果它们是分组的,则不能删除。但一旦分组消失,一切就都好了。
在尝试删除之前:

在成功删除后:

添加标记代码:
var markers = L.markerClusterGroup();
map.addLayer(markers);
L.geoJSON(data, {
pointToLayer: pointToLayer,
onEachFeature: onEachFeature,
})
.on('click', markerOnClick)
.addTo(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);
}
}
});发布于 2021-02-24 09:04:56
只需在您的eachLayer method标记集群组上使用markers来迭代每个子标记(不管它们当前是否是集群的)。
markers.eachLayer(layer => {
if(layer.feature.properties.obj == 2 && layer.feature.properties.type == 1) {
markers.removeLayer(layer);
}
});当访问markers._map._layers时,您将查找映射中当前的每个层,但是当标记被集群时,Leaflet.markercluster会删除它们(取而代之的是集群标记)。这就是为什么你再也找不到一些标记了。
https://stackoverflow.com/questions/66345788
复制相似问题