Is it possible when calling map.fitBounds()
to use an easing function to ensure a smooth change of view on the map?
Not easily. It's not very easy to "animate" the transition of zoom levels / map center and the fitBounds
function doesn't provide any options to enable this.
If you wanted to do this yourself, your best bet would be to calculate the best center and zoom level and then write some jQuery to animate the setCenter calls. The zoom level adjustments would be tricky because there are rather discrete changes. jQuery can't animate smoothly zooming from 1 -> 3 because the only step tiles will be served for is 2.
What about map.panToBounds(latLngBounds:LatLngBounds)
? https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map
Given that the map.fitBounds
transitioning seems to be reasonably smooth when the amount of zooming and panning is not too important, it should be possible to write a function that does a step-by-step animation through a number of intermediate LatLngBounds. The Map class has an idle
event which would tell when to start the next step.
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