How to close all popups?

2024/2/27 8:16:58

I have multiple (444) popups open on my map.

I tried this:

$(".leaflet-popup-close-button").each(function (index) {$(".leaflet-popup-close-button")[index].click();
});

But this way, not all get closed. Only half of them get removed. Exactly half. So first time 222 get removed, the second time 111 get removed.

Why is this happening?

Answer

For recent versions of Leaflet:

The proper way to close a popup is to use the built-in .closePopup() method:

map.closePopup();

If you have multiple layers with different popups (like in the OP's case), then you could iterate over the layers and close the popup on each layer:

map.eachLayer(function (layer) {layer.closePopup();
});
http://en.ppmy.cn/q/42422.html

Related Q&A

Arrow function and this inside a constructor function

I have read this paragraph about the this keyword : https://bonsaiden.github.io/JavaScript-Garden/#function.thisIn this first case this refers to global objet, and it seems totally normal because when …

Why can my code run in a standard Node.js file, but not in a AWS Lambda Function?

What Im trying to do is create a lambda function where the function calls two commands on an ec2 instance. When I had trouble running this code in a lambda function, I removed the code from the exports…

Get Parent ID of this DIV

I am looking to find the parent div id (i.e. "Bakerloo") from this layout when the button is clicked within ".buttonleft0" in jquery / javascript.<div id=Bakerloo class=box>ba…

Call external Javascript function from react typescript components

I have a react redux application with typescript. So the scenario is like this, I have an index.cshtml file that includes some javascript. <script type="text/javascript">function test()…

what is the meaning of the Object window[0] and window[1] in javascript

Iam a beginners of javaScript,and i really want to know what does the Window[0] means. I guess it may be connected with frame element of html,but how and i can not find answer in the book Professional …

Dynamically populated google maps sidebar

Ive been using the code from this V3 example to set up a links bar that dynamically populates when different category filters are selected, but have two problems at the moment. Firstly, Ive put the the…

How to unescape UTF-8 characters in Node (\u00f6)?

I have a properties file which is encoded using ISO Latin but with special characters as UTF-8 escape sequences, for example the following string:Einstellungen l\u00f6schenIve tried a bunch of differen…

How to Play RAW Audio Files?

I am currently working on a project that consists of a chart that shows audio levels picked up by another device. The charts are made through the flot API and I have zooming and selecting capabilities …

jQuery animate working in fiddle but not smooth online

Ive made a sort of accordion with three expanding divs (#a, #b, #c) in fiddle, but when I save it locally and open it in a browser the transitions are no longer smooth. I noticed specifically after cli…

How to handle nested services and promises using resolve and $routeChangeError

Thats more like a research I did while I was playing with AngularJS and I would like to share as I think some people might find this useful.Sometimes you need to fetch some data from several services b…