2017-10-06 87 views
1

我的应用程序中有以下代码,所有标记都添加到一个组中。我希望在加载地图时,群集中未折叠的标记弹出窗口显示它们的弹出窗口。 (标记,其是群集的一部分,但不折叠成集群上的特定缩放级别,当映射在该缩放等级加载)传单markercluster加载时打开弹出框

var markers = [{ 
     "latLong": [57.67, -3.89] 
     }, 
    { 
     "latLong": [-4.4, -58.34] 
     }, 
    { 
     "latLong": [35.79, 139.48] 
     }], 
markerGroup = L.markerClusterGroup(), 
marker; 

markers.forEach(function (markerConfig, index) { 

marker = new L.Marker(new L.LatLng(markerConfig.latLong[0], markerConfig.latLong[1])); 
marker.bindPopup(index, { 
    "autoClose": false, 
    "closeOnClick": false 
}).openPopup(); 
markerGroup.addLayer(marker); 
}); 

clusterMap.addLayer(markerGroup); 

我想上标记的openPopup()方法,以打开弹出当加载地图时,它会在点击标记时打开。请帮忙。

回答

0

我找到了一个解决方案,诀窍是首先将群集添加到地图,然后将标记添加到该群组,然后在标记上调用openPopup。所以这只是一个调用函数的顺序问题。

var markers = [{ 
      "latLong": [57.67, -3.89] 
      }, 
     { 
      "latLong": [-4.4, -58.34] 
      }, 
     { 
      "latLong": [35.79, 139.48] 
     }], 
    markerGroup = L.markerClusterGroup(), 
    marker; 
clusterMap.addLayer(markerGroup); 

markers.forEach(function (markerConfig, index) { 
    marker = new L.Marker(new L.LatLng(markerConfig.latLong[0], markerConfig.latLong[1])); 
    markerGroup.addLayer(marker); 
    marker.bindPopup(index, { 
     "autoClose": false, 
     "closeOnClick": flase 
    }).openPopup(); 
});