leaflet清除所有的图层
来源:openlayers-cesium.com 时间:09-08
我们在执行一个任务的时候,有时候需要清除leaflet的所有图层,怎么解决呢?
核心代码
- clearAll(){
- this.map.eachLayer(function (layer) {
- this.map.removeLayer(layer);
- });
- }
另外的场景:保留地图
- clearAll(tile){
- this.map.eachLayer(function (layer) {
- this.map.removeLayer(layer);
- });
- this.map.addLayer(tile); //为底图的一个信息
- }