--- layout: default category: reference title: Mapbox GL Style Reference permalink: / class: fill-light options: full navigation: - title: Root subnav: - title: version - title: name - title: metadata - title: center - title: zoom - title: bearing - title: pitch - title: sources - title: sprite - title: glyphs - title: transition - title: layers - title: Sources subnav: - title: Vector - title: Raster - title: GeoJSON - title: Image - title: Video - title: Sprite - title: Glyphs - title: Transition subnav: - title: duration - title: delay - title: Layers subnav: - title: Background - title: Fill - title: Line - title: Symbol - title: Raster - title: Circle - title: Types subnav: - title: Color - title: Enum - title: String - title: Boolean - title: Number - title: Array - title: Function - title: Filter ---

{{ page.title }}

The Mapbox GL style is an object that defines what data to draw, the order to draw it in, and how to style the data when drawing it. The JSON structure follows the renderer implementation very closely. It provides the basic building blocks out of which more complex styles can be built.

Key: supports interpolated functions supports piecewise constant functions transitionable

Root Properties

Top level properties on the Mapbox GL style object specify the map's appearance, sources, and layers.

{% highlight json%} { "version": <%= ref.$version %>, "name": "Mapbox Streets", "sprite": "mapbox://sprites/mapbox/streets-v<%= ref.$version %>", "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf", "sources": {...}, "layers": [...] } {% endhighlight %}
<% _(ref.$root).each(function(prop, name) { %> <%= item({prop: prop, id: "root-" + name, name: name}) %> <% }); %>
<% var source_types = ['vector', 'raster', 'geojson', 'image', 'video']; %>

Sources

Sources supply data to be shown on the map. The type of source is specified by the "type" property, and must be one of <%= source_types.join(', ') %>. Tiled sources (vector and raster) must specify their details in terms of the TileJSON specification. This can be done in two ways:

  • By supplying TileJSON properties such as "tiles", "minzoom", and "maxzoom" directly in the source:
    {% highlight json%} "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 } {% endhighlight %}
  • By providing a "url" to a TileJSON resource:
    {% highlight json%} "mapbox-streets": { "type": "vector", "url": "http://api.example.com/tilejson.json" } {% endhighlight %}

vector

A vector tile source. Tiles must be in Mapbox Vector Tile format. 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://mapid.

{% highlight json%} "mapbox-streets": { "type": "vector", "url": "mapbox://mapbox.mapbox-streets-v6" } {% endhighlight %}

raster

A raster tile source. For raster tiles hosted by Mapbox, the "url" value should be of the form mapbox://mapid.

{% highlight json%} "mapbox-satellite": { "type": "raster", "url": "mapbox://mapbox.satellite", "tileSize": 256 } {% endhighlight %}

geojson

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

{% highlight json%} "geojson-marker": { "type": "geojson", "data": { "type": "Feature", "geometry": { "type": "Point", "coordinates": [-77.0323, 38.9131] }, "properties": { "title": "Mapbox DC", "marker-symbol": "monument" } } } {% endhighlight %}

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.

{% highlight json%} "image": { "type": "image", "url": "/mapbox-gl-js/assets/radar.gif", "coordinates": [ [-80.425, 46.437], [-71.516, 46.437], [-71.516, 37.936], [-80.425, 37.936] ] } {% endhighlight %}

video

A video source. The "urls" value is an array. For each URL in the array, a video element source will be created, in order to support same media in multiple formats supported by different browsers.

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

{% highlight json%} "video": { "type": "video", "urls": [ "https://www.mapbox.com/drone/video/drone.mp4", "https://www.mapbox.com/drone/video/drone.webm" ], "coordinates": [ [-122.51596391201019, 37.56238816766053], [-122.51467645168304, 37.56410183312965], [-122.51309394836426, 37.563391708549425], [-122.51423120498657, 37.56161849366671] ] } {% endhighlight %}

Sprite

A style's sprite property supplies a URL template for loading small images to use in rendering background-pattern, fill-pattern, line-pattern, and icon-image style properties. <% if (ref.$root.sprite.example) { %>

{% highlight json %} <%= '"sprite": ' + JSON.stringify(ref.$root.sprite.example, null, 2) %> {% endhighlight %}
<% } %>

