我想在Openlayers地图中删除标记 如何删除我添加到地图的所有标记针
addmarker(name:any,lat:any,lng:any){
console.log("inside ",lat,lng,name)
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([lng,lat],'EPSG:4326', 'EPSG:3857')),
name: name
});
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: '../../assets/images/location_pin.png'
}))
});
iconFeature.setStyle(iconStyle);
var vectorSource = new ol.source.Vector({
features: [iconFeature]
});
this.vector = vectorSource
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
this.vector_layer = vectorLayer
this.map.addLayer(vectorLayer);
}
有人可以帮助我删除我添加到开放图层地图中的标记针
答案 0 :(得分:1)
this.map.removeLayer(vectorLayer);
是的,这意味着您必须跟踪已添加的所有图层。可悲的是开放层的情况。
答案 1 :(得分:0)
您可以使用以下解决方案删除已添加到地图的所有标记图钉:
vectorSource.clear();