Instances of this class represent bounding boxes. Data stored as left, bottom, right, top floats. All values are initialized to null, however, you should make sure you set them before using the bounds for anything.
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. | Instances of this class represent bounding boxes. |
Constructor | |
OpenLayers. | Construct a new bounds object. |
Functions | |
toString | Returns a string representation of the bounds object. |
toArray | Returns an array representation of the bounds object. |
toBBOX | Returns a boundingbox-string representation of the bounds object. |
toGeometry | Create a new polygon geometry based on this bounds. |
getWidth | Returns the width of the bounds. |
getHeight | Returns the height of the bounds. |
getSize | Returns an OpenLayers.Size object of the bounds. |
getCenterPixel | Returns the OpenLayers.Pixel object which represents the center of the bounds. |
getCenterLonLat | Returns the OpenLayers.LonLat object which represents the center of the bounds. |
scale | Scales the bounds around a pixel or lonlat. |
add | Shifts the coordinates of the bound by the given horizontal and vertical deltas. |
extend | Extend the bounds to include the OpenLayers.LonLat, OpenLayers.Geometry.Point or OpenLayers.Bounds specified. |
extendXY | Extend the bounds to include the XY coordinate specified. |
containsLonLat | Returns whether the bounds object contains the given OpenLayers.LonLat. |
containsPixel | Returns whether the bounds object contains the given OpenLayers.Pixel. |
contains | Returns whether the bounds object contains the given x and y. |
intersectsBounds | Determine whether the target bounds intersects this bounds. |
containsBounds | Returns whether the bounds object contains the given OpenLayers.Bounds. |
determineQuadrant | Returns the the quadrant (“br”, “tr”, “tl”, “bl”) in which the given OpenLayers.LonLat lies. |
transform | Transform the Bounds object from source to dest. |
fromString | Alternative constructor that builds a new OpenLayers.Bounds from a parameter string. |
fromArray | Alternative constructor that builds a new OpenLayers.Bounds from an array. |
fromSize | Alternative constructor that builds a new OpenLayers.Bounds from a size. |
Construct a new bounds object. Coordinates can either be passed as four arguments, or as a single argument.
left | {Number} The left bounds of the box. Note that for width calculations, this is assumed to be less than the right value. |
bottom | {Number} The bottom bounds of the box. Note that for height calculations, this is assumed to be less than the top value. |
right | {Number} The right bounds. |
top | {Number} The top bounds. |
bounds | {Array(Number)} [left, bottom, right, top] |
toArray: function( reverseAxisOrder )
Returns an array representation of the bounds object.
Returns an array of left, bottom, right, top properties, or -- when the optional parameter is true -- an array of the bottom, left, top, right properties.
reverseAxisOrder | {Boolean} Should we reverse the axis order? |
{Array} array of left, bottom, right, top
toBBOX:function( decimal, reverseAxisOrder )
Returns a boundingbox-string representation of the bounds object.
decimal | {Integer} How many significant digits in the bbox coords? Default is 6 |
reverseAxisOrder | {Boolean} Should we reverse the axis order? |
{String} Simple String representation of bounds object. (e.g. “5,42,10,45”)
toGeometry: function()
Create a new polygon geometry based on this bounds.
{OpenLayers.Geometry.Polygon} A new polygon with the coordinates of this bounds.
getSize:function()
Returns an OpenLayers.Size object of the bounds.
{OpenLayers.Size} The size of the bounds.
getCenterPixel:function()
Returns the OpenLayers.Pixel object which represents the center of the bounds.
{OpenLayers.Pixel} The center of the bounds in pixel space.
getCenterLonLat:function()
Returns the OpenLayers.LonLat object which represents the center of the bounds.
{OpenLayers.LonLat} The center of the bounds in map space.
scale: function( ratio, origin )
Scales the bounds around a pixel or lonlat. Note that the new bounds may return non-integer properties, even if a pixel is passed.
ratio | {Float} |
origin | {OpenLayers.Pixel or OpenLayers.LonLat} Default is center. |
{OpenLayers.Bounds} A new bounds that is scaled by ratio from origin.
add:function( x, y )
Shifts the coordinates of the bound by the given horizontal and vertical deltas.
var bounds = new OpenLayers.Bounds(0, 0, 10, 10); bounds.toString(); // => "0,0,10,10" bounds.add(-1.5, 4).toString(); // => "-1.5,4,8.5,14"
This method will throw a TypeError if it is passed null as an argument.
x | {Float} horizontal delta |
y | {Float} vertical delta |
{OpenLayers.Bounds} A new bounds whose coordinates are the same as this, but shifted by the passed-in x and y values.
extend:function( object )
Extend the bounds to include the OpenLayers.LonLat, OpenLayers.Geometry.Point or OpenLayers.Bounds specified.
Please note that this function assumes that left < right and bottom < top.
object | {OpenLayers.LonLat, OpenLayers.Geometry.Point or OpenLayers.Bounds} The object to be included in the new bounds object. |
containsLonLat: function( ll, options )
Returns whether the bounds object contains the given OpenLayers.LonLat.
ll | {<OpenLayers.LonLat>|Object} OpenLayers.LonLat or an object with a ‘lon’ and ‘lat’ properties. |
options | {Object} Optional parameters |
inclusive | {Boolean} Whether or not to include the border. Default is true. |
worldBounds | {OpenLayers.Bounds} If a worldBounds is provided, the ll will be considered as contained if it exceeds the world bounds, but can be wrapped around the dateline so it is contained by this bounds. |
{Boolean} The passed-in lonlat is within this bounds.
containsPixel:function( px, inclusive )
Returns whether the bounds object contains the given OpenLayers.Pixel.
px | {OpenLayers.Pixel} |
inclusive | {Boolean} Whether or not to include the border. Default is true. |
{Boolean} The passed-in pixel is within this bounds.
intersectsBounds:function( bounds, options )
Determine whether the target bounds intersects this bounds. Bounds are considered intersecting if any of their edges intersect or if one bounds contains the other.
bounds | {OpenLayers.Bounds} The target bounds. |
options | {Object} Optional parameters. |
inclusive | {Boolean} Treat coincident borders as intersecting. Default is true. If false, bounds that do not overlap but only touch at the border will not be considered as intersecting. |
worldBounds | {OpenLayers.Bounds} If a worldBounds is provided, two bounds will be considered as intersecting if they intersect when shifted to within the world bounds. This applies only to bounds that cross or are completely outside the world bounds. |
{Boolean} The passed-in bounds object intersects this bounds.
containsBounds:function( bounds, partial, inclusive )
Returns whether the bounds object contains the given OpenLayers.Bounds.
bounds | {OpenLayers.Bounds} The target bounds. |
partial | {Boolean} If any of the target corners is within this bounds consider the bounds contained. Default is false. If false, the entire target bounds must be contained within this bounds. |
inclusive | {Boolean} Treat shared edges as contained. Default is true. |
{Boolean} The passed-in bounds object is contained within this bounds.
determineQuadrant: function( lonlat )
Returns the the quadrant (“br”, “tr”, “tl”, “bl”) in which the given OpenLayers.LonLat lies.
lonlat | {OpenLayers.LonLat} |
{String} The quadrant (“br” “tr” “tl” “bl”) of the bounds in which the coordinate lies.
transform: function( source, dest )
Transform the Bounds object from source to dest.
source | {OpenLayers.Projection} Source projection. |
dest | {OpenLayers.Projection} Destination projection. |
{OpenLayers.Bounds} Itself, for use in chaining operations.
OpenLayers.Bounds.fromString = function( str, reverseAxisOrder )
Alternative constructor that builds a new OpenLayers.Bounds from a parameter string.
OpenLayers.Bounds.fromString("5,42,10,45"); // => equivalent to ... new OpenLayers.Bounds(5, 42, 10, 45);
str | {String} Comma-separated bounds string. (e.g. “5,42,10,45”) |
reverseAxisOrder | {Boolean} Does the string use reverse axis order? |
{OpenLayers.Bounds} New bounds object built from the passed-in String.
OpenLayers.Bounds.fromArray = function( bbox, reverseAxisOrder )
Alternative constructor that builds a new OpenLayers.Bounds from an array.
OpenLayers.Bounds.fromArray( [5, 42, 10, 45] ); // => equivalent to ... new OpenLayers.Bounds(5, 42, 10, 45);
bbox | {Array(Float)} Array of bounds values (e.g. [5,42,10,45]) |
reverseAxisOrder | {Boolean} Does the array use reverse axis order? |
{OpenLayers.Bounds} New bounds object built from the passed-in Array.
OpenLayers.Bounds.fromSize = function( size )
Alternative constructor that builds a new OpenLayers.Bounds from a size.
OpenLayers.Bounds.fromSize( new OpenLayers.Size(10, 20) ); // => equivalent to ... new OpenLayers.Bounds(0, 20, 10, 0);
size | {OpenLayers.Size or Object} OpenLayers.Size or an object with both ‘w’ and ‘h’ properties. |
{OpenLayers.Bounds} New bounds object built from the passed-in size.
Returns a string representation of the bounds object.
toString:function()
Returns an array representation of the bounds object.
toArray: function( reverseAxisOrder )
Returns a boundingbox-string representation of the bounds object.
toBBOX:function( decimal, reverseAxisOrder )
Create a new polygon geometry based on this bounds.
toGeometry: function()
Returns the width of the bounds.
getWidth:function()
Returns the height of the bounds.
getHeight:function()
Returns an OpenLayers.Size object of the bounds.
getSize:function()
Returns the OpenLayers.Pixel object which represents the center of the bounds.
getCenterPixel:function()
Returns the OpenLayers.LonLat object which represents the center of the bounds.
getCenterLonLat:function()
Scales the bounds around a pixel or lonlat.
scale: function( ratio, origin )
Shifts the coordinates of the bound by the given horizontal and vertical deltas.
add:function( x, y )
Extend the bounds to include the OpenLayers.LonLat, OpenLayers.Geometry.Point or OpenLayers.Bounds specified.
extend:function( object )
Extend the bounds to include the XY coordinate specified.
extendXY:function( x, y )
Returns whether the bounds object contains the given OpenLayers.LonLat.
containsLonLat: function( ll, options )
Returns whether the bounds object contains the given OpenLayers.Pixel.
containsPixel:function( px, inclusive )
Returns whether the bounds object contains the given x and y.
contains:function( x, y, inclusive )
Determine whether the target bounds intersects this bounds.
intersectsBounds:function( bounds, options )
Returns whether the bounds object contains the given OpenLayers.Bounds.
containsBounds:function( bounds, partial, inclusive )
Returns the the quadrant (“br”, “tr”, “tl”, “bl”) in which the given OpenLayers.LonLat lies.
determineQuadrant: function( lonlat )
Transform the Bounds object from source to dest.
transform: function( source, dest )
Alternative constructor that builds a new OpenLayers.Bounds from a parameter string.
OpenLayers.Bounds.fromString = function( str, reverseAxisOrder )
Alternative constructor that builds a new OpenLayers.Bounds from an array.
OpenLayers.Bounds.fromArray = function( bbox, reverseAxisOrder )
Alternative constructor that builds a new OpenLayers.Bounds from a size.
OpenLayers.Bounds.fromSize = function( size )