本文介紹了清除傳單地圖中的所有折線的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在努力清除地圖上的所有折線,我只清除最新的.
I am struggling to clear all polylines from my map, i only clear the newest.
var polylines;
// add map polylines
function addPolyline(polyArray, colour) {
polylines = L.polyline(polyArray, {color: colour});
polylines.addTo(map);
}
// clear polylines
function clearPolylines() {
map.removeLayer(polylines);
}
其中 addPolylines 被多次調用,而 clear Polylines 被調用一次.如何清除地圖上的所有折線?
where addPolylines is called multiple times and clear Polylines is called once. How can i clear all polylines on the map?
推薦答案
你必須把它們全部記住,或者稍微作弊,然后窺視 map._layers
以找到它們.
You'll have to remember them all or cheat a bit and peek into map._layers
to find them.
編輯 @Ben 添加示例代碼:
EDIT adding sample code by @Ben:
function clearMap() {
for(i in m._layers) {
if(m._layers[i]._path != undefined) {
try {
m.removeLayer(m._layers[i]);
}
catch(e) {
console.log("problem with " + e + m._layers[i]);
}
}
}
}
這篇關于清除傳單地圖中的所有折線的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!