Skip to content

Commit cae4df3

Browse files
committed
Merge pull request #916 from Turbo87/bounds
Added extendXY() method to Bounds class
2 parents 9a06ec4 + 467bf66 commit cae4df3

File tree

2 files changed

+178
-124
lines changed

2 files changed

+178
-124
lines changed

lib/OpenLayers/BaseTypes/Bounds.js

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -355,39 +355,59 @@ OpenLayers.Bounds = OpenLayers.Class({
355355
* object.
356356
*/
357357
extend:function(object) {
358-
var bounds = null;
359358
if (object) {
360-
// clear cached center location
361359
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);
365362
break;
366363
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);
369365
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+
}
373383
break;
374384
}
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;
391411
}
392412
},
393413

0 commit comments

Comments
 (0)