为什么弹出没有显示第二次在传单标记

Why the popup is not showing second time in leaflet marker

本文关键字:第二次 单标记 显示 为什么      更新时间:2023-09-26

我正在绘制一个标记在我的传单地图和点击标记我显示一个弹出消息。

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

这是我的代码点击事件
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();
});

目前,当用户每次单击标记时,您都会创建弹出窗口。

您只需要使用一次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();
});