简体   繁体   English

第二次单击标记时,单张弹出窗口不会打开

[英]Leaflet popup does not open on the second click on the marker

I am using leaflet.js to display markers on a OSM map. 我正在使用leaflet.js在OSM地图上显示标记。

The problem is, that the first time a marker is clicked, the popup opens normally, but on a second click on the same marker the popup does not open anymore. 问题是,第一次单击标记时,弹出窗口会正常打开,但是在第二次单击同一标记时,弹出窗口不再打开。

PS: Anywhere else in the code I close popups (with the closePopup() function). PS:代码中的其他任何地方我关闭弹出窗口(使用closePopup()函数)。 In the block below i even commented out the explicit closing of other popups once a marker is clicked. 在下面的块中,我甚至在点击标记时注释掉了其他弹出窗口的明确关闭。
PPS: My application runs on Ruby on Rails (ruby-1.9.3, Rails 3.2.16), and uses leaflet-rails (0.7.2) PPS:我的应用程序在Ruby on Rails上运行(ruby-1.9.3,Rails 3.2.16),并使用leaflet-rails(0.7.2)

bindListeners = function(marker){
    marker.on('click', function(evt) {  

        //resize all markers' icons to default size
        for (i=0;i<markersOfTheMap.length;i++) {
            resizeMarkerIcon(markersOfTheMap[i], false);
        }
              //map.closePopup();

        var infoBoxContent = buildInfoboxHtml(marker);

        marker.bindPopup(infoBoxContent, {className: 'click-popup'}, {closeOnClick: false});
        resizeMarkerIcon(marker, true);
        marker.openPopup();


        var popup = marker.getPopup(); // returns marker._popup
        popup._isOpen = true; 
        console.log("is popup open? " +popup._isOpen); // true
        popupsTestArray.push(popup); 
        console.log(popupsTestArray); // popup_isOpen is false...
           });

I also faced the same issue. 我也遇到了同样的问题。 I am pasting here my piece of code. 我在这里粘贴我的代码。 Hope It will help you out to sort out your problem. 希望它能帮助你解决问题。

marker.on('click', function (e) {
                            if (e.target._popup == undefined) { // same as e.target.getPopup()
                                $.getJSON(url, { entityObject: e.target.options.alt }, function (infoBoxContent ) { //e.target.options.alt contains entity Id from which we will get Infobox window content.
                                    e.target.bindPopup(infoBoxContent).openPopup();
                                });
                            }
                            else {
                                marker.openPopup();
                            }
                        });

In If condition we fetch data from server side and bind it to marker popup. 在If条件下,我们从服务器端获取数据并将其绑定到标记弹出窗口。 And in Else condition there after same marker is clicked again we will show content from client side. 在Else条件下再次点击相同的标记后,我们将显示来自客户端的内容。

This code works fine me. 这段代码很好用。 If you have any queries then we can discuss here. 如果您有任何疑问,我们可以在这里讨论。

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

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