【问题标题】:leaflet markercluster open popup on load传单markercluster在加载时打开弹出窗口
【发布时间】:2018-03-17 22:20:49
【问题描述】:

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

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

【问题讨论】:

    标签: javascript leaflet leaflet.markercluster


    【解决方案1】:

    我找到了一个解决方案,诀窍是先将集群组添加到地图中,然后将标记添加到组中,然后在标记上调用 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();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-22
      相关资源
      最近更新 更多