Sources

Contents

Sources state which data the map should display. Specify the type of source with the “type” property, which must be one of vector, raster, raster-dem, geojson, image, video. Adding a source isn’t enough to make data appear on the map because sources don’t contain styling details like color or width. Layers refer to a source and give it a visual representation. This makes it possible to style the same source in different ways, like differentiating between types of roads in a highways layer.

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:
"my-datasource": {
    "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:
"my-datasource": {
    "type": "vector",
    "url": "https://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 the bbox parameter.
"wms-imagery": {
    "type": "raster",
    "tiles": [
        "https://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.

"my-datasource": {
  "type": "vector",
  "url": "https://api.example.com/tilejson.json"
}

attribution #

Optional string.

Contains an attribution to be displayed when the map is shown to a user.

bounds #

Optional array of numbers. Defaults to [-180,-85.051129,180,85.051129].

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.

maxzoom #

Optional number. Defaults to 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 #

Optional number. Defaults to 0.

Minimum zoom level for which tiles are available, as in the TileJSON spec.

scheme #

Optional enum. One of "xyz", "tms". Defaults to "xyz".

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 #

Optional array of strings.

An array of one or more tile source URLs, as in the TileJSON spec.

url #

Optional string.

A URL to a TileJSON resource. Supported protocols are http: and https:.

raster #

A raster tile source.

“satellite-data”: { “type”: “raster”, “url”: “https://…”, “tileSize”: 256 }

attribution #

Optional string.

Contains an attribution to be displayed when the map is shown to a user.

bounds #

Optional array of numbers. Defaults to [-180,-85.051129,180,85.051129].

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.

maxzoom #

Optional number. Defaults to 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 #

Optional number. Defaults to 0.

Minimum zoom level for which tiles are available, as in the TileJSON spec.

scheme #

Optional enum. One of "xyz", "tms". Defaults to "xyz".

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.

tileSize #

Optional number. Units in pixels. Defaults to 512.

The minimum visual size to display tiles for this layer. Only configurable for raster layers.

tiles #

Optional array of strings.

An array of one or more tile source URLs, as in the TileJSON spec.

url #

Optional string.

A URL to a TileJSON resource. Supported protocols are http: and https:.

geojson #

A GeoJSON source. Data must be provided via a "data" property, whose value can be a URL or inline GeoJSON.

"geojson-marker": {
    "type": "geojson",
    "data": {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [-77.0323, 38.9131]
        },
        "properties": {
            "title": "Monument DC",
            "marker-symbol": "monument"
        }
    }
}

This example of a GeoJSON source refers to an external GeoJSON document via its URL. The GeoJSON document must be on the same domain or accessible using CORS.

"geojson-lines": {
    "type": "geojson",
    "data": "./lines.geojson"
}

attribution #

Optional string.

Contains an attribution to be displayed when the map is shown to a user.

buffer #

Optional number between 0 and 512 inclusive. Defaults to 128.

Size of the tile buffer on each side. A value of 0 produces no buffer. A value of 512 produces a buffer as wide as the tile itself. Larger values produce fewer rendering artifacts near tile edges and slower performance.

cluster #

Optional boolean. Defaults to false.

If the data is a collection of point features, setting this to true clusters the points by radius into groups. Cluster groups become new Point features in the source with additional properties:

  • cluster Is true if the point is a cluster
  • cluster_id A unique id for the cluster to be used in conjunction with the cluster inspection methods
  • point_count Number of original points grouped into this cluster
  • point_count_abbreviated An abbreviated point count

clusterMaxZoom #

Optional number.

Max zoom on which to cluster points if clustering is enabled. Defaults to one zoom less than maxzoom (so that last zoom features are not clustered).

clusterProperties #

Optional.

An object defining custom properties on the generated clusters if clustering is enabled, aggregating values from clustered points. Has the form {"property_name": [operator, map_expression]}. operator is any expression function that accepts at least 2 operands (e.g. "+" or "max") — it accumulates the property value from clusters/points the cluster contains; map_expression produces the value of a single point.

Example: {"sum": ["+", ["get", "scalerank"]]}.

For more advanced use cases, in place of operator, you can use a custom reduce expression that references a special ["accumulated"] value, e.g.: {"sum": [["+", ["accumulated"], ["get", "sum"]], ["get", "scalerank"]]}

clusterRadius #

Optional number greater than or equal to 0. Defaults to 50.

Radius of each cluster if clustering is enabled. A value of 512 indicates a radius equal to the width of a tile.

data #

Optional.

A URL to a GeoJSON file, or inline GeoJSON.

generateId #

Optional boolean. Defaults to false.

Whether to generate ids for the geojson features. When enabled, the feature.id property will be auto assigned based on its index in the features array, over-writing any previous values.

lineMetrics #

Optional boolean. Defaults to false.

Whether to calculate line distance metrics. This is required for line layers that specify line-gradient values.

maxzoom #

Optional number. Defaults to 18.

Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels).

tolerance #

Optional number. Defaults to 0.375.

Douglas-Peucker simplification tolerance (higher means simpler geometries and faster performance).

image #

An image source. The "url" value contains the image location.

The "coordinates" array contains [longitude, latitude] pairs for the image corners listed in clockwise order: top left, top right, bottom right, bottom left.

"image": {
    "type": "image",
    "url": "https://assets.example.com/images/radar.gif",
    "coordinates": [
        [-80.425, 46.437],
        [-71.516, 46.437],
        [-71.516, 37.936],
        [-80.425, 37.936]
    ]
}

coordinates #

Required array of array of numbers.

Corners of image specified in longitude, latitude pairs.

url #

Required string.

URL that points to an image.

video #

A video source. The "urls" value is an array. For each URL in the array, a video element source will be created. To support the video across browsers, supply URLs in multiple formats.

The "coordinates" array contains [longitude, latitude] pairs for the video corners listed in clockwise order: top left, top right, bottom right, bottom left.

"video": {
    "type": "video",
    "urls": [
        "https://assets.example.com/videos/drone.mp4",
        "https://assets.example..com/videos/drone.webm"
    ],
    "coordinates": [
        [-122.51596391201019, 37.56238816766053],
        [-122.51467645168304, 37.56410183312965],
        [-122.51309394836426, 37.563391708549425],
        [-122.51423120498657, 37.56161849366671]
    ]
}

coordinates #

Required array of array of numbers.

Corners of video specified in longitude, latitude pairs.

urls #

Required array of strings.

URLs to video content in order of preferred format.

Last updated May 18, 2020.