Bounds: Simplified extend() method

.. by using the new extendXY() method if the given object is LonLat or a
Point.
This commit is contained in:
Tobias Bieniek
2013-03-23 11:49:17 +01:00
parent b3ce8d556a
commit 467bf66163
+17 -24
View File
@@ -355,40 +355,33 @@ OpenLayers.Bounds = OpenLayers.Class({
* object. * object.
*/ */
extend:function(object) { extend:function(object) {
var bounds = null;
if (object) { if (object) {
switch(object.CLASS_NAME) { switch(object.CLASS_NAME) {
case "OpenLayers.LonLat": case "OpenLayers.LonLat":
bounds = new OpenLayers.Bounds(object.lon, object.lat, this.extendXY(object.lon, object.lat);
object.lon, object.lat);
break; break;
case "OpenLayers.Geometry.Point": case "OpenLayers.Geometry.Point":
bounds = new OpenLayers.Bounds(object.x, object.y, this.extendXY(object.x, object.y);
object.x, object.y);
break; break;
case "OpenLayers.Bounds": case "OpenLayers.Bounds":
bounds = object; // 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; break;
} }
if (bounds) {
// clear cached center location
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;
}
}
} }
}, },