作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以显示集群标记的内容,但无法显示单个标记的内容。
请找到下面的代码,其中 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/
我可以显示集群标记的内容,但无法显示单个标记的内容。 请找到下面的代码,其中 else 语句将处理单个标记。 map.eachLayer(function(marker) { if (mark
我可以显示集群标记的内容,但无法显示单个标记的内容。 请找到下面的代码,其中 else 语句将处理单个标记。 map.eachLayer(function(marker) { if (mark
我正在尝试做一些与 Chris Essig 所做的非常相似的事情 here 。因为我需要知道在用户放下“trashMarker”的地方 20 米半径内有多少个数据点。 到目前为止我已经得到了这段代码:
我是一名优秀的程序员,十分优秀!