Mapbox Tiling Service


This is a complex example that uses Natural Earth Data's road data. The recipe generates a ranked quality attribute for each feature based on the road type defined in the source data. Then it filters attributes by these newly created quality attributes to keep only specific quality features per zoom level.

For example, the "Bypass" road type is the fourth ranked item (zero-indexed at 3). With the verbose filter definition below, you will only see "Bypass" style streets show up at zoom level 3 or greater.

"version": 1,
"layers": {
"roads": {
"source": "mapbox://tileset-source/{username}/road-data",
"minzoom": 0,
"maxzoom": 5,
"features": {
"attributes": {
"set": {
"quality": [
[ "get", "type" ],
"Ferry Route", 0,
"Major Highway", 1,
"Secondary Highway", 2,
"Bypass", 3,
"Beltway", 4,
"Road", 5,
"Track", 5,
"filter": [ "<=", [ "get", "quality" ], [ "zoom" ] ],
"simplification": [ "match", [ "zoom" ], 5, 1, 10 ]
FieldDescriptionData type
sourceThe source data to use for this layer. Tileset sources are created with the Create a tileset source endpoint of Mapbox Tiling Service (MTS).String
minzoomSpecify the minimum zoom at which your tileset will be available. A value of 0 here ensures that the roads will be visible at a global level.Integer
maxzoomSpecify the maximum zoom at which your tileset will be available. A value of 5 here ensures that the roads will be visible as the user zooms in a little bit, but will not be generated in higher precision if they zoom in significantly.Integer
features.attributes.setA JSON object that maps the names of attributes to be generated to filter expressions and returns the new attribute values for the final tileset. Here it is being used to generate a new quality attribute based on the type field included in the original data.Object
features.filterA verbose filter definition. Its use here excludes any feature from tiles where their quality attribute is greater than the current zoom level. For example, features with a quality attribute of "Bypass" will not be visible at zoom levels lower than or equal to 3.Array<Expression>
features.simplificationSpecify an integer value or expression that is greater than zero to control the level of simplification that occurs for features. The expression provided here gives a high precision (1) at the maximum zoom level (5) but lower precision (10) at other zoom levels.Integer expression
Was this page helpful?