問題描述
我想要一個在我單擊傳單標記時不顯示的彈出窗口.我不能使用 clickable : false
因為它會使標記充當底層地圖的一部分".這對我來說是不可接受的.我嘗試了以下代碼:
I want a popup that doesn't show itself when I click on the Leaflet marker. I cannot use clickable : false
because it will make the markers "act as a part of the underlying map" and this is unacceptable for me. I tried the following code:
marker.on('click', function(event) {
event.originalEvent.preventDefault();
});
沒有任何結果.在不使用標記對象的 clickable : false
屬性的情況下,防止彈出窗口顯示的正確方法是什么?
without any results. What is the right way to prevent a popup from showing without using the clickable : false
property of the marker object?
我只需要通過單擊一個自定義按鈕來打開地圖上的所有彈出窗口,但我不希望在單擊特定標記后彈出窗口顯示自己.
All I need is to open all the popups on the map by clicking on one custom button, but I don't want the popups to show themselves after I click on a particular marker.
推薦答案
只是不要將彈出窗口綁定到標記.這是一個帶有 2 個標記的 fiddle.一個有彈出窗口,另一個沒有.
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);
我已經編輯了 fiddle 并認為這可能是您要問的.這是代碼的重要部分:
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 中的標記時,如何防止顯示彈出窗口?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!