【问题标题】:Why the popup is not showing second time in leaflet marker为什么弹出窗口没有在传单标记中第二次显示
【发布时间】:2015-07-22 15:22:45
【问题描述】:

我正在我的leaflet 地图中绘制一个标记,单击该标记时我会显示一条弹出消息。

如果我点击标记第一次,我会看到弹出消息。但是,如果我关闭弹出消息,然后再次单击标记,尽管代码在打印控制台消息时进入单击事件代码块内,但我看不到弹出消息。

这是我的点击事件代码

circle.on("click",function(ev){
    var velocity=this.options.speed;
    console.log(velocity.toFixed(2));
    var layer=ev.target;
    layer.bindPopup('Speed: '+velocity.toFixed(2));
    console.log("Where is pop");
    layer.openPopup();
});

【问题讨论】:

    标签: javascript popup leaflet


    【解决方案1】:

    目前,每次用户单击标记时,您都会创建弹出窗口。可能,这会造成问题。

    您只需使用一次bindPopup() 函数,即在您创建标记时。并且只能在 click 函数中使用 openPopup()。试试这个

    //Place below two lines where you create the marker
    var velocity=this.options.speed; //you might need to change this line to get the speed value
    circle.bindPopup('Speed: '+velocity.toFixed(2));
    
    //open the popup when user click the marker
    circle.on("click",function(ev){
        layer.openPopup();
    });
    

    【讨论】:

      猜你喜欢
      • 2020-07-29
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多