How to close all popups?

前端 未结 3 2007
广开言路
广开言路 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 07:00

    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();
    });
    

提交回复
热议问题