An expression defines a formula for computing the value of any layout property, paint property, or filter within a map style. Expressions allow you to style data with multiple feature properties at once, apply conditional logic, and manipulate data with mathematical, logical, and string operators. This allows for sophisticated runtime styling.
For a complete list of all available expressions, see the Mapbox Style Specification.
Mapbox GL JS expressions uses a Lisp-like syntax, using JSON arrays. Expressions in Mapbox GL JS follow this format:
[expression_name, argument_0, argument_1, ...]
expression_name is the expression operator. For example, you would use
* to multiply two arguments:
['*', ['pi'], ['^', 3, 2]]
The first argument is
pi, which is an expression that returns the mathematical constant pi. The second argument is another expression in which
^ has two arguments of its own. It will return 32, and the result will be multiplied by pi.
In the Maps SDK for Android expressions are JSON arrays, in which the first element is the expression operator and the other elements are the arguments to the expression. For more information on using expressions in the Maps SDK for Android, see the expressions documentation page. Expressions are an important part of the Maps SDK's concept of data-driven styling. The Mapbox Annotations Plugin for Android also simplifies using expressions to adjust the visual properties of annotations on a Mapbox map.
- Expression documentation
- Mapbox Maps SDK for iOS predicates and expressions documentation
- Mapbox Maps SDK for Android expressions documentation
- Tutorial: Get started with Mapbox GL JS expressions
- Tutorial: Get started with expressions using the Mapbox Maps SDK for iOS
- Tutorial: Create interactive hover effects with Mapbox GL JS