2016-07-05 68 views
0

所以,我在Leaflet中創建了幾個GeoJSON圖層,但是我試圖在按下按鈕時刪除某些圖層。由於某種原因,小冊子無法識別我的圖層。這裏是我的代碼:Leaflet map not recognizing layer

var GE_Countries = L.geoJson(GE_Countries) 
var GE_Cities = L.geoJson(GE_Cities) 
var map = L.map('map', { 
    // set geographic center 
    center: [41.4, -110], 
    // set initial zoom level 
    zoom: 4, 
    maxZoom: 8, 
    minZoom: 2 
}); 
var attribute; 
var attributes; 

if (map.hasLayer(map)) { 
    console.log("map layer present"); 
} else { 
    console.log("no layer present") 
} 

控制檯記錄「no layer present」。任何幫助超級讚賞!

回答

1
GE_Cities.addTo(map); 
GE_Countries.addTo(map); 

if (map.hasLayer(GE_Cities)) { 
    … 
} 
+0

然後你檢查地圖是否有圖層'map',我想你想檢查地圖是否有一個圖層'GE_Countries'或類似的東西。 – Jieter