How to close all popups?

前端 未结 3 1989
广开言路
广开言路 2021-01-14 06:27

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

I tried this:

$(\".leaflet-popup-close-button\").each(function (index) {
    $         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 06:46

    This is what i did to solve my problem:

    var firstLayer = true;
    
     map.eachLayer(function (layer) {
        // do something with the layer
        if (firstLayer) {
            firstLayer = false;
        } else {
            map.removeLayer(layer);
        }
        //console.log(layer);
    });
    

    I have 3 layers, the first one is the main one which displays my map, that's why it mustn't be removed. I removed the second and the third one which are both layers with multiple popups on it.

    Thanks @rafaelbiten who pointed me in the right direction (layers).

提交回复
热议问题