Merge pull request #858 from elemoine/getzoom

Add ol.View2D#getZoom
This commit is contained in:
Éric Lemoine
2013-07-11 00:51:25 -07:00
3 changed files with 58 additions and 0 deletions

View File

@@ -4,4 +4,5 @@
@exportProperty ol.View2D.prototype.constrainRotation
@exportProperty ol.View2D.prototype.fitExtent
@exportProperty ol.View2D.prototype.getView2D
@exportProperty ol.View2D.prototype.getZoom
@exportProperty ol.View2D.prototype.setZoom

View File

@@ -363,6 +363,31 @@ ol.View2D.prototype.getView3D = function() {
};
/**
* Get the current zoom level. Return undefined if the current
* resolution is undefined or not a "constrained resolution".
* @return {number|undefined} Zoom.
*/
ol.View2D.prototype.getZoom = function() {
var zoom;
var resolution = this.getResolution();
if (goog.isDef(resolution)) {
var res, z = 0;
do {
res = this.constrainResolution(this.maxResolution_, z);
if (res == resolution) {
zoom = z;
break;
}
++z;
} while (res > this.minResolution_);
}
return zoom;
};
/**
* Fit the given extent based on the given map size.
* @param {ol.Extent} extent Extent.