diff --git a/src/ol/View.js b/src/ol/View.js index 4103cd0f48..ffc75f2bd6 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -1290,14 +1290,14 @@ class View extends BaseObject { centerRotY += ((padding[0] - padding[2]) / 2) * resolution; const centerX = centerRotX * cosAngle - centerRotY * sinAngle; const centerY = centerRotY * cosAngle + centerRotX * sinAngle; - const center = [centerX, centerY]; + const center = this.getConstrainedCenter([centerX, centerY], resolution); const callback = options.callback ? options.callback : VOID; if (options.duration !== undefined) { this.animateInternal( { resolution: resolution, - center: this.getConstrainedCenter(center, resolution), + center: center, duration: options.duration, easing: options.easing, }, diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index ca4145b6a7..ae24f773a4 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -1776,6 +1776,12 @@ describe('ol.View', function () { expect(view.getCenter()[0]).to.be(1500); expect(view.getCenter()[1]).to.be(1500); }); + it('fits correctly to the extent when a view extent is configured', function () { + view.options_.extent = [1500, 0, 2500, 10000]; + view.applyOptions_(view.options_); + view.fit([1000, 1000, 2000, 2000]); + expect(view.calculateExtent()).eql([1500, 1000, 2500, 2000]); + }); it('throws on invalid geometry/extent value', function () { expect(function () { view.fit(true, [200, 200]);