diff --git a/lib/OpenLayers/BaseTypes/Bounds.js b/lib/OpenLayers/BaseTypes/Bounds.js index 1e1e3715f0..a828eb0cc2 100644 --- a/lib/OpenLayers/BaseTypes/Bounds.js +++ b/lib/OpenLayers/BaseTypes/Bounds.js @@ -355,39 +355,59 @@ OpenLayers.Bounds = OpenLayers.Class({ * object. */ extend:function(object) { - var bounds = null; if (object) { - // clear cached center location switch(object.CLASS_NAME) { - case "OpenLayers.LonLat": - bounds = new OpenLayers.Bounds(object.lon, object.lat, - object.lon, object.lat); + case "OpenLayers.LonLat": + this.extendXY(object.lon, object.lat); break; case "OpenLayers.Geometry.Point": - bounds = new OpenLayers.Bounds(object.x, object.y, - object.x, object.y); + this.extendXY(object.x, object.y); break; - - case "OpenLayers.Bounds": - bounds = object; + + case "OpenLayers.Bounds": + // clear cached center location + this.centerLonLat = null; + + if ( (this.left == null) || (object.left < this.left)) { + this.left = object.left; + } + if ( (this.bottom == null) || (object.bottom < this.bottom) ) { + this.bottom = object.bottom; + } + if ( (this.right == null) || (object.right > this.right) ) { + this.right = object.right; + } + if ( (this.top == null) || (object.top > this.top) ) { + this.top = object.top; + } break; } - - if (bounds) { - this.centerLonLat = null; - if ( (this.left == null) || (bounds.left < this.left)) { - this.left = bounds.left; - } - if ( (this.bottom == null) || (bounds.bottom < this.bottom) ) { - this.bottom = bounds.bottom; - } - if ( (this.right == null) || (bounds.right > this.right) ) { - this.right = bounds.right; - } - if ( (this.top == null) || (bounds.top > this.top) ) { - this.top = bounds.top; - } - } + } + }, + + /** + * APIMethod: extendXY + * Extend the bounds to include the XY coordinate specified. + * + * Parameters: + * x - {number} The X part of the the coordinate. + * y - {number} The Y part of the the coordinate. + */ + extendXY:function(x, y) { + // clear cached center location + this.centerLonLat = null; + + if ((this.left == null) || (x < this.left)) { + this.left = x; + } + if ((this.bottom == null) || (y < this.bottom)) { + this.bottom = y; + } + if ((this.right == null) || (x > this.right)) { + this.right = x; + } + if ((this.top == null) || (y > this.top)) { + this.top = y; } }, diff --git a/tests/BaseTypes/Bounds.html b/tests/BaseTypes/Bounds.html index a1497cf6da..bdfeaf2af5 100644 --- a/tests/BaseTypes/Bounds.html +++ b/tests/BaseTypes/Bounds.html @@ -2,10 +2,10 @@