0
以下代碼將啓用在地圖上創建多邊形。此工作正常,但在添加新圖層時,以前的geojson圖層也可見。刪除以前的多邊形(geojson層)自動傳單時添加另一層?
$http.get("./json/sf.geo.json").success(function(data, status) {
leafletData.getMap('lfdt').then(function(map){
var polyLayer = L.geoJson(data, {filter: layerFilter}).addTo(map);
function clear_polygon() {
map.removeLayer(polyLayer);
}
function layerFilter(feature) {
if (feature.properties.zip === $scope.code) return true;
}
map.fitBounds(polyLayer.getBounds(), {
padding: [40, 40]
});
});
我有郵編下拉,我想在小冊子地圖上顯示選定的郵政編碼邊界。問題是當用戶被選中另一個郵政編碼時,新的多邊形正在顯示,但是舊的也正在顯示,如下圖所示。
任何人都可以請幫助我,我應該在哪裏寫removeLayers()。請建議我。
時,我想這一點,仍然呈現出以往多邊形 –