Merge pull request #6966 from ahocevar/resolution-for-zoom
Add getResolutionForZoom method for ol.View
This commit is contained in:
+13
-3
@@ -809,6 +809,18 @@ ol.View.prototype.getZoomForResolution = function(resolution) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the resolution for a zoom level.
|
||||||
|
* @param {number} zoom Zoom level.
|
||||||
|
* @return {number} The view resolution for the provided zoom level.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.View.prototype.getResolutionForZoom = function(zoom) {
|
||||||
|
return /** @type {number} */ (this.constrainResolution(
|
||||||
|
this.maxResolution_, zoom - this.minZoom_, 0));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fit the given geometry or extent based on the given map size and border.
|
* Fit the given geometry or extent based on the given map size and border.
|
||||||
* The size is pixel dimensions of the box to fit the extent into.
|
* The size is pixel dimensions of the box to fit the extent into.
|
||||||
@@ -1025,9 +1037,7 @@ ol.View.prototype.setRotation = function(rotation) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.View.prototype.setZoom = function(zoom) {
|
ol.View.prototype.setZoom = function(zoom) {
|
||||||
var resolution = this.constrainResolution(
|
this.setResolution(this.getResolutionForZoom(zoom));
|
||||||
this.maxResolution_, zoom - this.minZoom_, 0);
|
|
||||||
this.setResolution(resolution);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -988,6 +988,31 @@ describe('ol.View', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getResolutionForZoom', function() {
|
||||||
|
|
||||||
|
it('returns correct zoom resolution', function() {
|
||||||
|
var view = new ol.View();
|
||||||
|
var max = view.getMaxZoom();
|
||||||
|
var min = view.getMinZoom();
|
||||||
|
|
||||||
|
expect(view.getResolutionForZoom(max)).to.be(view.getMinResolution());
|
||||||
|
expect(view.getResolutionForZoom(min)).to.be(view.getMaxResolution());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns correct zoom levels for specifically configured resolutions', function() {
|
||||||
|
var view = new ol.View({
|
||||||
|
resolutions: [10, 8, 6, 4, 2]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(view.getResolutionForZoom(0)).to.be(10);
|
||||||
|
expect(view.getResolutionForZoom(1)).to.be(8);
|
||||||
|
expect(view.getResolutionForZoom(2)).to.be(6);
|
||||||
|
expect(view.getResolutionForZoom(3)).to.be(4);
|
||||||
|
expect(view.getResolutionForZoom(4)).to.be(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#getMaxZoom', function() {
|
describe('#getMaxZoom', function() {
|
||||||
|
|
||||||
it('returns the zoom level for the min resolution', function() {
|
it('returns the zoom level for the min resolution', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user