Google Groups

Re: [Leaflet] Keeping multiple popups open

Paulo Vieira Dec 20, 2012 5:54 AM
Posted in group: Leaflet
On Sun, Dec 9, 2012 at 7:04 AM, Mike George <> wrote:
Can anybody tell me, is there a way to prevent popups closing when another popup is opened?
I display markers and bind popups to them, and I would like users to be able to keep a few popups open at the same time to compare them.

This is not possible. There can be only one popup open at most. This happens because of the openPopup method in L.Map: it will close the current popup before opening the new one.

But this behavior can be easily changed. You can "L.Class.Extend" the default L.Map class, defining a new openPopup method. This new method will be a simple copy-paste of the default one, except for the part where the current popup is closed (just comment that line).

Here is a simple example:

But take caution because probably this hack will conflict with other parts of the library and unexpected things might happen. I didn't check the possible problems. But if you only have a bunch of popups, it should work with no problem.