Sources
A map or layer source states which data the map should display. Specify the type of source with the "type"
property, which must be one of vector, raster, raster-array, raster-dem, geojson, image, video.
A source provides map data that Mapbox GL JS can use with a style document to render a visual representation of that data. This delegation makes it possible to style the same source in different ways, as you might do to differentiate the appearances of different types of roads in a highways layer.
Adding a source to a map or layer isn't enough to make data appear on the map. You must also specify a style to provide properties like color or width for each feature.
Tiled sources
Tiled sources (vector and raster) must specify their details according to the TileJSON specification. There are several ways to do so:
- By supplying TileJSON properties such as
"tiles"
,"minzoom"
, and"maxzoom"
directly in the source:
"mapbox-streets": {
"type": "vector",
"tiles": [
"http://a.example.com/tiles/{z}/{x}/{y}.pbf",
"http://b.example.com/tiles/{z}/{x}/{y}.pbf"
],
"maxzoom": 14
}
- By providing a
"url"
to a TileJSON resource:
"mapbox-streets": {
"type": "vector",
"url": "http://api.example.com/tilejson.json"
}
- By providing a URL to a WMS server that supports EPSG:3857 (or EPSG:900913) as a source of tiled data. The server URL should contain a
"{bbox-epsg-3857}"
replacement token to supply thebbox
parameter.
"wms-imagery": {
"type": "raster",
"tiles": [
"http://a.example.com/wms?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&width=256&height=256&layers=example"
],
"tileSize": 256
}
vector
A vector tile source. Tiles must be in Mapbox Vector Tile format. All geometric coordinates in vector tiles must be between -1 * extent
and (extent * 2) - 1
inclusive. All layers that use a vector source must specify a "source-layer"
value. For vector tiles hosted by Mapbox, the "url"
value should be of the form mapbox://tilesetid
.
"mapbox-streets": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v6"
}
SDK Support | Mapbox GL JS | Android SDK | iOS SDK |
---|---|---|---|
basic functionality | >= 0.10.0 | >= 2.0.1 | >= 2.0.0 |
attribution
Contains an attribution to be displayed when the map is shown to a user.
bounds
An array containing the longitude and latitude of the southwest and northeast corners of the source's bounding box in the following order: [sw.lng, sw.lat, ne.lng, ne.lat]
. When this property is included in a source, no tiles outside of the given bounds are requested by Mapbox GL.
maxzoom
22
. Maximum zoom level for which tiles are available, as in the TileJSON spec. Data from tiles at the maxzoom are used when displaying the map at higher zoom levels.
minzoom
0
. Minimum zoom level for which tiles are available, as in the TileJSON spec.
promoteId
A property to use as a feature id (for feature state). Either a property name, or an object of the form {<sourceLayer>: <propertyName>}
. If specified as a string for a vector tile source, the same property is used across all its source layers. If specified as an object only specified source layers will have id overriden, others will fallback to original feature id
scheme
Influences the y direction of the tile coordinates. The global-mercator (aka Spherical Mercator) profile is assumed.
"xyz"
:Slippy map tilenames scheme.
"tms"
:OSGeo spec scheme.
tiles
An array of one or more tile source URLs, as in the TileJSON spec. Required if url
is not provided.
url
A URL to a TileJSON resource. Supported protocols are http:
, https:
, and mapbox://<Tileset ID>
. Required if tiles
is not provided.
volatile
false
. A setting to determine whether a source's tiles are cached locally.
SDK Support | Mapbox GL JS | Android SDK | iOS SDK |
---|---|---|---|
basic functionality | Not yet supported | >= 9.3.0 | >= 5.10.0 |
raster
A raster tile source. For raster tiles hosted by Mapbox, the "url"
value should be of the form mapbox://tilesetid
.
"mapbox-satellite": {
"type": "raster",
"url": "mapbox://mapbox.satellite",
"tileSize": 256
}
SDK Support | Mapbox GL JS | Android SDK | iOS SDK |
---|---|---|---|
basic functionality | >= 0.10.0 | >= 2.0.1 | >= 2.0.0 |
attribution
Contains an attribution to be displayed when the map is shown to a user.
bounds
An array containing the longitude and latitude of the southwest and northeast corners of the source's bounding box in the following order: [sw.lng, sw.lat, ne.lng, ne.lat]
. When this property is included in a source, no tiles outside of the given bounds are requested by Mapbox GL.
maxzoom
22
. Maximum zoom level for which tiles are available, as in the TileJSON spec. Data from tiles at the maxzoom are used when displaying the map at higher zoom levels.
minzoom
0
. Minimum zoom level for which tiles are available, as in the TileJSON spec.
scheme
Influences the y direction of the tile coordinates. The global-mercator (aka Spherical Mercator) profile is assumed.
"xyz"
:Slippy map tilenames scheme.
"tms"
:OSGeo spec scheme.
tiles
An array of one or more tile source URLs, as in the TileJSON spec. Required if url
is not provided.
tileSize
512
. The minimum visual size to display tiles for this layer. Only configurable for raster layers.