Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close All Popups with Leaflet.js

I'm working on a map using Leaflet.js that uses a number of markers (eventually there will be ~40 markers). Each marker has a related popup with details. The default behaviour of Leaflet.js seems to be to automatically open at least one marker's popup (the last listed marker, I believe).

I'd like all the popups to be closed on the initial loading of the map page so users have to click the markers to open the popups. Does anyone know how to do this? I have a prototype here:

http://dev.monographic.org/maps/prototype-10.html

Thank you.

like image 532
Fehler Avatar asked Dec 28 '13 15:12

Fehler


2 Answers

There is a clean method from your map object to close all open popups

map.closePopup(); 
like image 84
Florian Boudot Avatar answered Sep 18 '22 14:09

Florian Boudot


I managed to solve my problem by this piece of code:

$(".leaflet-popup-close-button")[0].click(); 

Hope it helps someone in future.

like image 22
sAm Avatar answered Sep 20 '22 14:09

sAm