diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index bd3ee9d0a9..b12fa52488 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -336,20 +336,24 @@ OpenLayers.Layer.prototype = { /** Calculates based on resolution, center, and mapsize * + * @param {float} resolution Specific resolution to get an extent for. + * If null, this.getResolution() is called * @returns A Bounds object which represents the lon/lat bounds of the * current viewPort. * @type OpenLayers.Bounds */ - getExtent: function () { + getExtent: function(resolution) { var extent = null; var center = this.map.getCenter(); if (center != null) { - var res = this.getResolution(); + if (resolution == null) { + resolution = this.getResolution(); + } var size = this.map.getSize(); - var w_deg = size.w * res; - var h_deg = size.h * res; + var w_deg = size.w * resolution; + var h_deg = size.h * resolution; extent = new OpenLayers.Bounds(center.lon - w_deg / 2, center.lat - h_deg / 2, diff --git a/lib/OpenLayers/Layer/FixedZoomLevels.js b/lib/OpenLayers/Layer/FixedZoomLevels.js index 6918e93640..55d6498a62 100644 --- a/lib/OpenLayers/Layer/FixedZoomLevels.js +++ b/lib/OpenLayers/Layer/FixedZoomLevels.js @@ -27,6 +27,11 @@ * taken from the pixel locations (0,0) and the size of the map. But how * will we be able to do lonlat-px translation without resolution....? * + * The getZoomForResolution() method is overridden. Instead of indexing into + * the resolutions[] array, we call OpenLayers.Layer.getExent(), passing in + * the desired resolution. With this extent, we then call getZoomForExtent() + * + * * Whenever you implement a layer using OpenLayers.Layer.FixedZoomLevels, * it is your responsibility to provide the following three functions: * @@ -107,6 +112,21 @@ OpenLayers.Layer.FixedZoomLevels.prototype = { return extent; }, + /** + * @param {float} resolution + * + * @returns A suitable zoom level for the specified resolution. + * If no baselayer is set, returns null. + * @type int + */ + getZoomForResolution: function(resolution) { + + var extent = OpenLayers.Layer.prototype.getExtent.apply(this, + [resolution]); + + return this.getZoomForExtent(extent); + }, + /** @final @type String */ CLASS_NAME: "FixedZoomLevels.js" };