I use Leaflet
to show a map to the user. The map has several markers on it and when the user clicks on one, I want to pan to the marker location and zoom in. I can achieve this by using the following code:
map.fitBounds([
// bounds of clicked marker
]);
This works fine and Leaflet even animates the transition. What I would like is set the duration of the animation in miliseconds. FitBounds
takes some options, but none of them allows me to specify the duration of the panning and zooming animation. Can anyone help me with this?
That's incorrect, the fitBounds method does accept the zoom/pan options of which pan options has duration as stated in the documentation for the fitBounds options.
What you are looking for is flyToBounds(<LatLngBounds> bounds, <fitBounds options> options?)
Sets the view of the map with a smooth animation like
flyTo
, but takes a bounds parameter likefitBounds
.
map.flyToBounds(bounds, { duration: 1 } );
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