Other

Some style properties are no longer the preferred method of accomplishing a particular styling goal. While they are still supported, they will eventually be removed from the Nextbillion.ai Style Specification and it is not recommended to use them in new styles. The following is provided as reference for users who need to continue maintaining legacy styles while transitioning to preferred style properties.

Function

property expressions is the preferred method for styling features based on zoom level or the feature's properties. Zoom and property functions are still supported, but will be phased out in a future release.

The value for any layout or paint property may be specified as a function. Functions allow you to make the appearance of a map feature change with the current zoom level and/or the feature's properties.

stops

Required (except for identity functions) array.

A set of one input value and one output value is a "stop." Stop output values must be literal values (i.e. not functions or expressions), and appropriate for the property. For example, stop output values for a fill-color function property must be colors.

Please note that stops is not mandatory for identity functions.

property

Optional string.

If specified, the function will take the specified feature property as an input. See Zoom Functions and Property Functions for more information

base

Optional number. Default is 1.

The exponential base of the interpolation curve. It controls the rate at which the function output increases. Higher values make the output increase more towards the high end of the range. With values close to 1 the output increases linearly.

type

Optional string. One of "identity", "exponential", "interval", or "categorical".

It supports following values:

  • identity: A function that returns its input as the output.

  • exponential: A function that generates an output by interpolating between stops just less than and just greater than the function input. The domain (input value) must be numeric, and the style property must support interpolation. Style properties that support interpolation are marked with ,the "exponential" symbol, and exponential is the default function type for these properties.

  • interval: A function that returns the output value of the stop just less than the function input. The domain (input value) must be numeric. Any style property may use interval functions. For properties marked with , the "interval" symbol, this is the default function type.

  • categorical: A function that returns the output value of the stop equal to the function input.

default

A value to serve as a fallback function result when a value isn't otherwise available. It is used in the following circumstances:

  • In categorical functions, when the feature value does not match any of the stop domain values.

  • In property and zoom-and-property functions, when a feature does not contain a value for the specified property.

  • In identity functions, when the feature value is not valid for the style property (for example, if the function is being used for a circle-color property but the feature property value is not a string or not a valid color).

  • In interval or exponential property and zoom-and-property functions, when the feature value is not numeric.

If no default is provided, the style property's default is used in these circumstances.

colorSpace

Optional string. One of "rgb", "lab", "hcl".

The color space in which colors interpolated. Interpolating colors in perceptual color spaces like LAB and HCL tend to produce color ramps that look more consistent and produce colors that can be differentiated more easily than those interpolated in RGB space.

  • hcl: Use the HCL color space to interpolate color values, interpolating the Hue, Chroma, and Luminance channels individually.

  • lab: Use the LAB color space to interpolate color values.

  • rgb: Use the RGB color space to interpolate color values

Zoom functions allow the appearance of a map feature to change with map’s zoom level. Zoom functions can be used to create the illusion of depth and control data density. Each stop is an array with two elements: the first is a zoom level and the second is a function output value.

1
{
2
"circle-radius": {
3
"stops": [
4
// zoom is 5 -> circle radius will be 1px
5
[5, 1],
6
// zoom is 10 -> circle radius will be 2px
7
[10, 2]
8
]
9
}
10
}

The rendered values of color, number, and array properties are interpolated between stops. Boolean and string property values cannot be interpolated, so their rendered values only change at the specified stops.

There is an important difference between the way that zoom functions render for layout and paint properties. Paint properties are continuously re-evaluated whenever the zoom level changes, even fractionally. The rendered value of a paint property will change, for example, as the map moves between zoom levels 4.1 and 4.6. Layout properties, however, are evaluated only once for each integer zoom level. To continue the prior example: the rendering of a layout property will not change between zoom levels 4.1 and 4.6, no matter what stops are specified; but at zoom level 5, the function will be re-evaluated according to the function, and the property's rendered value will change. (You can include fractional zoom levels in a layout property zoom function, and it will affect the generated values; but, still, the rendering will only change at integer zoom levels.)

