This page includes reference documentation for geography and geometry utilities in the Mapbox Search JS Core framework.
A LngLat object represents a given longitude and latitude coordinate, measured in degrees.
These coordinates use longitude, latitude coordinate order (as opposed to latitude, longitude)
to match the GeoJSON specification,
which is equivalent to the OGC:CRS84 coordinate reference system.
Note that any method that accepts a LngLat object as an argument or option
can also accept an Array of two numbers and will perform an implicit conversion.
This flexible type is documented as LngLatLike.
new LngLat(lng: any, lat: any)
| Name | Description |
|---|---|
| lng any | Longitude, measured in degrees. |
| lat any | Latitude, measured in degrees. |
const ll = new LngLat(-123.9749, 40.7736);
console.log(ll.lng); // = -123.9749Converts an array of two numbers or an object with lng and lat or lon and lat properties
to a LngLat object.
If a LngLat object is passed in, the function returns a copy.
| Name | Description |
|---|---|
| input (LngLat | {lng: number, lat: number} | {lon: number, lat: number} | [number, number]) | An array of two numbers or object to convert, or a
LngLat
object to return.
|
LngLat
object, if a conversion occurred, or the original
LngLat
object.
const arr = [-73.9749, 40.7736];
const ll = LngLat.convert(arr);
console.log(ll); // = LngLat {lng: -73.9749, lat: 40.7736}Returns the coordinates represent as a string.
'LngLat(lng, lat)'
.
const ll = new LngLat(-73.9749, 40.7736);
ll.toString(); // = "LngLat(-73.9749, 40.7736)"A LngLat object, an array of two numbers representing longitude and latitude,
or an object with lng and lat or lon and lat properties.
const v1 = new LngLat(-122.420679, 37.772537);
const v2 = [-122.420679, 37.772537];
const v3 = {lon: -122.420679, lat: 37.772537};A LngLatBounds object represents a geographical bounding box,
defined by its southwest and northeast points in longitude and latitude.
Note that any method that accepts a LngLatBounds object as an argument or option
can also accept an Array of two LngLatLike constructs and will perform an implicit conversion.
This flexible type is documented as LngLatBoundsLike.
new LngLatBounds()
Converts an array to a LngLatBounds object.
If a LngLatBounds object is passed in, the function returns a copy.
Internally, the function calls LngLat#convert to convert arrays to LngLat values.
| Name | Description |
|---|---|
| input (LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number]) | An array of two coordinates to convert, or a
LngLatBounds
object to return.
|
LngLatBounds
object, if a conversion occurred, or the original
LngLatBounds
object.
const arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
const llb = LngLatBounds.convert(arr);
console.log(llb); // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}Returns the southwest corner of the bounding box.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getSouthWest(); // LngLat {lng: -73.9876, lat: 40.7661}Returns the northeast corner of the bounding box.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getNorthEast(); // LngLat {lng: -73.9397, lat: 40.8002}Returns the northwest corner of the bounding box. This is commonly used as the 'min' point in the bounding box.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getNorthWest(); // LngLat {lng: -73.9876, lat: 40.8002}Returns the southeast corner of the bounding box. This is commonly used as the 'max' point in the bounding box.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getSouthEast(); // LngLat {lng: -73.9397, lat: 40.7661}Returns the west edge of the bounding box.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getWest(); // -73.9876Returns the south edge of the bounding box.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getSouth(); // 40.7661Returns the east edge of the bounding box.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getEast(); // -73.9397Returns the north edge of the bounding box.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getNorth(); // 40.8002Returns the bounding box represented as an array.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]Returns the bounding box represented as a flattened array.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toFlatArray(); // = [-73.9876, 40.7661, -73.9397, 40.8002]Return the bounding box represented as a string.
'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'
.
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"A LngLatBounds object, an array of LngLatLike objects in [sw, ne] order, or an array of numbers in [west, south, east, north] order.
const v1 = new LngLatBounds(
new LngLat(-73.9876, 40.7661),
new LngLat(-73.9397, 40.8002)
);
const v2 = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
const v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];Utility function to convert the SearchBoxFeatureSuggestion properties to a SearchBoxFeatureProperties object.
| Name | Description |
|---|---|
| feature (SearchBoxFeatureSuggestion | AddressAutofillFeatureSuggestion) |
"original_search_text" | "action")>)