1

我的应用程序中有以下代码,所有标记都添加到一个组中。我希望集群中未折叠的标记弹出窗口在加载地图时显示弹出窗口。(当地图以该缩放级别加载时,属于集群的一部分但未在特定缩放级别上折叠到集群中的标记)

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() 方法,在加载地图时打开弹出窗口,单击标记时打开。请帮忙。

4

1 回答 1

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();
});
于 2017-10-10T07:03:38.233 回答