gpt4 book ai didi

javascript - 如何从传单中的 L.control 中删除叠加层

转载 作者:行者123 更新时间:2023-11-29 10:34:25 25 4
gpt4 key购买 nike

在客户端上,我从 postgres 数据库中获取了一堆多边形,然后我将它们作为叠加层添加到图层控件中。目前这是通过单击菜单发生的,每次它都会在控件中添加另一个“多边形”复选框。我需要首先清楚地清除所有旧的叠加层,然后使用一组新的“多边形”叠加层进行刷新。在添加新叠加层之前如何以编程方式删除它?

var controlLayers = L.control.layers(baseMaps).addTo(map);


$.getJSON('/db/getPolys', function (geojsonFeatures) {
console.log('returned polys...',geojsonFeatures.features);
if(geojsonFeatures.features == null){
alert('No polygons where found');
}else{
geojsonLayer = L.geoJson(geojsonFeatures,{
onEachFeature: drawStep1Polys
});

// need to remove before adding anything
// if (geojsonLayer exists){
// controlLayers.removeLayer(geojsonLayer);
// }
controlLayers.addOverlay(geojsonLayer, 'Polygons');
}
});

最佳答案

controlLayers.removeLayer(geojsonLayer)

Remove the given layer from the control.

(请注意,您必须保留对之前图层的引用)

关于javascript - 如何从传单中的 L.control 中删除叠加层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39220018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com