Popup(options, options.closeButton, options.closeOnClick)Creates a popup component
| parameter | type | description |
|---|---|---|
| options | Object | |
| options.closeButton | Boolean | |
| options.closeOnClick | Boolean |
var tooltip =new mapboxgl.Popup() .setLatLng(map.unproject(e.point)) .setHTML("<h1>Hello World!</h1>") .addTo(map);
setText(text)Popuplate a popup element with text only content
| parameter | type | description |
|---|---|---|
| text | string |
Popup :this
setHTML(html)Popuplate a popup element with HTML content
| parameter | type | description |
|---|---|---|
| html | string |
Popup :this
setLatLng(latlng)Set the coordinates of a popup element to a map
| parameter | type | description |
|---|---|---|
| latlng | LatLng |
Popup :this
removeRemoves the popup from the map
Popup :this
var popup =new mapboxgl.Popup().addTo(map);popup.remove();
addTo(map)Attaches the popup to a map
| parameter | type | description |
|---|---|---|
| map | Map |
Popup :this
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 |
this zoomOut(animOptions)Zoom out by 1 level
| parameter | type | description |
|---|---|---|
| animOptions |
this zoomIn(animOptions)Zoom in by 1 level
| parameter | type | description |
|---|---|---|
| animOptions |
this update(updateStyle)Update this map's style and re-render the map.
| parameter | type | description |
|---|---|---|
| updateStyle | Object | new style |
Map :this
stopStop current animation
this setView(center, zoom, bearing, pitch)Sets a map position
| parameter | type | description |
|---|---|---|
| center | Array | Latitude and longitude (passed as |
| 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 |
Map :this
setZoom(zoom)Sets a map zoom
| parameter | type | description |
|---|---|---|
| zoom | number | Map zoom level |
Map :this
unproject(point)Get geographical coordinates given pixel coordinates
| parameter | type | description |
|---|---|---|
| point | Array<number> | [x, y] pixel coordinates |
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 theStyle Specification |
Map :this
setBearing(bearing)Sets a map rotation
| parameter | type | description |
|---|---|---|
| bearing | number | Map rotation bearing in degrees counter-clockwise from north |
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 theStyle Specification |
| klass | [ | optional class specifier for the property |
Map :this
setCenter(center)Sets a map location
| parameter | type | description |
|---|---|---|
| center | Array | Latitude and longitude (passed as |
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 theStyle Specification |
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 |
Map :this
rotateTo(bearing, animOptions)Rotate bearing by a certain number of degrees with easing
| parameter | type | description |
|---|---|---|
| bearing | Number | |
| animOptions |
this setStyle(style)Replaces the map's style object
| parameter | type | description |
|---|---|---|
| style | Object | A style object formatted as JSON |
Map :this
removeSource(id)Remove an existing source from the map style.
| parameter | type | description |
|---|---|---|
| id | string | ID of the source to remove |
Map :this
getSource(id)Return the style source object with the givenid.
| parameter | type | description |
|---|---|---|
| id | string | source ID |
Object project(latlng)Get pixel coordinates (relative to map container) given a geographical location
| parameter | type | description |
|---|---|---|
| latlng | LatLng |
Object :x andy coordinates
hasClass(klass)Check whether a style class is active
| parameter | type | description |
|---|---|---|
| klass | string | Name of style class |
boolean removeLayer(id)Remove the layer with the givenid from the map. Any layers which refer to thespecified layer via aref property are also removed.
| parameter | type | description |
|---|---|---|
| id | string |
Map :this
removeClass(klass, options)Removes a style class from a map
| parameter | type | description |
|---|---|---|
| klass | string | name of style class |
| options | styleOptions |
Map :this
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 | [ | optional class specifier for the property |
Any :value for the paint propery
panBy(offset, animOptions)Pan by a certain number of pixels
| parameter | type | description |
|---|---|---|
| offset | Array | [x, y] |
| animOptions |
this loadedIs this map fully loaded? If the style isn't loadedor it has a change to the sources or style that isn'tpropagated to its style, return false.
boolean :whether the map is loaded
renderCall when a (re-)render of the map is required, e.g. when theuser panned or zoomed,f or new data is available.
Map :this
panTo(latlng, animOptions)Pan to a certain location with easing
| parameter | type | description |
|---|---|---|
| latlng | Object | a |
| animOptions |
this resetNorth(animOptions)Sets map bearing to 0 (north) with easing
| parameter | type | description |
|---|---|---|
| animOptions |
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 |
| zoom | Number | |
| bearing | Number | |
| pitch | Number | |
| animOptions |
this flyTo(latlng, zoom, bearing, options)Flying animation to a specified location/zoom/bearing with automatic curve
| parameter | type | description |
|---|---|---|
| latlng | Object | a |
| zoom | Number | |
| bearing | Number | |
| options | Object |
getBearingGet the current bearing in degrees
number getClassesReturn an array of the current active style classes
boolean getBoundsGet the map's geographical bounds
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 |
Array :filter specification, as defined in theStyle 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 | [ | optional class specifier for the property |
Any :value for the layout propery
getContainerGet the Map's container as an HTML element
HTMLElement :container
getCanvasGet the Map's canvas as an HTML canvas
HTMLElement :canvas
setPitch(pitch)Sets a map angle
| parameter | type | description |
|---|---|---|
| pitch | number | The angle at which the camera is looking at the ground |
Map :this
addClass(klass, options)Adds a style class to a map
| parameter | type | description |
|---|---|---|
| klass | string | name of style class |
| options | styleOptions |
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 theMapbox GL Style Reference |
Map :this
addLayer(layer, [before])Add a layer to the map style. The layer will be inserted before the layer withIDbefore, or appended ifbefore is omitted.
| parameter | type | description |
|---|---|---|
| layer | Layer | |
| before | [ | ID of an existing layer to insert before |
Map :this
GeoJSONSourceCreate a GeoJSON data source instance given an options object
setData(data)Update source geojson data and rerender map
| parameter | type | description |
|---|---|---|
| data | Object orString | A GeoJSON data object or URL to it. The latter is preferable in case of large GeoJSON files. |
ControlA base class for map-related interface elements.
addTo(map)Add this control to the map, returning the control itselffor chaining. This will insert the control's DOM element intothe map's DOM element if the control has aposition specified.
| parameter | type | description |
|---|---|---|
| map | Map |
Control :this
AttributionCreates an attribution control
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 |
var latlng =new mapboxgl.LatLng(37.76, -122.44);
wrapReturn a newLatLng object whose longitude is wrapped to the range (-180, 180).
LatLng :wrapped LatLng object
convert(input)Convert an array to aLatLng object, or return an existingLatLng objectunchanged.
| parameter | type | description |
|---|---|---|
| input | Array<number> orLatLng |
|
LatLng :LatLng object or original input
EventedMethods mixed in to other classes for event capabilities.
listensCheck if an event is registered to a type
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 |
offRemove a event listener
on(type, listener)Subscribe to a specified event with a listener function the latter gets the data object that was passed tofire and additionallytarget andtype 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, anull bounding box is created.
| parameter | type | description |
|---|---|---|
| sw | LatLng | southwest |
| ne | LatLng | northeast |
var sw =new mapboxgl.LatLng(0,0);var ne =new mapboxgl.LatLng(10, -10);var bounds =new mapboxgl.LatLngBounds(sw, ne);
getSouthWestGet southwest corner
LatLng :southwest
getNorthEastGet northeast corner
LatLng :northeast
getNorthWestGet northwest corner
LatLng :northwest
getSouthEastGet southeast corner
LatLng :southeast
extend(obj)Extend the bounds to include a given LatLng or LatLngBounds.
| parameter | type | description |
|---|---|---|
| obj | LatLng orLatLngBounds | object to extend to |
LatLngBounds :this
VideoSourceCreate 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 |
windowmapboxgl is a A WebGL JavaScript interactive maps library that can renderMapbox vector tiles.
lngX(lon)lat/lon <-> absolute pixel coords conversion
| parameter | type | description |
|---|---|---|
| lon | Number |