Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easing function with Google Maps FitBounds() function

Is it possible when calling map.fitBounds() to use an easing function to ensure a smooth change of view on the map?

like image 538
Bill Avatar asked Jan 30 '12 15:01

Bill


3 Answers

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.

like image 116
bamnet Avatar answered Nov 03 '22 21:11

bamnet


What about map.panToBounds(latLngBounds:LatLngBounds)? https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map

like image 31
Drew LeSueur Avatar answered Nov 03 '22 20:11

Drew LeSueur


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.

like image 1
Nicolas Le Thierry d'Ennequin Avatar answered Nov 03 '22 22:11

Nicolas Le Thierry d'Ennequin