我在一个角度组件上使用leaflet,当用户从esri-leaflet反向地理编码中单击地图时,我显示了一个标记,我想删除用户单击时添加的以前的标记。
这是我的代码:
map.on('click', <LeafletMouseEvent>(e) => {
geocodeService.reverse().latlng(e.latlng).run( (error, result) => {
if (error) {
return;
}
L.marker(result.latlng).addTo(map).bindPopup(result.address.Match_addr).openPopup();
});
});发布于 2020-09-17 19:08:10
将标记存储在变量中,然后在添加新标记之前再次单击地图,然后从地图中删除该标记。
...
marker;
...
map.on("click", (e) => {
new ELG.ReverseGeocode().latlng(e.latlng).run((error, result) => {
if (error) {
return;
}
if (this.marker && map.hasLayer(this.marker))
map.removeLayer(this.marker);
this.marker = L.marker(result.latlng)
.addTo(map)
.bindPopup(result.address.Match_addr)
.openPopup();
});
});https://stackoverflow.com/questions/63935338
复制相似问题