如何防止在Leaflet中通过clik显示弹出窗口? [英] How can I prevent popup showing by clik on marker in Leaflet?

查看:490
本文介绍了如何防止在Leaflet中通过clik显示弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击Leaflet标记时,我希望弹出窗口不显示。
我不能使用 clickable:false 因为我会让标记作为底层地图的一部分,这对我来说是不可接受的。我尝试了下一个代码

I want popup doesn't show itself when I click on Leaflet marker. I cannot use clickable : false because I it will make the markers "act as a part of the underlying map" and this is unacceptable for me. I tried the next code

marker.on('click', function(event) {
  event.originalEvent.preventDefault();
});

没有任何结果。在不使用 clickable:false 标记对象属性的情况下阻止弹出窗口显示的正确方法是什么。

without any results. What is the right way to prevent popup showing without using clickable : false property of marker object.

编辑1:我需要的是通过单击一个自定义按钮打开地图上的所有popus,我点击特定标记后仍然不希望弹出窗口显示

Edit 1: All I need is to open all the popus on the map by clicking one custom button, still I don't want popup show itself after I click on the particular marker

推荐答案

只是不要将弹出窗口绑定到标记。这是一个带有2个标记的小提琴。一个有弹出窗口,另一个没有弹出窗口。

Just don't bind a popup to the marker. Here's a fiddle with 2 markers. One has a popup and the other does not.

L.marker([51, 0]).bindPopup("this is a popup").addTo(map);

L.marker([51, 1.5]).addTo(map);

编辑:
我编辑了小提琴并认为它可能就是你在问什么。以下是代码的重要部分:

I've edited the fiddle and think it might be what you are asking. Here's the important part of the code:

function onClick(event) {
    event.target.closePopup();
}

这篇关于如何防止在Leaflet中通过clik显示弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