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:
@@ -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();
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user