diff --git a/lib/OpenLayers/BaseTypes/Bounds.js b/lib/OpenLayers/BaseTypes/Bounds.js index 90e7fbce04..49a330512e 100644 --- a/lib/OpenLayers/BaseTypes/Bounds.js +++ b/lib/OpenLayers/BaseTypes/Bounds.js @@ -5,7 +5,14 @@ /** * Class: OpenLayers.Bounds * Instances of this class represent bounding boxes. Data stored as left, - * bottom, right, top floats + * bottom, right, top floats. All values are initialized to null, however, + * you should make sure you set them before using the bounds for anything. + * Possible use case: + * + * > bounds = new OpenLayers.Bounds(); + * > bounds.extend(new OpenLayers.LonLat(4,5)); + * > bounds.extend(new OpenLayers.LonLat(5,6)); + * > bounds.toBBOX() // returns 4,5,5,6 */ OpenLayers.Bounds = OpenLayers.Class({ @@ -13,25 +20,25 @@ OpenLayers.Bounds = OpenLayers.Class({ * Property: left * {Number} */ - left: 0.0, + left: null, /** * Property: bottom * {Number} */ - bottom: 0.0, + bottom: null, /** * Property: right * {Number} */ - right: 0.0, + right: null, /** * Property: top * {Number} */ - top: 0.0, + top: null, /** * Constructor: OpenLayers.Bounds @@ -46,10 +53,18 @@ OpenLayers.Bounds = OpenLayers.Class({ * top - {Number} The top bounds. */ initialize: function(left, bottom, right, top) { - this.left = parseFloat(left); - this.bottom = parseFloat(bottom); - this.right = parseFloat(right); - this.top = parseFloat(top); + if (left != null) { + this.left = parseFloat(left); + } + if (bottom != null) { + this.bottom = parseFloat(bottom); + } + if (right != null) { + this.right = parseFloat(right); + } + if (top != null) { + this.top = parseFloat(top); + } }, /** @@ -237,14 +252,18 @@ OpenLayers.Bounds = OpenLayers.Class({ } if (bounds) { - this.left = (bounds.left < this.left) ? bounds.left - : this.left; - this.bottom = (bounds.bottom < this.bottom) ? bounds.bottom - : this.bottom; - this.right = (bounds.right > this.right) ? bounds.right - : this.right; - this.top = (bounds.top > this.top) ? bounds.top - : this.top; + 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; + } } } }, diff --git a/tests/BaseTypes/test_Bounds.html b/tests/BaseTypes/test_Bounds.html index f9a403fbb0..6b9e8c5899 100644 --- a/tests/BaseTypes/test_Bounds.html +++ b/tests/BaseTypes/test_Bounds.html @@ -4,7 +4,17 @@