diff --git a/src/ol/view.js b/src/ol/view.js index b4a566267e..4b818ff955 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -296,9 +296,7 @@ ol.View.prototype.animate = function(var_args) { if (options.rotation !== undefined) { animation.sourceRotation = rotation; - var delta = - ol.math.modulo(options.rotation - rotation + Math.PI, 2 * Math.PI) - - Math.PI; + var delta = ol.math.modulo(options.rotation - rotation + Math.PI, 2 * Math.PI) - Math.PI; animation.targetRotation = rotation + delta; rotation = animation.targetRotation; } @@ -399,7 +397,7 @@ ol.View.prototype.updateAnimations_ = function() { } if (animation.sourceRotation !== undefined && animation.targetRotation !== undefined) { var rotation = progress === 1 ? - animation.targetRotation : + ol.math.modulo(animation.targetRotation + Math.PI, 2 * Math.PI) - Math.PI : animation.sourceRotation + progress * (animation.targetRotation - animation.sourceRotation); if (animation.anchor) { this.set(ol.ViewProperty.CENTER, diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 1c10602a72..94402b7fd1 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -494,7 +494,7 @@ describe('ol.View', function() { }); }); - it('takes the shortest angle to the target rotation', function(done) { + it('takes the shortest arc to the target rotation', function(done) { var view = new ol.View({ center: [0, 0], zoom: 0, @@ -509,6 +509,21 @@ describe('ol.View', function() { }); }); + it('normalizes rotation to angles between -180 and 180 degrees after the anmiation', function(done) { + var view = new ol.View({ + center: [0, 0], + zoom: 0, + rotation: Math.PI / 180 * 1 + }); + view.animate({ + rotation: Math.PI / 180 * -181, + duration: 0 + }, function() { + expect(view.getRotation()).to.roughlyEqual(Math.PI / 180 * 179, 1e-12); + done(); + }); + }); + it('calls a callback when animation completes', function(done) { var view = new ol.View({ center: [0, 0],