Close All Popups with Leaflet.js

Fehler picture Fehler · Dec 28, 2013 · Viewed 26.1k times · Source

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.

Answer

Florian Boudot picture Florian Boudot · Apr 29, 2016

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

map.closePopup();