gpt4 book ai didi

leaflet - 如何使用传单的 map.eachLayer 查找标记?

转载 作者:行者123 更新时间:2023-12-02 00:38:54 25 4
gpt4 key购买 nike

我可以显示集群标记的内容,但无法显示单个标记的内容。

请找到下面的代码,其中 else 语句将处理单个标记。

map.eachLayer(function(marker) {  
if (marker.getChildCount) { // to get cluster marker details
console.log('cluster length ' + marker.getAllChildMarkers().length);
} else {
// how to display the contents of a single marker ??

alert(marker.options.title); // doesn't work
}

谢谢。

最佳答案

请记住,map.eachLayer() 适用于 map 的每个 层。这包括弹出窗口和 map 图 block 层,以及标记和标记簇。并非所有这些类型的图层都具有与标记或群集相同的选项。您将需要测试以检查每一层是否是标记、集群或其他东西。另外,请记住,标记不一定具有标题集。

这对我有用:

map.eachLayer(function(layer) {
if(layer.options && layer.options.pane === "markerPane") {
alert("Marker [" + layer.options.title + "]");
}
});

关于leaflet - 如何使用传单的 map.eachLayer 查找标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48049901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com