在OpenLayers 3.20+中使用view.animate()进行view.fit() [英] view.fit() using view.animate() in OpenLayers 3.20+

查看:388
本文介绍了在OpenLayers 3.20+中使用view.animate()进行view.fit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,是为OpenLayers 3.20之前的版本编写的:

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
    })
}

我的问题是如何将此函数转换为OpenLayers 3.20中引入的新view.animate()语法?

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

或者,我是否应该打开GitHub问题并请求将新选项添加​​到view.animate?

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

推荐答案

使用ol.View#fit()duration选项,您应该能够以更简单的方式实现相同的动画:

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
});

以上内容适用于OpenLayers 4.x.

The above works in OpenLayers 4.x.

这篇关于在OpenLayers 3.20+中使用view.animate()进行view.fit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