From dcb0f24f50e9f45692266ca09c98a66aa3e287ef Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 28 Jun 2006 02:51:37 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Layer/Grid.js | 28 +++++++++++++++++++++++ lib/OpenLayers/Layer/WMS.js | 43 ------------------------------------ 2 files changed, 28 insertions(+), 43 deletions(-) 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" });