Geography and geometry
General utilities and types that relate to working with and manipulating geographic information or geometries.
LngLat
src/geo/lng_lat.tsA 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 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.
Parameters
| Name | Description |
|---|---|
| Longitude, measured in degrees. | |
| Latitude, measured in degrees. |
Example
const ll = new mapboxgl.LngLat(-123.9749, 40.7736);
console.log(ll.lng); // = -123.9749
Static Members
Instance Members
Related
LngLatBounds
src/geo/lng_lat.tsA LngLatBounds object represents a geographical bounding box,
defined by its southwest and northeast points in longitude and latitude.
Longitude values are typically set between -180 to 180, but can exceed this range if renderWorldCopies is set to true. Latitude values must be within -85.051129 to 85.051129.
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 an Array of two LngLatLike constructs and will perform an implicit conversion.
This flexible type is documented as LngLatBoundsLike.
Parameters
| Name | Description |
|---|---|
| The southwest corner of the bounding box. | |
| The northeast corner of the bounding box. |
Example
const sw = new mapboxgl.LngLat(-73.9876, 40.7661);
const ne = new mapboxgl.LngLat(-73.9397, 40.8002);
const llb = new mapboxgl.LngLatBounds(sw, ne);
Static Members
Instance Members
LngLatBoundsLike
src/geo/lng_lat.tsA LngLatBounds object, an array of LngLatLike objects in [sw, ne] order, or an array of numbers in [west, south, east, north] order.
(LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number])Example
const v1 = new mapboxgl.LngLatBounds(
new mapboxgl.LngLat(-73.9876, 40.7661),
new mapboxgl.LngLat(-73.9397, 40.8002)
);
const v2 = new mapboxgl.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
const v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
LngLatLike
src/geo/lng_lat.tsA LngLat object, an array of two numbers representing longitude and latitude,
or an object with lng and lat or lon and lat properties.
(LngLat | {lng: number, lat: number} | {lon: number, lat: number} | [number, number])Example
const v1 = new mapboxgl.LngLat(-122.420679, 37.772537);
const v2 = [-122.420679, 37.772537];
const v3 = {lon: -122.420679, lat: 37.772537};
MercatorCoordinate
src/geo/mercator_coordinate.tsA MercatorCoordinate object represents a projected three dimensional position.
MercatorCoordinate uses the web mercator projection (EPSG:3857) with slightly different units:
- the size of 1 unit is the width of the projected world instead of the "mercator meter"
- the origin of the coordinate space is at the north-west corner instead of the middle.
For example, MercatorCoordinate(0, 0, 0) is the north-west corner of the mercator world and
MercatorCoordinate(1, 1, 0) is the south-east corner. If you are familiar with
vector tiles it may be helpful to think
of the coordinate space as the 0/0/0 tile with an extent of 1.
The z dimension of MercatorCoordinate is conformal. A cube in the mercator coordinate space would be rendered as a cube.
Parameters
| Name | Description |
|---|---|
| The x component of the position. | |
| The y component of the position. | |
| The z component of the position. |
Example
const nullIsland = new mapboxgl.MercatorCoordinate(0.5, 0.5, 0);
Static Members
Instance Members
Related
Point
src/ui/map.tsA Point geometry object, which has
x and y screen coordinates in pixels, or other units.
PointExample
const point = new mapboxgl.Point(400, 525);
PointLike
src/ui/map.tsA Point or an array of two numbers representing x and y screen coordinates in pixels, or other units.
(Point | Array<number>)Example
const p1 = new mapboxgl.Point(400, 525); // a PointLike which is a Point
const p2 = [400, 525]; // a PointLike which is an array of two numbers