diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index e621138776..6d1b698116 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -320,67 +320,6 @@ OpenLayers.Layer.Grid.prototype = }, - /********************************************************/ - /* */ - /* Baselayer Functions */ - /* */ - /********************************************************/ - - /** Calculates based on resolution, center, and mapsize - * - * @returns A Bounds object which represents the lon/lat bounds of the - * current viewPort. - * @type OpenLayers.Bounds - */ - getExtent: function () { - var extent = null; - - var center = this.map.getCenter(); - if (center != null) { - - var res = this.map.getResolution(); - var size = this.map.getSize(); - var w_deg = size.w * res; - var h_deg = size.h * res; - - extent = new OpenLayers.Bounds(center.lon - w_deg / 2, - center.lat - h_deg / 2, - center.lon + w_deg / 2, - center.lat + h_deg / 2); - - } - - return extent; - }, - - /** - * @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; - }, - /** go through and remove all tiles from the grid, calling * destroy() on each of them to kill circular references * @@ -462,6 +401,68 @@ OpenLayers.Layer.Grid.prototype = } }, + /********************************************************/ + /* */ + /* Baselayer Functions */ + /* */ + /********************************************************/ + + /** Calculates based on resolution, center, and mapsize + * + * @returns A Bounds object which represents the lon/lat bounds of the + * current viewPort. + * @type OpenLayers.Bounds + */ + getExtent: function () { + var extent = null; + + var center = this.map.getCenter(); + if (center != null) { + + var res = this.map.getResolution(); + var size = this.map.getSize(); + var w_deg = size.w * res; + var h_deg = size.h * res; + + extent = new OpenLayers.Bounds(center.lon - w_deg / 2, + center.lat - h_deg / 2, + center.lon + w_deg / 2, + center.lat + h_deg / 2); + + } + + return extent; + }, + + /** + * @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.Grid" });