Add getResolutionForZoom method for ol.View

This commit is contained in:
Andreas Hocevar
2017-06-28 10:30:32 +02:00
parent 8d0857fd7a
commit aa8d7b0b36
2 changed files with 38 additions and 3 deletions

View File

@@ -805,6 +805,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.
* The size is pixel dimensions of the box to fit the extent into.
@@ -1021,9 +1033,7 @@ ol.View.prototype.setRotation = function(rotation) {
* @api
*/
ol.View.prototype.setZoom = function(zoom) {
var resolution = this.constrainResolution(
this.maxResolution_, zoom - this.minZoom_, 0);
this.setResolution(resolution);
this.setResolution(this.getResolutionForZoom(zoom));
};