bluehalo / ngx-leaflet

Core Leaflet package for Angular.io
MIT License
763 stars 126 forks source link

Move marker and FlyTo new marker position #317

Open youssefajaamoum opened 2 years ago

youssefajaamoum commented 2 years ago

Hi, I am trying to update the position of the marker on the map, the position of the marker has been updated but I cannot fly to the new position of the marker.

@ViewChild(LeafletDirective, { static: false }) map: LeafletDirective;

updateMarker(lat: number, lng: number) {
var newLatLng = new leaflet.LatLng(lat, lng);
// the marker moved to new lat, lng this.markers[0].marker.setLatLng(newLatLng);

// can’t use this.map.panTo() or flyTo()

}

reblace commented 2 years ago

Can you provide the full code for what you're trying to do? How are you calling panTo or flyTo? Are you just passing in the newLatLng? You might need to create a second leaflet.LatLng object from the same lat/lng cause Leaflet is weird about mutating objects you would think would be mutable.