Property functions allow the appearance of a map feature to change with its properties. Property functions can be used to visually differentiate types of features within the same layer or create data visualizations. Each stop is an array with two elements, the first is a property input value and the second is a function output value. Note that support for property functions is not available across all properties and platforms.

1
{
2
"circle-color": {
3
"property": "temperature",
4
"stops": [
5
// "temperature" is 0 -> circle color will be blue
6
[0, 'blue'],
7
// "temperature" is 100 -> circle color will be red
8
[100, 'red']
9
]
10
}
11
}

Zoom-and-property functions allow the appearance of a map feature to change with both its properties and zoom. Each stop is an array with two elements, the first is an object with a property input value and a zoom, and the second is a function output value. Note that support for property functions is not yet complete.

1
{
2
"circle-radius": {
3
"property": "rating",
4
"stops": [
5
// zoom is 0 and "rating" is 0 -> circle radius will be 0px
6
[{zoom: 0, value: 0}, 0],
7
8
// zoom is 0 and "rating" is 5 -> circle radius will be 5px
9
[{zoom: 0, value: 5}, 5],
10
11
// zoom is 20 and "rating" is 0 -> circle radius will be 0px
12
[{zoom: 20, value: 0}, 0],
13
14
// zoom is 20 and "rating" is 5 -> circle radius will be 20px
15
[{zoom: 20, value: 5}, 20]
16
]
17
}
18
}


Other filter

In previous versions of the style specification, filters were defined using the deprecated syntax documented below. Though filters defined with this syntax will continue to work, we recommend using the more flexible expression syntax instead. Expression syntax and the deprecated syntax below cannot be mixed in a single filter definition.

Existential filters

["has", key] feature[key] exists

["!has", key] feature[key] does not exist

Comparison filters

["==", key, value] equality: feature[key] = value

["!=", key, value] inequality: feature[key]value

[">", key, value greater than: feature[key] > value

[">=", key, value greater than or equal: feature[key]value

["<", key, value less than: feature[key] < value

["<", key, value less than or equal: feature[key]value

Set membership filters

["in", key, v0, ..., vn] set inclusion: feature[key] ∈ {v0, ..., vn}

["!in", key, v0, ..., vn] set exclusion: feature[key] ∉ { v0, ..., vn}

Combining filters

["all", f0, ..., fn] logical AND: f0 ∧ ... ∧ fn

["any", f0, ..., fn] logical OR: f0 ∨ ... ∨ fn

["none", f0, ..., fn] logical NOR: ¬f0 ∧ ... ∧ ¬fn

A key must be a string that identifies a feature property, or one of the following special keys:

  • "$type": the feature type. This key may be used with the "==","!=", "in", and "!in" operators. Possible values are "Point", "LineString", and "Polygon".
  • "$id": the feature identifier. This key may be used with the "==","!=", "has", "!has", "in", and "!in" operators.

A value (and v0, ..., vn for set operators) must be a string, number, or boolean to compare the property value against.

Set membership filters are a compact and efficient way to test whether a field matches any of multiple values.

The comparison and set membership filters implement strictly-typed comparisons; for example, all of the following evaluate to false: 0 &lt; "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.

1
["==", "$type", "LineString"]

This filter requires that the class property of each feature is equal to either "street_major", "street_minor", or "street_limited".

1
["in", "class", "street_major", "street_minor", "street_limited"]`

The combining filter "all" takes the three other filters that follow it and requires all of them to be true for a feature to be included: a feature must have a class equal to "street_limited", its admin_level must be greater than or equal to 3, and its type cannot be Polygon. You could change the combining filter to "any" to allow features matching any of those criteria to be included - features that are Polygons, but have a different class value, and so on.

1
[
2
"all",
3
["==", "class", "street_limited"],
4
[">=", "admin_level", 3],
5
["!in", "$type", "Polygon"]
6
]

© 2024 NextBillion.ai all rights reserved.