@@ -355,39 +355,59 @@ OpenLayers.Bounds = OpenLayers.Class({
355
355
* object.
356
356
*/
357
357
extend :function ( object ) {
358
- var bounds = null ;
359
358
if ( object ) {
360
- // clear cached center location
361
359
switch ( object . CLASS_NAME ) {
362
- case "OpenLayers.LonLat" :
363
- bounds = new OpenLayers . Bounds ( object . lon , object . lat ,
364
- object . lon , object . lat ) ;
360
+ case "OpenLayers.LonLat" :
361
+ this . extendXY ( object . lon , object . lat ) ;
365
362
break ;
366
363
case "OpenLayers.Geometry.Point" :
367
- bounds = new OpenLayers . Bounds ( object . x , object . y ,
368
- object . x , object . y ) ;
364
+ this . extendXY ( object . x , object . y ) ;
369
365
break ;
370
-
371
- case "OpenLayers.Bounds" :
372
- bounds = object ;
366
+
367
+ case "OpenLayers.Bounds" :
368
+ // clear cached center location
369
+ this . centerLonLat = null ;
370
+
371
+ if ( ( this . left == null ) || ( object . left < this . left ) ) {
372
+ this . left = object . left ;
373
+ }
374
+ if ( ( this . bottom == null ) || ( object . bottom < this . bottom ) ) {
375
+ this . bottom = object . bottom ;
376
+ }
377
+ if ( ( this . right == null ) || ( object . right > this . right ) ) {
378
+ this . right = object . right ;
379
+ }
380
+ if ( ( this . top == null ) || ( object . top > this . top ) ) {
381
+ this . top = object . top ;
382
+ }
373
383
break ;
374
384
}
375
-
376
- if ( bounds ) {
377
- this . centerLonLat = null ;
378
- if ( ( this . left == null ) || ( bounds . left < this . left ) ) {
379
- this . left = bounds . left ;
380
- }
381
- if ( ( this . bottom == null ) || ( bounds . bottom < this . bottom ) ) {
382
- this . bottom = bounds . bottom ;
383
- }
384
- if ( ( this . right == null ) || ( bounds . right > this . right ) ) {
385
- this . right = bounds . right ;
386
- }
387
- if ( ( this . top == null ) || ( bounds . top > this . top ) ) {
388
- this . top = bounds . top ;
389
- }
390
- }
385
+ }
386
+ } ,
387
+
388
+ /**
389
+ * APIMethod: extendXY
390
+ * Extend the bounds to include the XY coordinate specified.
391
+ *
392
+ * Parameters:
393
+ * x - {number} The X part of the the coordinate.
394
+ * y - {number} The Y part of the the coordinate.
395
+ */
396
+ extendXY :function ( x , y ) {
397
+ // clear cached center location
398
+ this . centerLonLat = null ;
399
+
400
+ if ( ( this . left == null ) || ( x < this . left ) ) {
401
+ this . left = x ;
402
+ }
403
+ if ( ( this . bottom == null ) || ( y < this . bottom ) ) {
404
+ this . bottom = y ;
405
+ }
406
+ if ( ( this . right == null ) || ( x > this . right ) ) {
407
+ this . right = x ;
408
+ }
409
+ if ( ( this . top == null ) || ( y > this . top ) ) {
410
+ this . top = y ;
391
411
}
392
412
} ,
393
413
0 commit comments