I'm currently working with leaflet.js and I'm searching the web now for quite a bit, to find out: If there is an event, that can be fired after animation end of asynchronous function setView().
This is what I tried:
map.setView( [lat, lon ], 12 , {
pan: { animate: true , duration: 0.5 },
zoom: { animate: true },
animate: true
}.on('ready', function(e) {
console.log("animation finished!");
});
The setView-command works perfectly, but the function, that should be fired when map-animation is ready, is not working.
Does anyone have a solution?
setView : Set the view of the map (center and zoom level) flyTo : Flys to a given location/zoom-level using smooth pan-zoom. fitBounds : Set the bounds of a map. flyToBounds : Flys to given bound using smooth pan/zoom. setMaxBounds : Restricts the map view to the given bounds.
Yes, you are free to remove the Leaflet attribution. You can remove the entire attribution control when you create the map by setting attributionControl: false. If you just want to remove (or change) the default Leaflet attribution, you can do something like this: map. attributionControl.
Used to load and display tile layers on the map, implements ILayer interface.
Have you tried the moveend
and zoomend
events?
You can attach a callback on both events easily: map.once("moveend zoomend", callback)
(note the once
that will remove the listener once it is triggered)
A very special case may not trigger your callback: if setView
does not change anything, i.e. the requested view is already the current view. To be checked, it is possible that the moveend
event is fired by setView
in all cases.
Otherwise, a simple timeout could be enough.Especially since you specify the animation duration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With