2015-07-21 63 views
2

我正在绘制标记在我的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(); 
}); 

回答

1

目前,正在创建每次弹出当用户单击该标记。可能这是造成问题的原因。

只需要使用bindPopup()函数即可创建标记。并且只能使用openPopup()里面的click功能。试试这个

//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(); 
}); 
相关问题