首页 > 解决方案 > 更新传单标记

问题描述

这是关于角度 5 上的传单标记,标记值是动态的,我只需要绘制最后一个结果。请问我该怎么做?

var markers;
markers = new L.LayerGroup().addTo(myfrugalmap);
let timer = TimerObservable.create(0, 10000);
this.subscription = timer.subscribe(t => { this.MyService.Localize().subscribe( result => {
this.positions = result;
let xpo = this.positions.x;
let ypo = this.positions.y;
let mar=L.marker([xpo,ypo], {icon: greenIcon}) mar.addTo(markers) });

//markers.clearLayers();
} )

结果(没有(markers.clearLayers))我在地图上每10秒就有一个新位置,我需要放弃旧位置,只看到最后一个

标签: javascriptangularleafletangular-leaflet-directiveleaflet.markercluster

解决方案


在将新创建的标记添加到图层之前,您是否尝试过清除?你的最后几行看起来像这样。

let mar=L.marker([xpo,ypo], {icon: greenIcon});
markers.clearLayers();
mar.addTo(markers);

推荐阅读