我在 Leaflet 中创建了一些 GeoJSON 图层,但我试图在按下按钮时删除某些图层。由于某种原因,Leaflet 无法识别我的图层。
这是我的代码:
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")
}
控制台记录“不存在图层”。
最佳答案
GE_Cities.addTo(map);
GE_Countries.addTo(map);
if (map.hasLayer(GE_Cities)) {
…
}
关于javascript - 传单 map 无法识别图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38207808/