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](https://datatracker.ietf.org/doc/html/rfc7946#section-4), which is equivalent to the OGC:CRS84 coordinate reference system. Note that any Mapbox GL 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 SuperMap3D.LngLat(lng, lat)

Name Type Description
lng number Longitude, measured in degrees.
lat number Latitude, measured in degrees.
Example:
const ll = new mapboxgl.LngLat(-123.9749, 40.7736);
console.log(ll.lng); // = -123.9749
See:
  • [Example: Get coordinates of the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/mouse-position/)
  • [Example: Display a popup](https://www.mapbox.com/mapbox-gl-js/example/popup/)
  • [Example: Highlight features within a bounding box](https://www.mapbox.com/mapbox-gl-js/example/using-box-queryrenderedfeatures/)
  • [Example: Create a timeline animation](https://www.mapbox.com/mapbox-gl-js/example/timeline-animation/)

Methods

staticSuperMap3D.LngLat.convert(input)LngLat

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 it unchanged.
Name Type Description
input LngLatLike An array of two numbers or object to convert, or a `LngLat` object to return.
Returns:
A new `LngLat` object, if a conversion occurred, or the original `LngLat` object.
Example:
const arr = [-73.9749, 40.7736];
const ll = mapboxgl.LngLat.convert(arr);
console.log(ll);   // = LngLat {lng: -73.9749, lat: 40.7736}

distanceTo(lngLat)number

Returns the approximate distance between a pair of coordinates in meters. Uses the Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159).
Name Type Description
lngLat LngLat Coordinates to compute the distance to.
Returns:
Distance in meters between the two coordinates.
Example:
const newYork = new mapboxgl.LngLat(-74.0060, 40.7128);
const losAngeles = new mapboxgl.LngLat(-118.2437, 34.0522);
newYork.distanceTo(losAngeles); // = 3935751.690893987, "true distance" using a non-spherical approximation is ~3966km

toArray()Array.<number>

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

toBounds(radius)LngLatBounds

Returns a `LngLatBounds` from the coordinates extended by a given `radius`. The returned `LngLatBounds` completely contains the `radius`.
Name Type Default Description
radius number 0 optional Distance in meters from the coordinates to extend the bounds.
Returns:
A new `LngLatBounds` object representing the coordinates extended by the `radius`.
Example:
const ll = new mapboxgl.LngLat(-73.9749, 40.7736);
ll.toBounds(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]

toString()string

Returns the coordinates represent as a string.
Returns:
The coordinates represented as a string of the format `'LngLat(lng, lat)'`.
Example:
const ll = new mapboxgl.LngLat(-73.9749, 40.7736);
ll.toString(); // = "LngLat(-73.9749, 40.7736)"

wrap()LngLat

Returns a new `LngLat` object whose longitude is wrapped to the range (-180, 180).
Returns:
The wrapped `LngLat` object.
Example:
const ll = new mapboxgl.LngLat(286.0251, 40.7736);
const wrapped = ll.wrap();
console.log(wrapped.lng); // = -73.9749