From 97d942c8e2ef93121f5d257304cca1538150e634 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 10 Nov 2016 10:18:42 -0700 Subject: [PATCH] Correctly prune completed animation series --- src/ol/view.js | 8 +++++--- test/spec/ol/view.test.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/ol/view.js b/src/ol/view.js index 61b4640ee9..d99c613a15 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -305,7 +305,7 @@ ol.View.prototype.updateAnimations_ = function() { } var elapsed = now - animation.start; var fraction = elapsed / animation.duration; - if (fraction > 1) { + if (fraction >= 1) { animation.complete = true; fraction = 1; } else { @@ -345,14 +345,16 @@ ol.View.prototype.updateAnimations_ = function() { } } if (seriesComplete) { + this.animations_[i] = null; this.setHint(ol.View.Hint.ANIMATING, -1); - var completed = this.animations_.pop(); - var callback = completed[0].callback; + var callback = series[0].callback; if (callback) { callback(true); } } } + // prune completed series + this.animations_ = this.animations_.filter(Boolean); if (more && this.updateAnimationKey_ === undefined) { this.updateAnimationKey_ = requestAnimationFrame(this.updateAnimations_); } diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index cf5d4dacba..6e36870a25 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -484,6 +484,39 @@ describe('ol.View', function() { }); + it('completes multiple staggered animations run in parallel', function(done) { + + var view = new ol.View({ + center: [0, 0], + zoom: 0 + }); + + var calls = 0; + + view.animate({ + zoom: 1, + duration: 25 + }, function() { + ++calls; + }); + + setTimeout(function() { + expect(view.getZoom() > 0).to.be(true); + expect(view.getZoom() < 1).to.be(true); + expect(view.getAnimating()).to.be(true); + view.animate({ + zoom: 2, + duration: 25 + }, function() { + expect(calls).to.be(1); + expect(view.getZoom()).to.roughlyEqual(2, 1e-8); + expect(view.getAnimating()).to.be(false); + done(); + }); + }, 10); + + }); + }); describe('#getResolutions', function() {