For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Class LngLatBounds
Constructors
constructor
-
new LngLatBounds(
sw?:
| [number, number, number, number]
| LngLatLike
| [LngLatLike, LngLatLike],
ne?: LngLatLike,
): LngLatBoundsParameters
Optionalsw: [number, number, number, number] | LngLatLike | [LngLatLike, LngLatLike]The southwest corner of the bounding box. OR array of 4 numbers in the order of west, south, east, north OR array of 2 LngLatLike: [sw,ne]
Optionalne: LngLatLikeThe northeast corner of the bounding box.
Returns LngLatBounds
Methods
adjustAntiMeridian
-
Adjusts the given bounds to handle the case where the bounds cross the 180th meridian (antimeridian).
Returns LngLatBounds
The adjusted LngLatBounds
contains
-
Check if the point is within the bounding box.
Parameters
- lnglat: LngLatLike
geographic point to check against.
Returns boolean
trueif the point is within the bounding box. - lnglat: LngLatLike
extend
-
Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
Parameters
- obj: LngLatLike | LngLatBoundsLike
object to extend to
Returns this
- obj: LngLatLike | LngLatBoundsLike
getCenter
-
Returns the geographical coordinate equidistant from the bounding box's corners.
Returns LngLat
The bounding box's center.
getEast
-
Returns the east edge of the bounding box.
Returns number
The east edge of the bounding box.
getNorth
-
Returns the north edge of the bounding box.
Returns number
The north edge of the bounding box.
getNorthEast
-
Returns the northeast corner of the bounding box.
Returns LngLat
The northeast corner of the bounding box.
getNorthWest
-
Returns the northwest corner of the bounding box.
Returns LngLat
The northwest corner of the bounding box.
getSouth
-
Returns the south edge of the bounding box.
Returns number
The south edge of the bounding box.
getSouthEast
-
Returns the southeast corner of the bounding box.
Returns LngLat
The southeast corner of the bounding box.
getSouthWest
-
Returns the southwest corner of the bounding box.
Returns LngLat
The southwest corner of the bounding box.
getWest
-
Returns the west edge of the bounding box.
Returns number
The west edge of the bounding box.
intersects
-
Checks if this bounding box intersects with another bounding box.
Returns true if the bounding boxes share any area, including cases where they only touch along an edge or at a corner.
This method properly handles cases where either or both bounding boxes cross the antimeridian (date line).
Parameters
- other: LngLatBoundsLike
Returns boolean
isEmpty
-
Check if the bounding box is an empty/
null-type box.Returns boolean
True if bounds have been defined, otherwise false.
setNorthEast
-
Set the northeast corner of the bounding box
Parameters
- ne: LngLatLike
a LngLatLike object describing the northeast corner of the bounding box.
Returns this
- ne: LngLatLike
setSouthWest
-
Set the southwest corner of the bounding box
Parameters
- sw: LngLatLike
a LngLatLike object describing the southwest corner of the bounding box.
Returns this
- sw: LngLatLike
toArray
-
Returns the bounding box represented as an array.
Returns [[number, number], [number, number]]
The bounding box represented as an array, consisting of the southwest and northeast coordinates of the bounding represented as arrays of numbers.
toString
-
Return the bounding box represented as a string.
Returns string
The bounding box represents as a string of the format
'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'.
Staticconvert
-
Converts an array to a
LngLatBoundsobject.If a
LngLatBoundsobject is passed in, the function returns it unchanged.Internally, the function calls LngLat.convert to convert arrays to
LngLatvalues.Parameters
- input: LngLatBoundsLike | null
An array of two coordinates to convert, or a
LngLatBoundsobject to return.
Returns LngLatBounds
A new
LngLatBoundsobject, if a conversion occurred, or the originalLngLatBoundsobject. - input: LngLatBoundsLike | null
StaticfromLngLat
-
Returns a
LngLatBoundsfrom the coordinates extended by a givenradius. The returnedLngLatBoundscompletely contains theradius.Parameters
- center: LngLat
center coordinates of the new bounds.
Optionalradius: numberDistance in meters from the coordinates to extend the bounds.
Returns LngLatBounds
A new
LngLatBoundsobject representing the coordinates extended by theradius. - center: LngLat
A
LngLatBoundsobject represents a geographical bounding box, defined by its southwest and northeast points in longitude and latitude.If no arguments are provided to the constructor, a
nullbounding box is created.Note that any MapLibre GL method that accepts a
LngLatBoundsobject as an argument or option can also accept anArrayof two LngLatLike constructs and will perform an implicit conversion. This flexible type is documented as LngLatBoundsLike.Example
See
Fit to the bounds of a LineString