Reputation: 3
it's about leaflet marker on angular 5 , the marker value is dynamic and I need to draw just the last result. How can I do it please?
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();
} )
in result (without (markers.clearLayers)) I have evry 10 second the new position on the map and I need to drop the old positions and the see just the last
Upvotes: 0
Views: 1337
Reputation: 656
Did you try clearing before you added the newly created marker to the layer? Your last few lines would look something like this.
let mar=L.marker([xpo,ypo], {icon: greenIcon});
markers.clearLayers();
mar.addTo(markers);
Upvotes: 1