How to handle 'popup close button' click?

4,910 views
Skip to first unread message

Арсений Зуев

unread,
Oct 9, 2012, 9:04:47 PM10/9/12
to leafl...@googlegroups.com
Hi,

I need to know, when the user clicked on "close" button on the popup. How should I do that? I know about 'popupclose' event, but it it triggers every time another marker has been clicked and the new popup appears.

I'm trying to write some application when open/close markers corresponds to the current active item. So there are 2 ways to activate item (select it in the list or click the marker)  - the marker popup appears and item is "selected" in the list, and it has also 2 ways to deactivate item (click "close" button on the marker popup or click the active element in the list). The problem is, that "popupclose" event triggers every time i select another marker, so i decided to handle "close button" clicks, but i can't do it because of stopPropognation() method, which leaflet use.

How can i differentiate situations when popup were closed by clicking "close popup" button, and when the popup were closed by opening another marker popup? ( "popupclose" event appears in both cases )

Thanks in advance and sorry for my horrible english :(

Jacob Toye

unread,
Oct 10, 2012, 12:04:19 AM10/10/12
to leafl...@googlegroups.com
By the sounds of it you need a way to link markers (with a popup bound) and your list items E.g. an id. When you select a list item it shows the popup and when you click a marker it sets the list item as active.

When you use bindPopup you can pass in an options object. E.g. bindPopup('popup content', { myId:  123}). When the popupclosed event is fired on the map you can get the popup that closed via e.popup (where e is event handler argument). So now you can get the id of the item that just closed: e.popup.options.myId

Hope this helps :)
Reply all
Reply to author
Forward
0 new messages