Geography and geometry

This page includes reference documentation for geography and geometry utilities in the Mapbox Search JS Core framework.

LngLat

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)

Parameters

NameDescription
lng any Longitude, measured in degrees.
lat any Latitude, measured in degrees.

Example

const ll = new LngLat(-123.9749, 40.7736);
console.log(ll.lng); // = -123.9749

Static Members

Converts 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.

Parameters
NameDescription
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.
Returns
LngLat: A new LngLat object, if a conversion occurred, or the original LngLat object.
Example
const arr = [-73.9749, 40.7736];
const ll = LngLat.convert(arr);
console.log(ll);   // = LngLat {lng: -73.9749, lat: 40.7736}

Instance Members

Returns the coordinates represented as an array of two numbers.

Returns
[number, number]: The coordinates represeted as an array of longitude and latitude.
Example
const ll = new LngLat(-73.9749, 40.7736);
ll.toArray(); // = [-73.9749, 40.7736]

Returns the coordinates represent as a string.

Returns
string: The coordinates represented as a string of the format 'LngLat(lng, lat)' .
Example
const ll = new LngLat(-73.9749, 40.7736);
ll.toString(); // = "LngLat(-73.9749, 40.7736)"
このsection on LngLatは役に立ちましたか?YesNo

LngLatLike

A LngLat object, an array of two numbers representing longitude and latitude, or an object with lng and lat or lon and lat properties.

Type

(LngLat | [number, number] | {lng: number, lat: number} | {lon: number, lat: number})

Example

const v1 = new LngLat(-122.420679, 37.772537);
const v2 = [-122.420679, 37.772537];
const v3 = {lon: -122.420679, lat: 37.772537};
このsection on LngLatLikeは役に立ちましたか?YesNo

LngLatBounds

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()

Static Members

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.

Parameters
NameDescription
input (LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number]) An array of two coordinates to convert, or a LngLatBounds object to return.
Returns
LngLatBounds: A new LngLatBounds object, if a conversion occurred, or the original LngLatBounds object.
Example
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}}

Instance Members

Returns the southwest corner of the bounding box.

Returns
LngLat: The southwest corner of the bounding box.
Example
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.

Returns
LngLat: The northeast corner of the bounding box.
Example
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.

Returns
LngLat: The northwest corner of the bounding box.
Example
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.

Returns
LngLat: The southeast corner of the bounding box.
Example
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.

Returns
number: The west edge of the bounding box.
Example
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getWest(); // -73.9876

Returns the south edge of the bounding box.

Returns
number: The south edge of the bounding box.
Example
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getSouth(); // 40.7661

Returns the east edge of the bounding box.

Returns
number: The east edge of the bounding box.
Example
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getEast(); // -73.9397

Returns the north edge of the bounding box.

Returns
number: The north edge of the bounding box.
Example
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getNorth(); // 40.8002

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.
Example
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.

Returns
[number, number, number, number]: The bounding box represented as an array of numbers in [west, south, east, north] order.
Example
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.

Returns
string: The bounding box represents as a string of the format 'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))' .
Example
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))"
このsection on LngLatBoundsは役に立ちましたか?YesNo

LngLatBoundsLike

A LngLatBounds object, an array of LngLatLike objects in [sw, ne] order, or an array of numbers in [west, south, east, north] order.

Type

(LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number])

Example

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]];
このsection on LngLatBoundsLikeは役に立ちましたか?YesNo

featureToSuggestion

Utility function to convert the SearchBoxFeatureSuggestion properties to a SearchBoxFeatureProperties object.

Parameters

NameDescription
feature (SearchBoxFeatureSuggestion | AddressAutofillFeatureSuggestion) 

Returns

(SearchBoxFeatureProperties | Omit<AddressAutofillSuggestion, ("original_search_text" | "action")>)
このsection on featureToSuggestionは役に立ちましたか?YesNo