Class: BoundingBox

BoundingBox(bounds)

new BoundingBox(bounds)

create bounding box from input
Parameters:
Name Type Description
bounds object | Leaflet.latLngBounds | GeoJSON Input boundary. Can be an object with { minlat, minlon, maxlat, maxlon } or { lat, lon } or { lat, lng } or [ N (lat), N (lon) ] a GeoJSON object or a Leaflet object (latLng or latLngBounds). The boundary will automatically be wrapped at longitude -180 / 180.
Source:
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })

Members

toBBoxString

return the bounding box as lon-lat string, e.g. '179.5,55,-179.5,56'. Useful for sending requests to web services that return geo data.
Source:
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
console.log(bbox.toBBoxString()) // '16.23,48.123,16.367,49.012'

Methods

diagonalDistance(optionsopt) → {number}

return the diagonal distance (using the haversine function). See https://github.com/njj/haversine for further details.
Parameters:
Name Type Attributes Description
options object <optional>
Options
Properties
Name Type Attributes Default Description
unit string <optional>
km Unit of measurement applied to result ('km', 'mile', 'meter', 'nmi')
threshold number <optional>
If passed, will result in library returning boolean value of whether or not the start and end points are within that supplied threshold.
Source:
Returns:
Type
number
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
console.log(bbox.diagonalDistance({ unit: 'm' })) // 99.36491328576697

diagonalLength() → {number}

return the diagonal length (length of hypothenuse).
Source:
Returns:
Type
number
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
console.log(bbox.diagonalLength()) // 0.8994943023721748

extend(other)

extends current boundary by the other boundary
Parameters:
Name Type Description
other BoundingBox
Source:
Example
var bbox1 = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
var bbox2 = new BoundingBox({ minlat: 48.000, minlon: 16.23, maxlat: 49.012, maxlon: 16.789 })
bbox1.extend(bbox2)
console.log(bbox1.bounds) // { minlat: 48, minlon: 16.23, maxlat: 49.012, maxlon: 16.789 }

getCenter() → {object}

Returns the center point of the bounding box as { lat, lon }
Source:
Returns:
Type
object
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
console.log(bbox.getCenter()) // { lat: 48.567499999999995, lon: 16.2985 }

getEast()

get Eastern boundary (longitude)
Parameters:
Type Description
number
Source:

getNorth()

get Northern boundary (latitude)
Parameters:
Type Description
number
Source:

getSouth()

get Southern boundary (latitude)
Parameters:
Type Description
number
Source:

getWest()

get Western boundary (longitude)
Parameters:
Type Description
number
Source:

intersects(other) → {boolean}

Checks whether the other bounding box intersects (shares any portion of space) the current object.
Parameters:
Name Type Description
other BoundingBox Other boundingbox to check for
Source:
Returns:
true if the bounding boxes intersect
Type
boolean
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
var bbox2 = new BoundingBox({ lat: 48.5, lon: 16.267 })
console.log(bbox.intersects(bbox2)) // true

toGeoJSON() → {object}

Returns the bounding box as GeoJSON feature. In case of bounding boxes crossing the antimeridian, this function will return a multipolygon with the parts on each side of the antimeridian (as specified in RFC 7946, section 3.1.9).
Source:
Returns:
Type
object
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
bbox.toGeoJSON()
// {
//   "type": "Feature",
//   "properties": {},
//   "geometry": {
//     "type": "Polygon",
//     "coordinates": [
//       [
//         [ 16.23, 48.123 ],
//         [ 16.367, 48.123 ],
//         [ 16.367, 49.012 ],
//         [ 16.23, 49.012 ],
//         [ 16.23, 48.123 ]
//       ]
//     ]
//   }
// }

toLatLonString() → {string}

return the bounding box as lon-lat string, e.g. '55,179.5,56,-179.5'. Useful e.g. for Overpass API requests.
Source:
Returns:
Type
string
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
console.log(bbox.toLatLonString()) // '48.123,16.23,49.012,16.367'

toLeaflet(optionsopt)

Returns the bounding box as L.latLngBounds object. Leaflet must be included separately!
Parameters:
Name Type Attributes Description
options object <optional>
Options.
Properties
Name Type Attributes Default Description
shiftWorld Array.<number> <optional>
[0, 0] Shift the world by the first value for the Western hemisphere (lon < 0) or the second value for the Eastern hemisphere (lon >= 0).
Source:

toLonLatString() → {string}

return the bounding box as lon-lat string, e.g. '179.5,55,-179.5,56'
Source:
Returns:
Type
string
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
console.log(bbox.toLonLatString()) // '16.23,48.123,16.367,49.012'

within(other) → {boolean}

Checks whether the current object is fully within the other bounding box.
Parameters:
Name Type Description
other BoundingBox Other boundingbox to check for
Source:
Returns:
true if the bounding boxes is within other
Type
boolean
Example
var bbox = new BoundingBox({ minlat: 48.123, minlon: 16.23, maxlat: 49.012, maxlon: 16.367 })
var bbox2 = new BoundingBox({ lat: 48.5, lon: 16.267 })
console.log(bbox2.within(bbox)) // true