Use calculateBounds function from patch on #228. This is a refactoring of the

code that Tim Schaub contributed on that patch. Thanks Tim!


git-svn-id: http://svn.openlayers.org/trunk/openlayers@1702 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-10-17 22:23:19 +00:00
parent 97f92fb3a8
commit b1490cf7a9
2 changed files with 41 additions and 25 deletions

View File

@@ -445,35 +445,16 @@ OpenLayers.Layer.prototype = {
return this.resolutions[zoom];
},
/** 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(resolution) {
var extent = null;
var center = this.map.getCenter();
if (center != null) {
if (resolution == null) {
resolution = this.getResolution();
}
var size = this.map.getSize();
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,
center.lon + w_deg / 2,
center.lat + h_deg / 2);
}
return extent;
getExtent: function() {
// just use stock map calculateBounds function -- passing no arguments
// means it will user map's current center & resolution
//
return this.map.calculateBounds();
},
/**

View File

@@ -607,6 +607,41 @@ OpenLayers.Map.prototype = {
return size;
},
/**
* @param {OpenLayers.LonLat} center Default is this.getCenter()
* @param {float} resolution Default is this.getResolution()
*
* @returns A Bounds based on resolution, center, and current mapsize.
* @type OpenLayers.Bounds
*/
calculateBounds: function(center, resolution) {
var extent = null;
if (center == null) {
center = this.getCenter();
}
if (resolution == null) {
resolution = this.getResolution();
}
if ((center != null) && (resolution != null)) {
var size = this.getSize();
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,
center.lon + w_deg / 2,
center.lat + h_deg / 2);
}
return extent;
},
/********************************************************/
/* */
/* Zoom, Center, Pan Functions */