Javascript 为什么弹出窗口未在传单标记中显示第二次

Javascript 为什么弹出窗口未在传单标记中显示第二次,javascript,popup,leaflet,Javascript,Popup,Leaflet,我正在我的地图中绘制一个标记,单击该标记,我将显示一条弹出消息 如果我第一次单击标记,我会看到弹出消息。但是,如果我关闭弹出消息,然后再次单击标记,我看不到弹出消息,尽管在控制台消息打印时,代码进入点击事件代码块 这是我的点击事件代码 circle.on("click",function(ev){ var velocity=this.options.speed; console.log(velocity.toFixed(2)); var layer=ev.target;

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

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

这是我的点击事件代码

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();
});

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

您只需使用
bindpoop()
功能一次,即当您创建标记时。并且只使用
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();
});