part two of #204 -- all that remains is to write some test functions

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1383 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-08-26 10:36:18 +00:00
parent 693eab5cc9
commit 57161a94be
2 changed files with 28 additions and 4 deletions

View File

@@ -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,

View File

@@ -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"
};