Keeping multiple popups open

7,108 views
Skip to first unread message

Mike George

unread,
Dec 9, 2012, 2:04:28 AM12/9/12
to leafl...@googlegroups.com
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.
 

Mike George

unread,
Dec 18, 2012, 12:47:39 AM12/18/12
to leafl...@googlegroups.com
Anybody?
 
This would be really useful for me if I could make it work, but I've checked the documentation again and there doesn't seem to be an option for it?

Bryan McBride

unread,
Dec 19, 2012, 10:33:56 PM12/19/12
to leafl...@googlegroups.com
I know this is possible using the Leaflet Vector Layers plugin: http://geojason.info/leaflet-vector-layers/.

BRYAN

Paulo Vieira

unread,
Dec 20, 2012, 8:54:09 AM12/20/12
to leafl...@googlegroups.com
On Sun, Dec 9, 2012 at 7:04 AM, Mike George <mi...@cartergeorge.co.uk> 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: http://jsfiddle.net/paulovieira/yVLJf/

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.

Tushar Agarwal

unread,
Jan 14, 2013, 4:12:45 AM1/14/13
to leafl...@googlegroups.com
You should use map#addLayer to prevent popups from closing.
map.addLayer(popup);

To remove this popup, use:
map.removeLayer(popup);

dan lamp

unread,
Jun 20, 2013, 7:45:13 AM6/20/13
to leafl...@googlegroups.com
I tried this, wouldnt work, still kept closing popups. any other ideas? Can Popup.js be altered to stop this?

Paulo Vieira

unread,
Jun 24, 2013, 12:28:48 PM6/24/13
to leafl...@googlegroups.com
On Thu, Jun 20, 2013 at 12:45 PM, dan lamp <dann...@hotmail.co.uk> wrote:
I tried this, wouldnt work, still kept closing popups. any other ideas? Can Popup.js be altered to stop this?

Mubin Khan

unread,
Sep 11, 2013, 6:54:42 AM9/11/13
to leafl...@googlegroups.com

Thanks a lot Paulo ... this really worked for me :D ... Two Thumbs up :) 
Reply all
Reply to author
Forward
0 new messages