所以,我在Leaflet中创建了一些GeoJSON图层,但是我试图在按下按钮时删除某些图层。由于某种原因,传单无法识别我的图层。这是我的代码:
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")
}
控制台记录“不存在图层”。任何帮助超级赞赏!
答案 0 :(得分:1)
GE_Cities.addTo(map);
GE_Countries.addTo(map);
if (map.hasLayer(GE_Cities)) {
…
}