Javascript 如何防止在传单中通过标记上的clik显示弹出窗口?

Javascript 如何防止在传单中通过标记上的clik显示弹出窗口?,javascript,maps,leaflet,Javascript,Maps,Leaflet,我想当我点击传单标记时,弹出窗口不会自动显示。 我不能使用clickable:false,因为它会使标记“作为基础地图的一部分”,这对我来说是不可接受的。我试了下一个密码 marker.on('click', function(event) { event.originalEvent.preventDefault(); }); 没有任何结果。如果不使用标记对象的clickable:false属性,防止弹出窗口显示的正确方法是什么 编辑1:我所需要的是通过单击一个自定义按钮打开地图上的所有P

我想当我点击传单标记时,弹出窗口不会自动显示。 我不能使用
clickable:false
,因为它会使标记“作为基础地图的一部分”,这对我来说是不可接受的。我试了下一个密码

marker.on('click', function(event) {
  event.originalEvent.preventDefault();
});
没有任何结果。如果不使用标记对象的
clickable:false
属性,防止弹出窗口显示的正确方法是什么


编辑1:我所需要的是通过单击一个自定义按钮打开地图上的所有POPU,但我不希望在单击特定标记后弹出窗口自动显示。它应该会起作用。虽然我不是很确定

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

只是不要将弹出窗口绑定到标记。这是一张有两个记号笔的照片。一个有弹出窗口,另一个没有

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

L.marker([51, 1.5]).addTo(map);
编辑: 我编辑了这篇文章,我想这可能就是你要问的。以下是代码的重要部分:

function onClick(event) {
    event.target.closePopup();
}
尝试以下解决方法:

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

有关详细信息,请参阅。

其他答案对我都不起作用(可能是因为新版本的传单)。最后我跳过了marker.bindPopup(),只是使用
L.popup()
单独创建了弹出窗口,然后在需要它们出现时调用
map.openPopup(thePopup)

大概是这样的:

var map = L.map(),
    popup = L.popup().setContent("Stuff"),
    marker = L.marker();
popup.setLatLng(marker.getLatLng());

// In my event handler
map.openPopup(popup);

只需从标记的单击事件中删除
openPopup

marker.bindPopup('My popup!');
marker.off('click', this.openPopup);

我想我不是这样,因为我仍然需要弹出窗口。我只需单击一个自定义按钮即可打开地图上的所有POPU,但我不希望在单击特定标记后弹出窗口自动显示。仅供参考,
event.target.closePopup()不适用于当前版本的传单。如果您可以作为全局变量访问map,则可以执行
map.closePopup()取而代之。