Reset hint first and notify of change when cancelling animations
This commit is contained in:
@@ -272,6 +272,7 @@ ol.View.prototype.getAnimating = function() {
|
||||
* Cancel any ongoing animations.
|
||||
*/
|
||||
ol.View.prototype.cancelAnimations = function() {
|
||||
this.setHint(ol.View.Hint.ANIMATING, -this.getHints()[ol.View.Hint.ANIMATING]);
|
||||
for (var i = 0, ii = this.animations_.length; i < ii; ++i) {
|
||||
var series = this.animations_[i];
|
||||
if (series[0].callback) {
|
||||
@@ -279,7 +280,7 @@ ol.View.prototype.cancelAnimations = function() {
|
||||
}
|
||||
}
|
||||
this.animations_.length = 0;
|
||||
this.setHint(ol.View.Hint.ANIMATING, -this.getHints()[ol.View.Hint.ANIMATING]);
|
||||
this.changed(); // notify that the hint changed
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -519,6 +519,100 @@ describe('ol.View', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#cancelAnimations()', function() {
|
||||
|
||||
var originalRequestAnimationFrame = window.requestAnimationFrame;
|
||||
var originalCancelAnimationFrame = window.cancelAnimationFrame;
|
||||
|
||||
beforeEach(function() {
|
||||
window.requestAnimationFrame = function(callback) {
|
||||
return setTimeout(callback, 1);
|
||||
};
|
||||
window.cancelAnimationFrame = function(key) {
|
||||
return clearTimeout(key);
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
window.requestAnimationFrame = originalRequestAnimationFrame;
|
||||
window.cancelAnimationFrame = originalCancelAnimationFrame;
|
||||
});
|
||||
|
||||
it('cancels a currently running animation', function(done) {
|
||||
var view = new ol.View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
rotation: 0
|
||||
});
|
||||
|
||||
view.animate({
|
||||
rotation: 10,
|
||||
duration: 50
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
expect(view.getAnimating()).to.be(true);
|
||||
view.once('change', function() {
|
||||
expect(view.getAnimating()).to.be(false);
|
||||
done();
|
||||
});
|
||||
view.cancelAnimations();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('cancels a multiple animations', function(done) {
|
||||
var view = new ol.View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
rotation: 0
|
||||
});
|
||||
|
||||
view.animate({
|
||||
rotation: 10,
|
||||
duration: 50
|
||||
}, {
|
||||
zoom: 10,
|
||||
duration: 50
|
||||
});
|
||||
|
||||
view.animate({
|
||||
center: [10, 30],
|
||||
duration: 100
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
expect(view.getAnimating()).to.be(true);
|
||||
view.once('change', function() {
|
||||
expect(view.getAnimating()).to.be(false);
|
||||
done();
|
||||
});
|
||||
view.cancelAnimations();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('calls callbacks with false to indicate animations did not complete', function(done) {
|
||||
var view = new ol.View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
});
|
||||
|
||||
view.animate({
|
||||
zoom: 10,
|
||||
duration: 50
|
||||
}, function(complete) {
|
||||
expect(view.getAnimating()).to.be(false);
|
||||
expect(complete).to.be(false);
|
||||
done();
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
expect(view.getAnimating()).to.be(true);
|
||||
view.cancelAnimations();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getResolutions', function() {
|
||||
var view;
|
||||
var resolutions = [512, 256, 128, 64, 32, 16];
|
||||
|
||||
Reference in New Issue
Block a user