[英]How to remove marker by method, openlayers 4, angular 4
I want to remove the marker in Openlayers map How could i remove all the marker pin i have added to map 我想在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);
}
could some one help me remove the marker pin i have added to the open layers map 有人可以帮我删除我添加到开放图层地图中的标记图钉吗
this.map.removeLayer(vectorLayer);
Yes, this means you have to keep track of all the layers you've been adding. 是的,这意味着您必须跟踪已添加的所有图层。 Which sadly is the case with open layers.
可悲的是开放层的情况。
您可以使用以下解决方案删除已添加到地图的所有标记图钉:
vectorSource.clear();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.