Search code examples
zoomingopenlayerssmoothingpan

Smooth zoom and pan in OpenLayers?


I was wondering, has smooth zooming and panning described in http://www.win.tue.nl/~vanwijk/zoompan.pdf been implemented in OpenLayers?

It has been implemented for PolyMaps: http://bl.ocks.org/RandomEtc/600144 And ModestMaps: https://github.com/stamen/modestmaps-js/tree/master/examples/zoompan


Solution

  • Since 3.20.0, OpenLayers has an ol.View.animate() method that allows smooth zooming and/or panning (among others) and deprecates the old ol.animation.

    From the latest API docs:

    The view's center, zoom (or resolution), and rotation can be animated for smooth transitions between view states.

    So, you can zoom and pan by doing:

    var view = map.getView();
    view.animate({
        center: coordinates,
        zoom:   zoomLevel
    });