Class: Bounds

cercaliagl.Bounds


Javascript ES5

const bounds = new cercaliagl.Bounds();

Bounding box classes with multiple methods. It's a rectangle with geographical coordinates (WGS84 - https://es.wikipedia.org/wiki/WGS84):
This is useful for some spatial calculations.
Coordinates order in array is: [left, bottom, right, top].

Example usage:

  const bounds = new cercaliagl.Bounds([-23.62473534670107,31.285369382485797,18.56276465329893,47.98055500672558]);
  map.fitBounds(bounds); // Fit map to bounds
  const marker = new cercaliagl.Marker({ position: bounds.getCenterLonLat(), simpleLabel: new cercaliagl.SimpleLabe({text: 'Center bbox'})});
  map.addMarker(marker);

new Bounds(arrCoord, {boundsOptions})

Name Type Description
arrCoord Array.<number>

Coordinates [left, bottom, right, top]. Coordinates in EPSG:4326 projection.

{boundsOptions}

Bounds options. Default: undefined.

Name Type Description
animation boolean

Animation.

bearing number

Map bearing

duration number

Duration if animation is enabled. Default 2000.

maxZoom number

Maximum zoom level when fitting the bounds.

padding number | module:cercaliagl/Bounds~BoundsPadding

Padding in pixels from the bounds to the map canvas.

pitch number

Map pitch.

Methods

Move the limits horizontally and vertically

Name Type Description
x number

Displacement X axis

y number

Displacement Y axis

Returns:
Bounds after add

clear()

Cleans the object bounds. It reinitializes.

Clone object

Returns:
Object cloned

cloneIncreasingPercentage(percentage){module:cercaliagl/Bounds~Bounds}

Name Type Description
percentage number

to increase for every limit (top, bottom, left, right)

Returns:
Returns the object 'Bounds' increased

contains(x, y, inclusive){boolean}

Returns if it's inside the object bounds del objeto

Name Type Description
x number | undefined

Latitude.

y number | undefined

Longitude.

inclusive boolean (defaults to true)

Inclusive, with the bounds.

Returns:
Returns if it's inside the object bounds.

containsBounds(bounds, partial, inclusive){boolean}

Name Type Description
bounds module:cercaliagl/Bounds~Bounds

Bounds.

partial boolean (defaults to false)

If one destination corner is inside the bounds consider contains the bounds. The default value is false. If false, all the destination bounds must be inside this bounds.

inclusive boolean (defaults to true)

Include edges. Default value: true

Returns:
Returns if contains bounds inside object

containsLonLat(lonLat){boolean}

Returns true if a coordinate (LonLat object) is inside the bounds

Name Type Description
lonLat module:cercaliagl/LonLat~LonLat

Coordinate.

Returns:
true or false.

equals(bounds){boolean}

Name Type Description
bounds module:cercaliagl/Bounds~Bounds

Bounds to compare

Returns:
Returns if bounds have the same limits

extend(boundsOrLonLat)

Expand the limits for including coordinates {ol.Coordinate} or more limits {Bounds}.

Name Type Description
boundsOrLonLat module:cercaliagl/LonLat~LonLat | module:cercaliagl/Bounds~Bounds | null

Bounds or LonLat to extend current bounds

extendXY(x, y)

Expand the limits for including the coordinate XY. Format [x, y]

Name Type Description
x number

Longitud

y number

Latitud

getBottom(){number|undefined}

Returns the lower limit for Y axis.

Returns:
bottom

Returns the Bounds Options

Returns:
Bounds Options

getCenterLonLat(){module:cercaliagl/LonLat~LonLat|undefined}

Returns the bounds center

Returns:
Map center

Returns an object increasing (* 0.5) all the limits (top, bottom, left, right).

Returns:
bounds doubled by 0.5 for each limit.

getHeight(){number}

Height limits.

Returns:
Height bounds

getHeightInMeters(){number|undefined}

Get height width distance in meters.

Returns:
Bounds height distance in meters.

getLeft(){number|undefined}

Returns the left limit for X axis.

Returns:
left

Returns the North East coordinate

Returns:
array NorthEast coordinate

Returns the North West coordinate

Returns:
Northwest coordinate

getRight(){number|undefined}

Returns the right limit for X axis.

Returns:
right

getSize(){Array.<number>}

Array with size limits [width,height]

Returns:
Size bounds [width, height]

Returns the South East coordinate

Returns:
SouthEast coordinate

Returns the South West coordinate

Returns:
Southwest coordinate

getTop(){number|undefined}

Returns the top limit for Y axis.

Returns:
top

getWidth(){number}

Width limits

Returns:
Bounds width

getWidthInMeters(){number|undefined}

Get bounds width distance in meters.

Returns:
Bounds width distance in meters.

intersectsBounds(bounds, options){boolean}

Determina si unos limites intersecta con los limites del objeto actual. Se considera que intersectan si uno de sus aristas se encuentran dentro de los limites del otro

Name Type Description
bounds module:cercaliagl/Bounds~Bounds

Bounds

options Object

Options

Returns:
true if bounds intersects.

isEmpty(){boolean}

Check if bounds are emty or have been initialized yet.

Returns:
true if empty, else false.

setBoundsOptions(boundsOptions)

Sets the Bounds options

Name Type Description
boundsOptions
Name Type Description
animation boolean

Animation.

bearing number

Map bearing

duration number

Duration if animation is enabled. Default 2000.

maxZoom number

Maximum zoom level when fitting the bounds.

padding number | module:cercaliagl/Bounds~BoundsPadding

Padding in pixels from the bounds to the map canvas.

pitch number

Map pitch.

toArray(){Array.<number>}

Returns:
Returns an array with the bounds. Format: [left, bottom, right, top]

toBBOX(){string}

Returns:
Returns BoundingBox-String '0.41,41.24,0.541,40.51'

toDoubleArray(){Array.<Array.<number>>}

Convert bounds to double array. Format: [[left, bottom], [right, top]]

toString(){string}

Returns the object in string [left, bottom, right, top]

Returns:
Returns a string with the bounds. Format: 'left,bottom,right,top'

toWKT(){string}

Returns:
Returns BoundingBox in WKT format

wrapDateLine(maxExtent, options){module:cercaliagl/Bounds~Bounds}

Name Type Description
maxExtent module:cercaliagl/Bounds~Bounds

Max extent

options

Optional value. options.leftTolerance|options.rightTolerance

Name Type Description
leftTolerance number | undefined
rightTolerance number | undefined
Returns:
Bounds