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();
});
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.
Juste remove openPopup
from the click event of the marker.
marker.bindPopup('My popup!');
marker.off('click', this.openPopup);
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);
EDIT: 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();
}
Try this workaround:
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;});
See plunker for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With