Leaflet.js: How to remove multiple layers from map

后端 未结 3 1508
囚心锁ツ
囚心锁ツ 2021-02-08 12:18

I am using Leaflet.js for a map. Now I want to remove added layers from the map. By clicking the input #button all checked checkboxes shall be changed to unchecked and all corre

3条回答
  •  半阙折子戏
    2021-02-08 12:27

    I wrote the below example to show how to remove multiples geoJSON layer.

    ///adding geoJSON data

          var myGeoJSON = L.geoJSON(myData, {
    
            onEachFeature: function (feature, layer) {
                layer.myTag = "myGeoJSON"
            }
    
        });
    

    ////// function to remove geoJSON layers

    var removeMarkers = function() {
        map.eachLayer( function(layer) {
    
          if ( layer.myTag &&  layer.myTag === "myGeoJSON") {
            map.removeLayer(layer)
              }
    
            });
    
    }
    

    //// calling function

    removeMarkers();

提交回复
热议问题