Closing angular-leaflet popups on event

1.2k Views Asked by At

Is there a function that I can call to close all open popups in the angular-leaflet directive? Working from the jQuery suggestion from here I have tried the following:

document.getElementsByClassName('.leaflet-popup-close-button').click();

but I get

TypeError: undefined is not a function

alternatively, I have tried:

document.getElementsByClassName('.leaflet-popup-close-button')[0].click();

but that does not work either:

TypeError: Cannot read property 'click' of undefined
1

There are 1 best solutions below

0
On BEST ANSWER

Looking through the original Leaflet docs, the solution is to get the native Leaflet map object and call functions on that.

            leafletData.getMap().then(function(map) {
                map.closePopup();
            });