Ant*_*huk 6 javascript maps leaflet
我希望当我单击Leaflet标记时弹出窗口不显示自身。我无法使用,clickable : false因为它将使标记“充当基础地图的一部分”,这对我来说是不可接受的。我尝试了下一个代码
marker.on('click', function(event) {
event.originalEvent.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
没有任何结果。不使用clickable : false标记对象的属性来防止弹出窗口显示的正确方法是什么。
编辑1:我所需要的只是通过单击一个自定义按钮来打开地图上的所有弹出式窗口,但是我仍然不希望在单击特定标记后弹出式窗口显示出来
尝试以下解决方法:
marker.bindPopup('my popup content');
// remove openPopup click handler (actually all click handlers)
marker.off('click');
// Do nothing on click. This is not necessary, but now marker
// doesn't act like part of underlying map
marker.on('click', function() {return;});
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参见plunker。
只是不要将弹出窗口绑定到标记。这是带有2个标记的小提琴。一个有弹出窗口,另一个没有。
L.marker([51, 0]).bindPopup("this is a popup").addTo(map);
L.marker([51, 1.5]).addTo(map);
Run Code Online (Sandbox Code Playgroud)
编辑: 我已经编辑了小提琴,并认为这可能是您要的。这是代码的重要部分:
function onClick(event) {
event.target.closePopup();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8314 次 |
| 最近记录: |