Openlayers fit extent with bounce

走远了吗. 提交于 2020-01-03 03:47:18

问题


I am attempting to animate between two extents, with an increase in zoom during the middle of the animation, to create a bouncing or flying effect when going between locations which are far apart. Right now I am using view.fit(extent, {duration: 2000}). The problem is the zoom does not change at all during the animation. When I am panning from one extent to another which are far apart, you just see a bunch of tiles flying by at a very low zoom level.


回答1:


For a fly effect, you'll want to combine a center animation with two zoom animations, and start those at the same time. You can calculate the center and zoom from your desired extent (myExtent). Something like

    var resolution = view.getResolutionForExtent(myExtent);
    var zoom = view.getZoomForResolution(resolution);
    var center = ol.extent.getCenter(myExtent);
    view.animate({
      center: center,
      duration: duration
    });
    view.animate({
      zoom: zoom - 1,
      duration: duration / 2
    }, {
      zoom: zoom,
      duration: duration / 2
    });

Something similar is also shown as "Fly to Bern" in the official animation example (http://openlayers.org/en/latest/examples/animation.html).



来源:https://stackoverflow.com/questions/44763661/openlayers-fit-extent-with-bounce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!