allow an uninitialized Bounds object to be functional (and extendable). thanks for the extra docs cr5 (Closes #929)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@4049 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,7 +4,17 @@
|
||||
<script type="text/javascript"><!--
|
||||
var bounds;
|
||||
function test_01_Bounds_constructor (t) {
|
||||
t.plan( 11 );
|
||||
t.plan( 17 );
|
||||
|
||||
bounds = new OpenLayers.Bounds();
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
||||
t.eq( bounds.CLASS_NAME, "OpenLayers.Bounds", "bounds.CLASS_NAME is set correctly" );
|
||||
t.eq( bounds.left, null, "bounds.left is initialized to null" );
|
||||
t.eq( bounds.bottom, null, "bounds.bottom is initialized to null" );
|
||||
t.eq( bounds.right, null, "bounds.right is initialized to null" );
|
||||
t.eq( bounds.top, null, "bounds.top is initialized to null" );
|
||||
|
||||
|
||||
bounds = new OpenLayers.Bounds(0,2,10,4);
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
||||
t.eq( bounds.CLASS_NAME, "OpenLayers.Bounds", "bounds.CLASS_NAME is set correctly" );
|
||||
@@ -298,11 +308,19 @@
|
||||
|
||||
|
||||
function test_16_Bounds_extend(t) {
|
||||
t.plan( 8 );
|
||||
|
||||
var originalBounds = new OpenLayers.Bounds(10,20,50,80);
|
||||
t.plan( 9 );
|
||||
|
||||
var originalBounds = new OpenLayers.Bounds();
|
||||
var bounds = originalBounds.clone();
|
||||
//null bounds to start
|
||||
bounds.extend(new OpenLayers.LonLat(4,5));
|
||||
t.ok(bounds.equals(new OpenLayers.Bounds(4,5,4,5)), "uninitialized bounds can be safely extended");
|
||||
|
||||
|
||||
|
||||
originalBounds = new OpenLayers.Bounds(10,20,50,80);
|
||||
|
||||
bounds = originalBounds.clone();
|
||||
|
||||
//null obj
|
||||
bounds.extend(null);
|
||||
|
||||
Reference in New Issue
Block a user