Geography and geometry

General utilities and types that relate to working with and manipulating geographic information or geometries.

LngLat

src/geo/lng_lat.js

A LngLat object represents a given longitude and latitude coordinate, measured in degrees. These coordinates are based on the WGS84 (EPSG:4326) standard.

Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match the GeoJSON specification.

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 LngLat(lng: number, lat: number)

Parameters

lng(number)Longitude, measured in degrees.
lat(number)Latitude, measured in degrees.

Example

var ll = new mapboxgl.LngLat(-123.9749, 40.7736);
ll.lng; // = -123.9749

Static Members

Instance Members

Was this section on LngLat helpful?

LngLatLike

src/geo/lng_lat.js

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

Example

var v1 = new mapboxgl.LngLat(-122.420679, 37.772537);
var v2 = [-122.420679, 37.772537];
var v3 = {lon: -122.420679, lat: 37.772537};
Was this section on LngLatLike helpful?

LngLatBounds

src/geo/lng_lat_bounds.js

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 an Array of two LngLatLike constructs and will perform an implicit conversion. This flexible type is documented as LngLatBoundsLike.

new LngLatBounds(sw: LngLatLike?, ne: LngLatLike?)

Parameters

sw(LngLatLike?)The southwest corner of the bounding box.
ne(LngLatLike?)The northeast corner of the bounding box.

Example

var sw = new mapboxgl.LngLat(-73.9876, 40.7661);
var ne = new mapboxgl.LngLat(-73.9397, 40.8002);
var llb = new mapboxgl.LngLatBounds(sw, ne);

Static Members

Instance Members

Was this section on LngLatBounds helpful?

LngLatBoundsLike

src/geo/lng_lat_bounds.js

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

Example

var v1 = new mapboxgl.LngLatBounds(
new mapboxgl.LngLat(-73.9876, 40.7661),
new mapboxgl.LngLat(-73.9397, 40.8002)
);
var v2 = new mapboxgl.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002])
var v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
Was this section on LngLatBoundsLike helpful?

Point

src/ui/map.js

A Point geometry object, which has x and y properties representing screen coordinates in pixels.

Example

var point = new mapboxgl.Point(-77, 38);
Was this section on Point helpful?

PointLike

src/ui/map.js

A Point or an array of two numbers representing x and y screen coordinates in pixels.

Example

var p1 = new mapboxgl.Point(-77, 38); // a PointLike which is a Point
var p2 = [-77, 38]; // a PointLike which is an array of two numbers
Was this section on PointLike helpful?

MercatorCoordinate

src/geo/mercator_coordinate.js

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

new MercatorCoordinate(x: number, y: number, z: number)

Parameters

x(number)The x component of the position.
y(number)The y component of the position.
z(number)(default 0)The z component of the position.

Example

var nullIsland = new mapboxgl.MercatorCoordinate(0.5, 0.5, 0);

Static Members

Instance Members

Was this section on MercatorCoordinate helpful?

EdgeInsets

src/geo/edge_insets.js

An EdgeInset object represents screen space padding applied to the edges of the viewport. This shifts the apprent center or the vanishing point of the map. This is useful for adding floating UI elements on top of the map and having the vanishing point shift as UI elements resize.

new EdgeInsets(top: number, bottom: number, left: number, right: number)

Parameters

top(number)(default 0)
bottom(number)(default 0)
left(number)(default 0)
right(number)(default 0)

Static Members

Was this section on EdgeInsets helpful?