Marker mouse events not fired as expected?

11 views
Skip to first unread message

David G

unread,
Jun 5, 2022, 10:52:46 AMJun 5
to Leaflet
I have a marker that has a popup associated with it. The behaviour I wanted was that on clicking the marker, you could toggle the visibility of the associated popup.

So, using the "click" event, I tried using the "togglePopup" method so that if the popup was not visible, it would be made visible, and if it was visible, it would be made invisible.

However, I can see from debug I've added, that when I click on the marker, both the popupopen and popupclose events are getting fired as soon as I make a single click on the marker, the net result is my popup is never shown.

If I use other means of showing/hiding the popup, e.g. mouseover makes it visible, mouseout hides it, it works perfectly, but toggle does not seem to work as I expected.

Is there something obvious I am missing?

Thanks!

Pat Keller

unread,
Jun 10, 2022, 11:19:14 PMJun 10
to Leaflet
There's no need to manually call togglePopup in the click event. The default behavior of a popup bound to a marker is to toggle the popup. See the description here: marker.bindPopup
Reply all
Reply to author
Forward
0 new messages