Leaflet 如何使用map.eachLayer传单查找标记?

Leaflet 如何使用map.eachLayer传单查找标记?,leaflet,marker,Leaflet,Marker,我能够显示群集标记的内容,但无法显示单个标记的内容 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

我能够显示群集标记的内容,但无法显示单个标记的内容

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
   }
请查找下面的代码,其中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.eachLayer(function(layer) {
    if(layer.options && layer.options.pane === "markerPane") {
        alert("Marker [" + layer.options.title + "]");
    }
});

适用于我:如果您仍然需要帮助,请确保提供。您的描述帮助我理解并解决了我的问题。谢谢你,很高兴能帮上忙。事后来看,
if(L.Marker的层实例)
可能是一个更好的测试。