Upgrade notes and example update for shortest arc rotation animation

This commit is contained in:
Andreas Hocevar
2017-06-28 15:31:26 +02:00
parent c0e4da6d8c
commit cd4ed759ed
2 changed files with 40 additions and 3 deletions

View File

@@ -2,6 +2,26 @@
### Next release ### 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 ### v4.2.0
#### Return values of two `ol.style.RegularShape` getters have changed #### Return values of two `ol.style.RegularShape` getters have changed

View File

@@ -1,5 +1,6 @@
goog.require('ol.Map'); goog.require('ol.Map');
goog.require('ol.View'); goog.require('ol.View');
goog.require('ol.easing');
goog.require('ol.layer.Tile'); goog.require('ol.layer.Tile');
goog.require('ol.proj'); goog.require('ol.proj');
goog.require('ol.source.OSM'); goog.require('ol.source.OSM');
@@ -73,9 +74,16 @@ onClick('rotate-right', function() {
}); });
onClick('rotate-around-rome', function() { onClick('rotate-around-rome', function() {
// Rotation animation takes the shortest arc, so animate in two parts
var rotation = view.getRotation();
view.animate({ view.animate({
rotation: view.getRotation() + 2 * Math.PI, rotation: rotation + Math.PI,
anchor: rome 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() { onClick('spin-to-rome', function() {
// Rotation animation takes the shortest arc, so animate in two parts
var center = view.getCenter();
view.animate({ 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, center: rome,
rotation: 2 * Math.PI, rotation: 2 * Math.PI,
duration: 2000 easing: ol.easing.easeOut
}); });
}); });