Optional
sw: [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]
Optional
ne: LngLatLikeThe northeast corner of the bounding box.
let sw = new LngLat(-73.9876, 40.7661);
let ne = new LngLat(-73.9397, 40.8002);
let llb = new LngLatBounds(sw, ne);
OR
let llb = new LngLatBounds([-73.9876, 40.7661, -73.9397, 40.8002]);
OR
let llb = new LngLatBounds([sw, ne]);
Check if the point is within the bounding box.
geographic point to check against.
true
if the point is within the bounding box.
let llb = new LngLatBounds(
new LngLat(-73.9876, 40.7661),
new LngLat(-73.9397, 40.8002)
);
let ll = new LngLat(-73.9567, 40.7789);
console.log(llb.contains(ll)); // = true
Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
object to extend to
Set the northeast corner of the bounding box
a LngLatLike object describing the northeast corner of the bounding box.
Set the southwest corner of the bounding box
a LngLatLike object describing the southwest corner of the bounding box.
Returns the bounding box represented as an array.
The bounding box represented as an array, consisting of the southwest and northeast coordinates of the bounding represented as arrays of numbers.
let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
Return the bounding box represented as a string.
The bounding box represents as a string of the format
'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'
.
let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
Static
convertConverts an array to a LngLatBounds
object.
If a LngLatBounds
object is passed in, the function returns it unchanged.
Internally, the function calls LngLat#convert
to convert arrays to LngLat
values.
An array of two coordinates to convert, or a LngLatBounds
object to return.
A new LngLatBounds
object, if a conversion occurred, or the original LngLatBounds
object.
let arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
let llb = LngLatBounds.convert(arr); // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
Static
fromReturns a LngLatBounds
from the coordinates extended by a given radius
. The returned LngLatBounds
completely contains the radius
.
center coordinates of the new bounds.
Distance in meters from the coordinates to extend the bounds.
A new LngLatBounds
object representing the coordinates extended by the radius
.
let center = new LngLat(-73.9749, 40.7736);
LngLatBounds.fromLngLat(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
A
LngLatBounds
object 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
null
bounding box is created.Note that any Mapbox GL method that accepts a
LngLatBounds
object as an argument or option can also accept anArray
of two LngLatLike constructs and will perform an implicit conversion. This flexible type is documented as LngLatBoundsLike.Example