问题
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