diff --git a/src/ol/view.js b/src/ol/view.js index 5b5ef4550f..8ce7350d16 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -238,7 +238,7 @@ ol.View.prototype.animate = function(var_args) { this.maxResolution_, options.zoom - this.minZoom_, 0); resolution = animation.targetResolution; } else if (options.resolution) { - animation.sourceResolution = this.getResolution(); + animation.sourceResolution = resolution; animation.targetResolution = options.resolution; resolution = animation.targetResolution; } diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 2301a7c124..c057b27030 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -546,6 +546,57 @@ describe('ol.View', function() { }); + it('completes complex animation using resolution', function(done) { + + var view = new ol.View({ + center: [0, 0], + resolution: 2 + }); + + var calls = 0; + + function onAnimateEnd() { + if (calls == 2) { + expect(view.getAnimating()).to.be(false); + done(); + } + } + + view.animate({ + center: [100, 100], + duration: 50 + }, function() { + ++calls; + expect(view.getCenter()).to.eql([100, 100]); + onAnimateEnd(); + }); + + view.animate({ + resolution: 2000, + duration: 25 + },{ + resolution: 2, + duration: 25 + }, function() { + ++calls; + expect(view.getResolution()).to.roughlyEqual(2, 1e-8); + onAnimateEnd(); + }); + + setTimeout(function() { + expect(view.getResolution() > 2).to.be(true); + expect(view.getResolution() < 2000).to.be(true); + expect(view.getAnimating()).to.be(true); + }, 10); + + setTimeout(function() { + expect(view.getResolution() > 2).to.be(true); + expect(view.getResolution() < 2000).to.be(true); + expect(view.getAnimating()).to.be(true); + }, 40); + + }); + }); describe('#cancelAnimations()', function() {