Map(options, options.container)

Creates a map instance.

parameter type description
options Object
options.container String

HTML element to initialize the map in (or element id as string)

zoomTo(zoom, animOptions)

Zooms to a certain zoom level with easing.

parameter type description
zoom Number
animOptions

Returns

this

zoomOut(animOptions)

Zoom out by 1 level

parameter type description
animOptions

Returns

this

zoomIn(animOptions)

Zoom in by 1 level

parameter type description
animOptions

Returns

this

update(updateStyle)

Update this map's style and re-render the map.

parameter type description
updateStyle Object

new style

Returns

Map :

this

stop

Stop current animation

Returns

this

setView(center, zoom, bearing, pitch)

Sets a map position

parameter type description
center Array

Latitude and longitude (passed as [lat, lng])

zoom number

Map zoom level

bearing number

Map rotation bearing in degrees counter-clockwise from north

pitch number

The angle at which the camera is looking at the ground

Returns

Map :

this

setZoom(zoom)

Sets a map zoom

parameter type description
zoom number

Map zoom level

Returns

Map :

this

unproject(point)

Get geographical coordinates given pixel coordinates

parameter type description
point Array<number>

[x, y] pixel coordinates

Returns

LatLng

setLayoutProperty(layer, name, value)

Set the value of a layout property in a given style layer.

parameter type description
layer string

ID of a layer

name string

name of a layout property

value Any

value for the layout propery; must have the type appropriate for the property as defined in the Style Specification

Returns

Map :

this

setBearing(bearing)

Sets a map rotation

parameter type description
bearing number

Map rotation bearing in degrees counter-clockwise from north

Returns

Map :

this

setPaintProperty(layer, name, value, [klass])

Set the value of a paint property in a given style layer.

parameter type description
layer string

ID of a layer

name string

name of a paint property

value Any

value for the paint propery; must have the type appropriate for the property as defined in the Style Specification

klass [string]

optional class specifier for the property

Returns

Map :

this

setCenter(center)

Sets a map location

parameter type description
center Array

Latitude and longitude (passed as [lat, lng])

Returns

Map :

this

setFilter(layer, filter)

Set the filter for a given style layer.

parameter type description
layer string

ID of a layer

filter Array

filter specification, as defined in the Style Specification

Returns

Map :

this

setClasses(klasses, options)

Helper method to add more than one class

parameter type description
klasses Array<string>

An array of class names

options styleOptions

Returns

Map :

this

rotateTo(bearing, animOptions)

Rotate bearing by a certain number of degrees with easing

parameter type description
bearing Number
animOptions

Returns

this

setStyle(style)

Replaces the map's style object

parameter type description
style Object

A style object formatted as JSON

Returns

Map :

this

removeSource(id)

Remove an existing source from the map style.

parameter type description
id string

ID of the source to remove

Returns

Map :

this

getSource(id)

Return the style source object with the given id.

parameter type description
id string

source ID

Returns

Object

project(latlng)

Get pixel coordinates (relative to map container) given a geographical location

parameter type description
latlng LatLng

Returns

Object :

x and y coordinates

hasClass(klass)

Check whether a style class is active

parameter type description
klass string

Name of style class

Returns

boolean

removeLayer(id)

Remove the layer with the given id from the map. Any layers which refer to the specified layer via a ref property are also removed.

parameter type description
id string

Returns

Map :

this

removeClass(klass, options)

Removes a style class from a map

parameter type description
klass string

name of style class

options styleOptions

Returns

Map :

this

getPitch

Get the current angle in degrees

Returns

number

getPaintProperty(layer, name, [klass])

Get the value of a paint property in a given style layer.

parameter type description
layer string

ID of a layer

name string

name of a paint property

klass [string]

optional class specifier for the property

Returns

Any :

value for the paint propery

getZoom

Get the current zoom

Returns

number

panBy(offset, animOptions)

Pan by a certain number of pixels

parameter type description
offset Array

[x, y]

animOptions

Returns

this

loaded

Is this map fully loaded? If the style isn't loaded or it has a change to the sources or style that isn't propagated to its style, return false.

Returns

boolean :

whether the map is loaded

render

Call when a (re-)render of the map is required, e.g. when the user panned or zoomed,f or new data is available.

Returns

Map :

this

remove

Destroys the map's underlying resources, including web workers.

Returns

Map :

this

panTo(latlng, animOptions)

Pan to a certain location with easing

parameter type description
latlng Object

a LatLng object

animOptions

Returns

this

resetNorth(animOptions)

Sets map bearing to 0 (north) with easing

parameter type description
animOptions

Returns

this

resize

Detect the map's new width and height and resize it.

Returns

Map :

this

fitBounds(bounds, options)

Zoom to contain certain geographical bounds

parameter type description
bounds Array

[[minLat, minLng], [maxLat, maxLng]]

options Object

easeTo(latlng, zoom, bearing, pitch, animOptions)

Easing animation to a specified location/zoom/bearing

parameter type description
latlng Object

a LatLng object

zoom Number
bearing Number
pitch Number
animOptions

Returns

this

flyTo(latlng, zoom, bearing, options)

Flying animation to a specified location/zoom/bearing with automatic curve