A valid sprite source must supply two types of files:

  • An index file, which is a JSON document containing a description of each image contained in the sprite. The content of this file must be a JSON object whose keys form identifiers to be used as the values of the above style properties, and whose values are objects describing the dimensions (width and height properties) and pixel ratio (pixelRatio) of the image and its location within the sprite (x and y). For example, a sprite containing a single image might have the following index file contents:
    {% highlight json%} { "poi": { "width": 32, "height": 32, "x": 0, "y": 0, "pixelRatio": 1 } } {% endhighlight %}
    Then the style could refer to this sprite image by creating a symbol layer with the layout property "icon-image": "poi", or with the tokenized value "icon-image": "{icon}" and vector tile features with a icon property with the value poi.
  • Image files, which are PNG images containing the sprite data.

Mapbox GL renderers will use the value of the sprite property in the style to generate the URLs for loading both files. First, for both file types, it will append @2x to the URL on high-DPI devices. Second, it will append a file extension: .json for the index file, and .png for the image file. For example, if you specified "sprite": "https://example.com/sprite", renderers would load https://example.com/sprite.json and https://example.com/sprite.png, or https://example.com/sprite@2x.json and https://example.com/sprite@2x.png.

If you are using Mapbox Studio, you will use prebuilt sprites provided by Mapbox, or you can upload custom SVG images to build your own sprite. In either case, the sprite will be built automatically and supplied by Mapbox APIs. If you want to build a sprite by hand and self-host the files, you can use spritezero-cli, a command line utility that builds Mapbox GL compatible sprite PNGs and index files from a directory of SVGs.

Glyphs

A style's glyphs property provides a URL template for loading signed-distance-field glyph sets in PBF format. <% if (ref.$root.glyphs.example) { %>

{% highlight json %} <%= '"glyphs": ' + JSON.stringify(ref.$root.glyphs.example, null, 2) %> {% endhighlight %}
<% } %>

Transition

A style's transition property provides global transition defaults for that style. <% if (ref.$root.transition.example) { %>

{% highlight json %} <%= '"transition": ' + JSON.stringify(ref.$root.transition.example, null, 2) %> {% endhighlight %}
<% } %>

<% _(ref.transition).each(function(prop, name) { %> <%= item({prop: prop, id: "transition-" + name, name: name}) %> <% }); %>
<% var layer_types = ['background', 'fill', 'line', 'symbol', 'raster', 'circle']; %>

Layers

A style's layers property lists all of the layers available in that style. The type of layer is specified by the "type" property, and must be one of <%= layer_types.join(', ') %>. <% if (ref.$root.layers.example) { %>

{% highlight json %} <%= '"layers": ' + JSON.stringify(ref.$root.layers.example, null, 2) %> {% endhighlight %}
<% } %>

<% _(ref.layer).each(function(prop, name) { %> <%= item({prop: prop, id: "layer-" + name, name: name}) %> <% }); %>

Layers have two sub-properties that determine how data from that layer is rendered: layout and paint properties.

Layout properties appear in the layer's "layout" object. They are applied early in the rendering process and define how data for that layer is passed to the GPU. For efficiency, a layer can share layout properties with another layer via the "ref" layer property, and should do so where possible. This will decrease processing time and allow the two layers will share GPU memory and other resources associated with the layer.

Paint properties are applied later in the rendering process. A layer that shares layout properties with another layer can have independent paint properties. Paint properties appear in the layer's "paint" object. Layers can also have class-specific paint properties, which are applied only when the map has a certain class name set. For example, a layer with a "paint.night" property would have those properties applied when the map has the "night" class set.

<% _(layer_types).each(function(t) { %>

<%= t %>

Layout Properties

<% if (_.isEmpty(ref['layout_'+t])) { %>
None
<% } else { %> <% _(ref['layout_'+t]).each(function(prop, name) { %> <%= item({prop: prop, id: "layout-" + t + "-" + name, name: name}) %> <% }); %> <% } %>

Paint Properties

<% _(ref['paint_'+t]).each(function(prop, name) { %> <%= item({prop: prop, id: "paint-" + name, name: name}) %> <% }); %>
<% }); %>

Types

Below is a list of types and an explanation of any expression that can be applied to properties in Mapbox GL.

Color

Mapbox GL accepts a variety of syntaxes for colors - HTML-style hex values, rgb, rgba, hsl, and hsla. It also supports the predefined HTML colors names, like yellow and blue.

