Merge pull request #7122 from tschaub/unanimated

Immediately complete no-op animations
This commit is contained in:
Tim Schaub
2017-08-14 09:43:39 -04:00
committed by GitHub
2 changed files with 131 additions and 3 deletions

View File

@@ -302,7 +302,14 @@ ol.View.prototype.animate = function(var_args) {
}
animation.callback = callback;
start += animation.duration;
// check if animation is a no-op
if (ol.View.isNoopAnimation(animation)) {
animation.complete = true;
// we still push it onto the series for callback handling
} else {
start += animation.duration;
}
series.push(animation);
}
this.animations_.push(series);
@@ -1158,3 +1165,24 @@ ol.View.createRotationConstraint_ = function(options) {
return ol.RotationConstraint.disable;
}
};
/**
* Determine if an animation involves no view change.
* @param {ol.ViewAnimation} animation The animation.
* @return {boolean} The animation involves no view change.
*/
ol.View.isNoopAnimation = function(animation) {
if (animation.sourceCenter && animation.targetCenter) {
if (!ol.coordinate.equals(animation.sourceCenter, animation.targetCenter)) {
return false;
}
}
if (animation.sourceResolution !== animation.targetResolution) {
return false;
}
if (animation.sourceRotation !== animation.targetRotation) {
return false;
}
return true;
};