Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

view.fit() using view.animate() in OpenLayers 3.20+

Tags:

openlayers-3

I have the following code, written for OpenLayers pre 3.20:

fitViewToFeature: function (viewer, feature) {
    var pan = ol.animation.pan({
      source: viewer.olView.getCenter(),
      duration: 1000
    })

    var zoom = ol.animation.zoom({
      resolution: viewer.olView.getResolution(),
      duration: 1000
    })

    viewer.olMap.beforeRender(pan, zoom)

    viewer.olView.fit(feature.getGeometry(), viewer.olMap.getSize(), {
      padding: [ 100, 100, 100, 100 ],
      constrainResolution: false,
      maxZoom: 4
    })
}

My question is how to translate this function into the new view.animate() syntax introduced in OpenLayers 3.20?

Or alternately, should I open a GitHub issue and request a new option to be added to view.animate?

like image 962
hyperknot Avatar asked Dec 11 '22 13:12

hyperknot


1 Answers

You should be able to achieve the same animation in a much simpler way, with the duration option of ol.View#fit():

viewer.olView.fit(feature.getGeometry(), {
  duration: 1000
});

The above works in OpenLayers 4.x.

like image 127
ahocevar Avatar answered Feb 28 '23 04:02

ahocevar