{% highlight json %} { "line-color": "#ff0", "line-color": "#ffff00", "line-color": "rgb(255, 255, 0)", "line-color": "rgba(255, 255, 0, 1)", "line-color": "hsl(100, 50%, 50%)", "line-color": "hsla(100, 50%, 50%, 1)", "line-color": "yellow" } {% endhighlight %}

Especially of note is the support for hsl, which can be easier to reason about than rgb().

Enum

One of a fixed list of string values. Use quotes around values.

{% highlight json %} { "text-transform": "uppercase" } {% endhighlight %}

String

A string is basically just text. In the case of Mapbox GL, you're going to put it in quotes. Strings can be anything, though pay attention to the case of text-field - it actually will refer to features, which you refer to by putting them in curly braces, as seen in the example below.

{% highlight json %} { "text-field": "{MY_FIELD}" } {% endhighlight %}

Boolean

Boolean means yes or no, so it accepts the values true or false.

{% highlight json %} { "fill-enabled": true } {% endhighlight %}

Number

A number value, often an integer or floating point (decimal number). Written without quotes.

{% highlight json %} { "text-size": 24 } {% endhighlight %}

Array

Arrays are comma-separated lists of one or more numbers in a specific order. For example, they're used in line dash arrays, in which the numbers specify intervals of line, break, and line again.

{% highlight json %} { "line-dasharray": [2, 4] } {% endhighlight %}

Function

The value for any layout or paint property may be specified as a function, allowing you to parameterize the value according to the current zoom level. Functions are written as an array of stops, where each stop is an array with two elements: a zoom level and a corresponding value. Stops must be in ascending zoom order.

Some properties support interpolated functions. The result of an interpolated function is an interpolated value between the last stop whose zoom level is less than or equal to the current zoom level, and the next stop. By default, linear interpolation is used, but you can use a different exponential base for the interpolation curve via the base property. If the current zoom is less than the first stop or greater than the last stop, the result is the value from the first or last stop respectively.

All other properties support piecewise constant functions. The result of a piecewise constant function is the value of the last stop whose zoom value is less than or equal to the current zoom level.

{% highlight json %} { "line-width": { "base": 1.5, "stops": [[5, 1], [7, 2], [11, 3]] } } {% endhighlight %}
  • baseOptional number. Default is <%= ref.function.base.default %>.
    The exponential base of the interpolation curve. It controls the rate at which the result increases. Higher values make the result increase more towards the high end of the range. With values close to 1 the result increases linearly.
  • stopsRequired array.
    An array of zoom level and value pairs. The value can be a number or a color value for color properties.

Filter

A filter selects specific features from a layer. A filter is an array of one of the following forms:

["==", key, value] equality: key = value
["!=", key, value] inequality: keyvalue
[">", key, value] greater than: key > value
[">=", key, value] greater than or equal: keyvalue
["<", key, value] less than: key < value
["<=", key, value] less than or equal: keyvalue
["in", key, v0, ..., vn] set inclusion: key ∈ {v0, ..., vn}
["!in", key, v0, ..., vn] set exclusion: key ∉ {v0, ..., vn}
["all", f0, ..., fn] logical AND: f0 ∧ ... ∧ fn
["any", f0, ..., fn] logical OR: f0 ∨ ... ∨ fn
["none", f0, ..., fn] logical NOR: ¬f0 ∧ ... ∧ ¬fn

A filter's key must be a string that identifies a feature property, or the special key "$type", which identifies the feature type. A value (and v0, ..., vn for set operators) must be a string, number, or boolean to compare the property value against. For the "$type" key it must be one of "Point", "LineString", or "Polygon".

The binary and set operators implement strictly-typed comparisons; for example, all of the following evaluate to false: 0 < "1", 2 == "2", "true" in [true, false].

The "all", "any", and "none" filter operators are used to create compound filters. The values f0, ..., fn must be filter expressions themselves.

{% highlight json%} ["==", "$type", "LineString"] {% endhighlight %}
{% highlight json%} ["in", "class", "street_major", "street_minor", "street_limited"] {% endhighlight %}
{% highlight json%} [ "all", ["==", "class", "street_limited"], [">=", "admin_level", 3], ["!in", "$type", "Polygon"] ] {% endhighlight %}