简体   繁体   English

如何通过 Leaflet.MarkerClusterGroup 中的 ID 删除标记

[英]How to REMOVE a marker by ID in Leaflet.MarkerClusterGroup

I have no idea how to remove a marker with particular id in a clusterGroup layer.我不知道如何删除 clusterGroup 层中具有特定 id 的标记。 I have tried to remove the marker with map.removeLayer(marker[id]) and which is not working in a clustergroup.我试图用map.removeLayer(marker[id])删除标记,但它在集群组中不起作用。 I have done a simple Jsfiddle app here which shown the problem of removing particular marker with id.我在这里做了一个简单的 Jsfiddle 应用程序,它显示了删除带有 id 的特定标记的问题。 The id assigned for each marker is using object method.为每个标记分配的 id 使用 object 方法。

Wish to get help from anyone and any help is appreciate.希望得到任何人的帮助,我们将不胜感激。 Thank you.谢谢你。

app -> https://jsfiddle.net/wesleylim97/y76gbjq2/30/应用程序 -> https://jsfiddle.net/wesleylim97/y76gbjq2/30/

Remove the markers from the cluster group, instead of removing them from the map.从集群组中删除标记,而不是从 map 中删除它们。

So if you're doing...所以如果你在做...

clustergroup.addLayer(marker)

...or... ...要么...

marker.addTo(clustergroup)

...to add the marker, then the opposite action is... ...添加标记,则相反的操作是...

clustergroup.removeLayer(marker)

...or... ...要么...

marker.removeFrom(clustergroup)

Note that removeLayer is explicitly mentioned in the Leaflet.MarkerCluster documentation .请注意, Leaflet.MarkerCluster 文档中明确提到了removeLayer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM