diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 06d2aab9ef..f8b288f20e 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -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" diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index 3ccdaaf1c5..962fa72e7e 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -89,49 +89,6 @@ OpenLayers.Layer.WMS.prototype = url, this.tileSize); }, - - - /** - * @returns Degrees per Pixel - * @type float - */ - getResolution: function() { - var maxRes = this.map.getMaxResolution(); - var zoom = this.map.getZoom(); - - 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.Layer.WMS" });