Merge pull request #10786 from ahocevar/resolve-contraints-on-updatesize

Resolve constraints when updating size
This commit is contained in:
Andreas Hocevar
2020-03-10 13:05:29 +01:00
committed by GitHub
2 changed files with 8 additions and 1 deletions

View File

@@ -405,7 +405,6 @@ class View extends BaseObject {
} else if (options.zoom !== undefined) { } else if (options.zoom !== undefined) {
this.setZoom(options.zoom); this.setZoom(options.zoom);
} }
this.resolveConstraints(0);
this.setProperties(properties); this.setProperties(properties);
@@ -767,6 +766,7 @@ class View extends BaseObject {
*/ */
setViewportSize(opt_size) { setViewportSize(opt_size) {
this.viewportSize_ = Array.isArray(opt_size) ? opt_size.slice() : [100, 100]; this.viewportSize_ = Array.isArray(opt_size) ? opt_size.slice() : [100, 100];
this.resolveConstraints(0);
} }
/** /**

View File

@@ -35,6 +35,7 @@ describe('ol.View', function() {
maxResolution: 1000, maxResolution: 1000,
resolution: 1200 resolution: 1200
}); });
view.setViewportSize();
expect(view.getResolution()).to.eql(1000); expect(view.getResolution()).to.eql(1000);
expect(view.targetResolution_).to.eql(1000); expect(view.targetResolution_).to.eql(1000);
}); });
@@ -45,6 +46,7 @@ describe('ol.View', function() {
minResolution: 128, minResolution: 128,
resolution: 50 resolution: 50
}); });
view.setViewportSize();
expect(view.getResolution()).to.eql(128); expect(view.getResolution()).to.eql(128);
expect(view.targetResolution_).to.eql(128); expect(view.targetResolution_).to.eql(128);
}); });
@@ -54,6 +56,7 @@ describe('ol.View', function() {
resolutions: [1024, 512, 256, 128, 64, 32], resolutions: [1024, 512, 256, 128, 64, 32],
resolution: 1200 resolution: 1200
}); });
view.setViewportSize();
expect(view.getResolution()).to.eql(1024); expect(view.getResolution()).to.eql(1024);
expect(view.targetResolution_).to.eql(1024); expect(view.targetResolution_).to.eql(1024);
@@ -61,6 +64,7 @@ describe('ol.View', function() {
resolutions: [1024, 512, 256, 128, 64, 32], resolutions: [1024, 512, 256, 128, 64, 32],
resolution: 10 resolution: 10
}); });
view.setViewportSize();
expect(view.getResolution()).to.eql(32); expect(view.getResolution()).to.eql(32);
expect(view.targetResolution_).to.eql(32); expect(view.targetResolution_).to.eql(32);
}); });
@@ -70,6 +74,7 @@ describe('ol.View', function() {
minZoom: 3, minZoom: 3,
zoom: 2 zoom: 2
}); });
view.setViewportSize();
expect(view.getZoom()).to.eql(3); expect(view.getZoom()).to.eql(3);
expect(view.targetResolution_).to.eql(view.getMaxResolution()); expect(view.targetResolution_).to.eql(view.getMaxResolution());
}); });
@@ -79,6 +84,7 @@ describe('ol.View', function() {
maxZoom: 4, maxZoom: 4,
zoom: 5 zoom: 5
}); });
view.setViewportSize();
expect(view.getZoom()).to.eql(4); expect(view.getZoom()).to.eql(4);
expect(view.targetResolution_).to.eql(view.getMaxResolution() / Math.pow(2, 4)); expect(view.targetResolution_).to.eql(view.getMaxResolution() / Math.pow(2, 4));
}); });
@@ -89,6 +95,7 @@ describe('ol.View', function() {
extent: [0, 0, 50, 50], extent: [0, 0, 50, 50],
resolution: 1 resolution: 1
}); });
view.setViewportSize();
expect(view.getResolution()).to.eql(0.5); expect(view.getResolution()).to.eql(0.5);
expect(view.targetResolution_).to.eql(0.5); expect(view.targetResolution_).to.eql(0.5);
}); });