简体   繁体   English

传单标记集群在加载时打开弹出窗口

[英]leaflet markercluster open popup on load

I have the following code in my application and all markers are added to one group.I want the marker popups which are not collapsed in the cluster to show popup on them when the map is loaded. 我的应用程序中包含以下代码,并且所有标记都添加到一个组中。我希望未加载到群集中的标记弹出窗口在加载地图时在其上显示弹出窗口。 (markers which are part of the cluster but not collapsed into cluster on a particular zoom level, when the map is loaded at that zoom level) (当标记以特定缩放级别加载时,属于聚类的一部分但未折叠到特定缩放级别上的聚类的标记)

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);

I want the openPopup() method on marker, to open the popup when map is loaded, it opens when marker is clicked. 我想要标记的openPopup()方法在加载地图时打开弹出窗口,在单击标记时将其打开。 Please help. 请帮忙。

I found a solution to this, the trick was to add the cluster group to the map first and then add the markers to the group and then call openPopup on the markers. 我找到了解决方案,诀窍是先将群集组添加到地图,然后将标记添加到组,然后在标记上调用openPopup。 So it was just a matter of sequence of calling the functions. 因此,这只是调用函数的顺序问题。

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();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM