How to remove all layers and features from map?

后端 未结 3 1917
陌清茗
陌清茗 2020-12-11 02:25

I am working on a map and I would like to remove all features from the map on a certain event. The features are in multiple layers which are plotted dynamically.

Som

3条回答
  •  时光取名叫无心
    2020-12-11 03:04

    You can use the following truthy check to see if it's a valid geoJSON object:

    map.eachLayer(function(layer) {
      if (!!layer.toGeoJSON) {
        map.removeLayer(layer);
      }
    });
    

提交回复
热议问题