parameter type description
latlng Object

a LatLng object

zoom Number
bearing Number
options Object

getCenter

Get the current view geographical point

Returns

LatLng

getBearing

Get the current bearing in degrees

Returns

number

getClasses

Return an array of the current active style classes

Returns

boolean

getBounds

Get the map's geographical bounds

Returns

LatLngBounds

featuresAt(point, params)

Get all features at a point ([x, y])

parameter type description
point Array<number>

[x, y] pixel coordinates

params Object

getFilter(layer)

Get the filter for a given style layer.

parameter type description
layer string

ID of a layer

Returns

Array :

filter specification, as defined in the Style Specification

getLayoutProperty(layer, name, [klass])

Get the value of a layout property in a given style layer.

parameter type description
layer string

ID of a layer

name string

name of a layout property

klass [string]

optional class specifier for the property

Returns

Any :

value for the layout propery

getContainer

Get the Map's container as an HTML element

Returns

HTMLElement :

container

getCanvas

Get the Map's canvas as an HTML canvas

Returns

HTMLElement :

canvas

setPitch(pitch)

Sets a map angle

parameter type description
pitch number

The angle at which the camera is looking at the ground

Returns

Map :

this

addClass(klass, options)

Adds a style class to a map

parameter type description
klass string

name of style class

options styleOptions

Returns

Map :

this

addSource(id, source)

Add a source to the map style.

parameter type description
id string

ID of the source. Must not be used by any existing source.

source Object

source specification, following the Mapbox GL Style Reference

Returns

Map :

this

addLayer(layer, [before])

Add a layer to the map style. The layer will be inserted before the layer with ID before, or appended if before is omitted.

parameter type description
layer Layer
before [string]

ID of an existing layer to insert before

Returns

Map :

this

GeoJSONSource

Create a GeoJSON data source instance given an options object

setData(data)

Update source geojson data and rerender map

parameter type description
data Object or String

A GeoJSON data object or URL to it. The latter is preferable in case of large GeoJSON files.

Control

A base class for map-related interface elements.

remove

Remove this control from the map it has been added to.

Returns

Control :

this

addTo(map)

Add this control to the map, returning the control itself for chaining. This will insert the control's DOM element into the map's DOM element if the control has a position specified.

parameter type description
map Map

Returns

Control :

this

Attribution

Creates an attribution control

Examples

map.addControl(new mapboxgl.Attribution());

LatLng(lat, lng)

Create a latitude, longitude object from a given latitude and longitude pair in degrees.

parameter type description
lat number

latitude

lng number

longitude

Examples

var latlng = new mapboxgl.LatLng(37.76, -122.44);

wrap

Return a new LatLng object whose longitude is wrapped to the range (-180, 180).

Returns

LatLng :

wrapped LatLng object

convert(input)

Convert an array to a LatLng object, or return an existing LatLng object unchanged.

parameter type description
input Array<number> or LatLng

input to convert

Returns

LatLng :

LatLng object or original input

Evented

Methods mixed in to other classes for event capabilities.

listens

Check if an event is registered to a type

Returns

Boolean :

Returns true if the object listens to an event of a particular type

once(type, listener)

Call a function once when an event has fired

parameter type description
type String

Event type.

listener Function

Function to be called once when the event is fired

off

Remove a event listener

on(type, listener)

Subscribe to a specified event with a listener function the latter gets the data object that was passed to fire and additionally target and type properties

parameter type description
type String

Event type

listener Function

Function to be called when the event is fired

fire(type)

Fire event of a given string type with the given data object

parameter type description
type String

The event name

LatLngBounds(sw, ne)

Creates a bounding box from the given pair of points. If parameteres are omitted, a null bounding box is created.

parameter type description
sw LatLng

southwest

ne LatLng

northeast

Examples

var sw = new mapboxgl.LatLng(0, 0);
var ne = new mapboxgl.LatLng(10, -10);
var bounds = new mapboxgl.LatLngBounds(sw, ne);

getSouthWest

Get southwest corner

Returns

LatLng :

southwest

getSouth

Get south edge latitude

Returns

number :

south

getNorthEast

Get northeast corner

Returns

LatLng :

northeast

getNorthWest

Get northwest corner

Returns

LatLng :

northwest

getSouthEast

Get southeast corner

Returns

LatLng :

southeast

getWest

Get west edge longitude

Returns

number :

west

extend(obj)

Extend the bounds to include a given LatLng or LatLngBounds.

parameter type description
obj LatLng or LatLngBounds

object to extend to

Returns

LatLngBounds :

this

getCenter

Get the point equidistant from this box's corners

Returns

LatLng :

centerpoint

getEast

Get east edge longitude

Returns

number :

east

getNorth

Get north edge latitude

Returns

number :

north

VideoSource

Create a Video data source instance given an options object

extend

latY(lat)

latitude to absolute y coord

parameter type description
lat Number

supported(options)

Test whether the basic JavaScript and DOM features required for Mapbox GL are present.

parameter type description
options Object

window

mapboxgl is a A WebGL JavaScript interactive maps library that can render Mapbox vector tiles.

lngX(lon)

lat/lon <-> absolute pixel coords conversion

parameter type description
lon Number