Home > OS >  Google Maps API mimic OpenLayers' view.animate() function
Google Maps API mimic OpenLayers' view.animate() function

Time:10-18

I'm making an experiment with map animation. For now, I only use OpenLayers 6. I want to implement Google Maps as well.

The idea is to animate map interactions such as pan and zoom. Those animations need to be of a fixed duration. In OpenLayers, I'm using the handy view method animate() that way (variables can change depending on the context):

map.getView().animate({
  center: [newx, newy],
  zoom: newzoom,
  easing: oleasing,
  duration: durationms
})

I was wondering if there was any Google Maps equivalent. For now, I'm only looking for a way to animate a pan or a zoom with a fixed duration value. I know there are the Maps methods panTo() and setZoom() but I cannot set a specific duration.

CodePudding user response:

moveCamera works without animation, so you could program your own animation sequence using JavaScript timeouts - or even synchronize your Google map with the change:center and change:resolution events of a hidden OpenLayers view.

For example https://jsfiddle.net/r7kuge1y/ which applies OpenLayers animation from https://openlayers.org/en/latest/examples/animation.html to a Google map example from https://developers.google.com/maps/documentation/javascript/adding-a-google-map

  • Related