我想知道是否有人知道如何使用以下约定添加一层点,或者是否可以实际删除它们:
var pointsLayer, someFeatures = [{
//Hard coded for now
"type": "Feature",
"properties": {
"name": "Company A",
"show_on_map": true,
"icon": 'img/violations.png'
},
"geometry": {
"type": "Point",
"coordinates": [43.22519, -107.69348]
}
}, {
"type": "Feature",
.
.
.
}];
for(w=0; w < someFeatures.length; w++){
pointsLayer = L.marker(someFeatures[w].geometry.coordinates, {icon: violations})
.bindPopup("Company: "+someFeatures[w].properties.name);
//add map points
map.addLayer(pointsLayer);
}
在类似的for循环中,典型的removeLayer(pointsLayer);对我不起作用。但是,这并不意味着没有循环遍历的方法。我只是不确定到底是怎么做的。我正在尝试添加积分,这是有效的,然后在一个事件上删除它们(不起作用)。有什么想法吗?
发布于 2015-01-16 01:28:36
使用map.removeLayer()
var circle = L.circle([lat, lng], 1000).addTo(map);
map.removeLayer(circle);
发布于 2017-08-10 21:20:51
你可以直接在对象'map‘中遍历所有图层。
for ( key in map['_layers'] ){
if(typeof map['_layers'][key]['feature'] !== 'undefined') {
var l = map['_layers'][key];
if( l['feature']['properties']['name'] === 'Company A' ) l.removeFrom(map);}}
https://stackoverflow.com/questions/20751523
复制相似问题