diff --git a/src/ol/typedefs.js b/src/ol/typedefs.js index 86f7d2927c..f470c7f646 100644 --- a/src/ol/typedefs.js +++ b/src/ol/typedefs.js @@ -665,7 +665,7 @@ ol.TransformFunction; * rotationAnchor: (ol.Coordinate|undefined), * start: number, * duration: number, - * done: boolean, + * complete: boolean, * easing: function(number):number, * callback: (function(boolean)|undefined) * }} diff --git a/src/ol/view.js b/src/ol/view.js index 8f7ae82675..1e71a1b597 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -202,7 +202,7 @@ ol.View.prototype.animate = function(var_args) { var animation = /** @type {ol.ViewAnimation} */ ({ start: start, - done: false, + complete: false, anchor: options.anchor, duration: options.duration || 1000, easing: options.easing || ol.easing.inAndOut @@ -279,19 +279,19 @@ ol.View.prototype.updateAnimations_ = function() { var more = false; for (var i = this.animations_.length - 1; i >= 0; --i) { var series = this.animations_[i]; - var seriesDone = true; + var seriesComplete = true; for (var j = 0, jj = series.length; j < jj; ++j) { var animation = series[j]; - if (animation.done) { + if (animation.complete) { continue; } var elapsed = now - animation.start; var fraction = elapsed / animation.duration; if (fraction > 1) { - animation.done = true; + animation.complete = true; fraction = 1; } else { - seriesDone = false; + seriesComplete = false; } var progress = animation.easing(fraction); if (animation.sourceCenter) { @@ -323,7 +323,7 @@ ol.View.prototype.updateAnimations_ = function() { } more = true; } - if (seriesDone) { + if (seriesComplete) { var completed = this.animations_.pop(); if (this.animations_.length === 0) { this.animating_ = false; diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 8affac3187..4421b5cab9 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -338,7 +338,38 @@ describe('ol.View', function() { expect(view.getAnimating()).to.eql(false); done(); }, 50); + }); + it('calls a callback when animation completes', function(done) { + var view = new ol.View({ + center: [0, 0], + zoom: 0 + }); + + view.animate({ + zoom: 1, + duration: 25 + }, function(complete) { + expect(complete).to.be(true); + done(); + }); + }); + + it('calls callback with false when animation is interrupted', function(done) { + var view = new ol.View({ + center: [0, 0], + zoom: 0 + }); + + view.animate({ + zoom: 1, + duration: 25 + }, function(complete) { + expect(complete).to.be(false); + done(); + }); + + view.setCenter([1, 2]); // interrupt the animation }); });