Skip to main content

other

Some style properties are no longer the preferred method of achieving specific styling goals. Although they are still supported, they may be removed at a later date, so their use in styles is not recommended and is currently available for reference.

Method (Function)

The value of any layout or paint property can be specified as a function. Functions allow you to change the appearance of map properties based on the current map level and/or attributes of the features.

base

Optional attribute. number. Default value is 1.

Exponential basis for interpolation curves. It controls the rate at which the function’s output increases. The higher the number, the closer the output is to the top of the range. As the value approaches 1, the output increases linearly.

colorSpace

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

The color space into which the color is inserted. Interpolating colors in perceptual color spaces like LAB and HCL tends to produce color ramps that look more consistent and are easier to distinguish than interpolating colors in RGB space.

"rgb": Use RGB color space to interpolate color values.

"lab": Use LAB color space to interpolate color values.

"hcl": Use the HCL color space to interpolate color values, interpolating the hue, chroma and luminance channels separately.

Zoom functions allow the appearance of map functions to change depending on the zoom level of the map. Hierarchy functions can be used to create the illusion of depth and control data density. Each stop is an array containing two elements: the first is the map level, and the second is the function output value.

{
"circle-radius": {
"stops": [
// Zoom level is 5 -> radius of circle is 1 pixel
[5, 1],
// Zoom level is 10 -> radius of circle is 2 pixels
[10, 2]
]
}
}

Inserts rendered values ​​for color, number, and array properties between stops. Boolean and string property values ​​cannot be interpolated, so their rendered values ​​only change at specified stopping points.

There is an important difference between hierarchical functions rendering layouts and drawing properties. Drawing properties are constantly re-evaluated when the map hierarchy changes, even slightly. The render values ​​of the draw properties will change, for example, when the map moves between levels 4.1 and 4.6. However, layout properties are only evaluated once for each integer scaling level. Take the previous example: the rendering of the layout property will not change between 4.1 and 4.6, no matter what stop is specified; but at zoom level 5, the function will be recalculated based on the function, and the property’s rendering value will change. (You can include decimal levels in layout property level functions, which will affect the resulting values; however, rendering will still only change at integer levels.)

Property functions allow the appearance of a mapped property to change depending on its properties. Attribute functions can be used to visually differentiate between attribute types in the same layer, or to create data visualizations. Each stop is an array containing two elements, the first is the attribute input value, and the second is the function output value. Note that not all properties and platforms support property functions.

{
"circle-color": {
"property": "temperature",
"stops": [
// "Temperature" is 0 -> the color of the circle is blue
[0, 'blue'],
// "Temperature" is 100 -> the color of the circle is red
[100, 'red']
]
}
}

Zoom-and-property functions allow the appearance of map features to change with their properties and zoom. Each stop is an array containing two elements, the first is an object with property input values ​​and scale values, and the second is a function output value. Note that support for attribute functions is not yet complete.

{
"circle-radius": {
"property": "rating",
"stops": [
// zoom is 0 and "rating" is 0 -> the radius of the circle is 0 pixels
[{zoom: 0, value: 0}, 0],

// zoom is 0 and "rating" is 5 -> the radius of the circle is 5 pixels
[{zoom: 0, value: 5}, 5],

// zoom is 20 and "rating" is 0 -> the radius of the circle is 0 pixels
[{zoom: 20, value: 0}, 0],

// zoom is 20 and "rating" is 5 -> the radius of the circle is 20 pixels
[{zoom: 20, value: 5}, 20]
]
}
}

default

The value used as the fallback function result when a value is unavailable. Applies to the following situations:

  • In a classification function, when the feature value does not match any stopping domain value.
  • In attribute and scale attribute functions, when a property does not contain a value for the specified attribute.
  • In an identity function, when the feature value is invalid for the style attribute (for example, when the function is used for the circle color attribute, but the feature attribute value is not a string or an invalid color).
  • In interval or exponential properties and scaled properties, when feature values ​​are not numeric.

If no default value is provided, the style property’s default value is used in these cases.

property

Optional attribute. string.

If property is specified, the function will accept the specified feature attribute as input. For more information, see Hierarchy and Property Functions.

stops

Required attribute. array (except identity functions).

The set consisting of an input value and an output value is "stop". The stop output value must be a literal value (i.e. not a function or expression) and appropriate for this property. For example, the stop output value of the fill-color attribute must be colors.

type

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

"identity": A function that returns its input as output.

"exponential": A function that generates output by interpolating between stops that are slightly smaller or slightly larger than the function input. The field (input value) must be numeric, and the style attribute must support interpolation. Style properties that support interpolation are marked with the "exponential" notation, and exponential is the default function type for these properties.

"interval": A function that returns the output value of stop that is just less than the input value of the function. Field (input value) must be numeric. Any style attribute can use the spacer function. Properties marked with the "interval" symbol are the default function types.

"categorical": Returns a function whose output value of stop is equal to the function input value.

##Other filter

Existence judgment

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

Member Judgment

["!in", key, v0, ..., vn] Not included in: feature[key] ∉ { v0 , ..., vn }

Combination judgment

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

key must be a string identifying a feature attribute, or one of the following special keys:

  • "$type": Functional type. This key operates with "==", "!=", "in", and "!in". Possible values ​​are "Point", "LineString", and "Polygon".
  • "$id": Function identifier. This key operates with "==", "! = ", "has", "!has", "in", and "!in".

A value (and v0, …, vn for set operators) must be a string, number, or boolean in order to compare attribute values.

The set membership filter is an intensive and efficient way to test whether a field matches any of multiple values.

Comparison and collection feature filters implement strictly typed comparisons; for example, all of the following values ​​are 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 the filter expression itself.

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

This filter requires that the class attribute of each feature be equal to "street_major", "street_minor", or "street_limited".

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

The filter "all" contains the other three filters and requires all of its properties to be true. Including: A function must have a class equal to "street_limited", its admin_level must be greater than or equal to 3, polygons and their types are not allowed. You can change the combined filter to "any" to allow the inclusion of features that match any of these criteria - features that are polygons but have different class values, etc.

[
"all",
["==", "class", "street_limited"],
[">=", "admin_level", 3],
["!in", "$type", "Polygon"]
]