diff --git a/src/ol/view.js b/src/ol/view.js index dfbd4165ff..12de5c0d9e 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -15,6 +15,7 @@ goog.require('ol.extent'); goog.require('ol.geom.GeometryType'); goog.require('ol.geom.Polygon'); goog.require('ol.geom.SimpleGeometry'); +goog.require('ol.math'); goog.require('ol.obj'); goog.require('ol.proj'); goog.require('ol.proj.Units'); @@ -295,7 +296,10 @@ ol.View.prototype.animate = function(var_args) { if (options.rotation !== undefined) { animation.sourceRotation = rotation; - animation.targetRotation = options.rotation; + var delta = + ol.math.modulo(options.rotation - rotation + Math.PI, 2 * Math.PI) - + Math.PI; + animation.targetRotation = rotation + delta; rotation = animation.targetRotation; } diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 80356edd87..6541d6140f 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -494,6 +494,21 @@ describe('ol.View', function() { }); }); + it('takes the shortest angle to the target rotation', function(done) { + var view = new ol.View({ + center: [0, 0], + zoom: 0, + rotation: Math.PI / 180 * 1 + }); + view.animate({ + rotation: Math.PI / 180 * 359, + duration: 0 + }, function() { + expect(view.getRotation()).to.roughlyEqual(Math.PI / 180 * -1, 1e-12); + done(); + }); + }); + it('calls a callback when animation completes', function(done) { var view = new ol.View({ center: [0, 0],