简体   繁体   English

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

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

I have a leaflet application at http://atlantaartmap.com . 我在http://atlantaartmap.com上有一个传单应用程序。 The javascript it uses is http://atlantaartmap.com/lazy_art.js . 它使用的JavaScript是http://atlantaartmap.com/lazy_art.js

At line 16, I grab a url parameter that can be used to open the map on a specific piece. 在第16行,我获取了一个url参数,该参数可用于打开特定部分上的地图。 While creating the markers, there is a piece of code at line 71 that checks to see if the most recently created marker has the ID referred to in the URL. 在创建标记时,第71行有一段代码用于检查最近创建的标记是否具有URL中引用的ID。

This code used to work, but I recently added marker clusters to the website and it no longer does. 这段代码曾经可以使用,但是最近我在网站上添加了标记簇,现在不再可用。 It still pans and zooms to the marker, but the popup does not open. 它仍然可以平移并缩放到标记,但是不会打开弹出窗口。 Here is an example. 这是一个例子。

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

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

I'm not sure why, but map.setView() works and marker.openPopup() doesn't. 我不确定为什么,但是map.setView()可以工作,而marker.openPopup()不能。

Any ideas? 有任何想法吗? Thanks in advance. 提前致谢。

My guess (am unable to test this) is that your map is still zooming while you call openPopup on the marker. 我的猜测(我无法测试)是,当您在标记上调用openPopup ,地图仍在缩放。 At that time the marker isn't added to the map yet because of your cluster so the popup won't show. 那时由于您的集群,标记尚未添加到地图,因此不会显示弹出窗口。 You could try to wait untill the setView method has completed by listening to the zoomend event and then open the popup: 您可以尝试通过侦听zoomend事件,等到setView方法完成后再打开弹出窗口:

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

If that won't work you can try to use a little delay with setTimeout : 如果那行不通,您可以尝试对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
    });
}

Another option could be to wait for the marker's add event: 另一种选择是等待标记的add事件:

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

Hope that helps, as said am unable to test this due to the complexity of your case so i'm not sure. 希望能有所帮助,如前所述,由于您案件的复杂性而无法测试,因此我不确定。 Good luck! 祝好运!

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

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