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];
|
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
|
* @returns A Bounds object which represents the lon/lat bounds of the
|
||||||
* current viewPort.
|
* current viewPort.
|
||||||
* @type OpenLayers.Bounds
|
* @type OpenLayers.Bounds
|
||||||
*/
|
*/
|
||||||
getExtent: function(resolution) {
|
getExtent: function() {
|
||||||
var extent = null;
|
// just use stock map calculateBounds function -- passing no arguments
|
||||||
|
// means it will user map's current center & resolution
|
||||||
var center = this.map.getCenter();
|
//
|
||||||
if (center != null) {
|
return this.map.calculateBounds();
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -607,6 +607,41 @@ OpenLayers.Map.prototype = {
|
|||||||
return size;
|
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 */
|
/* Zoom, Center, Pan Functions */
|
||||||
|
|||||||
Reference in New Issue
Block a user