Correctly prune completed animation series

This commit is contained in:
Tim Schaub
2016-11-10 10:18:42 -07:00
parent 0c54d141cb
commit 97d942c8e2
2 changed files with 38 additions and 3 deletions

View File

@@ -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_);
}

View File

@@ -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() {