From b1490cf7a967c50b5603e513376ccd8cb02fd1af Mon Sep 17 00:00:00 2001 From: crschmidt Date: Tue, 17 Oct 2006 22:23:19 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Layer.js | 31 ++++++------------------------- lib/OpenLayers/Map.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index e8d4900140..7cd494760d 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -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(); }, /** diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index f85147e768..501c8fa428 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -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 */