【leaflet】 leaflet移除地图上所有marker(layers)

文章原地址:https://blog.csdn.net/huangsheng_blog/article/details/77855890

eaflet批量移除地图上的marker可采用分组的方式,然后用分组批量清除,如下所示:

批量生成marker

  1. var layers=[];
  2. for(var i = 0;i< result.length;i++){
  3. var layer = new L.marker([ result[i].lat, result[i].lng ]);
  4. layers.push(layer);
  5. }
marker分组

  1. var myGroup=L.layerGroup(layers);
  2. maps.addLayer(myGroup);

批量移除

myGroup.clearLayers();

转载自:https://blog.csdn.net/zl15145428/article/details/80854398

You may also like...

退出移动版