Test animation callback
This commit is contained in:
@@ -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)
|
||||
* }}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user