Glossary

expression

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.

Expressions in Mapbox GL JS

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, ...]

The 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.

Expressions in the mobile Maps SDKs

The Maps SDK for iOS uses NSExpression and NSPredicate syntax for expressions instead of JSON arrays.

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.


Related resources:

Was this page helpful?