diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index 82bb599bc1..9dab9b583f 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -2,6 +2,26 @@ ### Next release +#### `ol.animate` now takes the shortest arc for rotation animation + +Usually rotation animations should animate along the shortest arc. There are rare occasions where a spinning animation effect is desired. So if you previously had something like +```js +map.getView().animate({ + rotation: 2 * Math.PI, + duration: 2000 +}); +``` +we recommend to split the animation into two parts and use different easing functions. The code below results in the same effect as the snippet above did with previous versions: +```js +map.getView().animate({ + rotation: Math.PI, + easing: ol.easing.easeIn +}, { + rotation: 2 * Math.PI, + easing: ol.easing.easeOut +}); +``` + ### v4.2.0 #### Return values of two `ol.style.RegularShape` getters have changed diff --git a/examples/animation.js b/examples/animation.js index 6765e4ee38..bfac92e190 100644 --- a/examples/animation.js +++ b/examples/animation.js @@ -1,5 +1,6 @@ goog.require('ol.Map'); goog.require('ol.View'); +goog.require('ol.easing'); goog.require('ol.layer.Tile'); goog.require('ol.proj'); goog.require('ol.source.OSM'); @@ -73,9 +74,16 @@ onClick('rotate-right', function() { }); onClick('rotate-around-rome', function() { + // Rotation animation takes the shortest arc, so animate in two parts + var rotation = view.getRotation(); view.animate({ - rotation: view.getRotation() + 2 * Math.PI, - anchor: rome + rotation: rotation + Math.PI, + anchor: rome, + easing: ol.easing.easeIn + }, { + rotation: rotation + 2 * Math.PI, + anchor: rome, + easing: ol.easing.easeOut }); }); @@ -103,10 +111,19 @@ onClick('bounce-to-istanbul', function() { }); onClick('spin-to-rome', function() { + // Rotation animation takes the shortest arc, so animate in two parts + var center = view.getCenter(); view.animate({ + center: [ + center[0] + (rome[0] - center[0]) / 2, + center[1] + (rome[1] - center[1]) / 2 + ], + rotation: Math.PI, + easing: ol.easing.easeIn + }, { center: rome, rotation: 2 * Math.PI, - duration: 2000 + easing: ol.easing.easeOut }); });