Move getZoomForExtent from WMS to Grid. This also applies to WorldWind and KaMap, so having it in Grid.js means we can use it in more cases where it will matter.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@820 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-06-28 02:51:37 +00:00
parent 69c599b881
commit dcb0f24f50
2 changed files with 28 additions and 43 deletions

View File

@@ -316,6 +316,34 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
return maxRes / Math.pow(2, zoom);
},
/**
* @param {OpenLayers.Bounds} bounds
*
* @return {int}
*/
getZoomForExtent: function (bounds) {
var maxRes = this.map.getMaxResolution();
var viewSize = this.map.getSize();
var width = bounds.getWidth();
var height = bounds.getHeight();
var degPerPixel = (width > height) ? width / viewSize.w
: height / viewSize.h;
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
var maxZoomLevel = this.map.getMaxZoomLevel();
var minZoomLevel = this.map.getMinZoomLevel();
//make sure zoom is within bounds
zoom = Math.min( Math.max(zoom, minZoomLevel),
maxZoomLevel );
return zoom;
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Grid"