establish generic getExtent() function in Layer. Move resolution-based calculation up into Grid.js. This prevents infinite loops and is more useful to generic layers like Gmaps, VE, etc.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@950 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-07-16 16:55:20 +00:00
parent 629e62b82b
commit 3776a5d729
2 changed files with 57 additions and 40 deletions

View File

@@ -233,6 +233,36 @@ OpenLayers.Layer.prototype = {
extent.getHeight() / viewSize.h );
},
/** Calculates using px-> lonlat translation functions on tl and br
* corners of viewport
*
* @returns A Bounds object which represents the lon/lat bounds of the
* current viewPort.
* @type OpenLayers.Bounds
*/
getExtent: function () {
var extent = null;
var size = this.map.getSize();
var tlPx = new OpenLayers.Pixel(0,0);
var tlLL = this.getLonLatFromViewPortPx(tlPx);
var brPx = new OpenLayers.Pixel(size.w, size.h);
var brLL = this.getLonLatFromViewPortPx(brPx);
if ((tlLL != null) && (brLL != null)) {
extent = new OpenLayers.Bounds(tlLL.lon,
brLL.lat,
brLL.lon,
tlLL.lat);
}
return extent;
},
/**
* @param {OpenLayers.Pixel} viewPortPx
*
@@ -277,47 +307,7 @@ OpenLayers.Layer.prototype = {
// this should be implemented by subclasses
},
/**
* @returns A Bounds object which represents the lon/lat bounds of the
* current viewPort.
* @type OpenLayers.Bounds
*/
getExtent: function () {
// this should be implemented by subclasses
var extent = null;
var center = this.map.getCenter();
if (center != null) {
var res = this.getResolution();
var size = this.map.getSize();
var w_deg = size.w * res;
var h_deg = size.h * res;
return 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;
/** ALT CALCULATION FOR GETEXTENT
var size = this.getSize();
var tlPx = new OpenLayers.Pixel(0,0);
var tlLL = this.getLonLatFromViewPortPx(tlPx);
var brPx = new OpenLayers.Pixel(size.w, size.h);
var brLL = this.getLonLatFromViewPortPx(brPx);
extent = new OpenLayers.Bounds(tlLL.lon,
brLL.lat,
brLL.lon,
tlLL.lat);
**/
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer"