繁体   English   中英

由于使用了markercluster,因此使用url参数打开小叶标记无法正常工作

[英]Open leaflet marker using url parameter not working now that markercluster is used

我在http://atlantaartmap.com上有一个传单应用程序。 它使用的JavaScript是http://atlantaartmap.com/lazy_art.js

在第16行,我获取了一个url参数,该参数可用于打开特定部分上的地图。 在创建标记时,第71行有一段代码用于检查最近创建的标记是否具有URL中引用的ID。

这段代码曾经可以使用,但是最近我在网站上添加了标记簇,现在不再可用。 它仍然可以平移并缩放到标记,但是不会打开弹出窗口。 这是一个例子。

http://atlantaartmap.com/index.html?piece=40

if (marker.feature.properties.pieceID == pieceID) {
    map.setView(marker.getLatLng(), newZoom());
    marker.openPopup();
}

我不确定为什么,但是map.setView()可以工作,而marker.openPopup()不能。

有任何想法吗? 提前致谢。

我的猜测(我无法测试)是,当您在标记上调用openPopup ,地图仍在缩放。 那时由于您的集群,标记尚未添加到地图,因此不会显示弹出窗口。 您可以尝试通过侦听zoomend事件,等到setView方法完成后再打开弹出窗口:

if (marker.feature.properties.pieceID == pieceID) {
    map.setView(marker.getLatLng(), newZoom()).once('zoomend', function () {
        marker.openPopup();
    });
}

如果那行不通,您可以尝试对setTimeout稍加延迟:

if (marker.feature.properties.pieceID == pieceID) {
    map.setView(marker.getLatLng(), newZoom()).once('zoomend', function () {
        setTimeout(function () {
            marker.openPopup();
        }, 500); // Uses millisecs, you might need to fiddle around with it
    });
}

另一种选择是等待标记的add事件:

if (marker.feature.properties.pieceID == pieceID) {
    marker.once('add', function () {
        marker.openPopup();
    });
    map.setView(marker.getLatLng(), newZoom());
}

希望能有所帮助,如前所述,由于您案件的复杂性而无法测试,因此我不确定。 祝好运!

暂无
暂无

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

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