Expression
The value for any layout property, paint property, or filter may be specified as an expression. An expression defines a formula for computing the value of the property using the operators described below. The set of expression operators provided by MapLibre GL includes:
- Element
- Mathematical operators for performing arithmetic and other operations on numeric values
- Logical operators for manipulating boolean values and making conditional decisions
- String operators for manipulating strings
- Data operators, providing access to the properties of source features
- Camera operators, providing access to the parameters defining the current map view
Expressions are represented as JSON arrays. The first element of an expression array is a string naming the expression operator, e.g. "*"or "case". Subsequent elements (if any) are the arguments to the expression. Each argument is either a literal value (a string, number, boolean, or null), or another expression array.
Data expression: a data expression is any expression that access feature data -- that is, any expression that uses one of the data operators:get,has,id,geometry-type, or properties. Data expressions allow a feature's properties to determine its appearance. They can be used to differentiate features within the same layer and to create data visualizations.
Camera expression: a camera expression is any expression that uses the zoom operator. Such expressions allow the the appearance of a layer to change with the map's zoom level. Camera expressions can be used to create the appearance of depth and to control data density.
Composition: a single expression may use a mix of data operators, camera operators, and other operators. Such composite expressions allows a layer's appearance to be determined by a combination of the zoom level and individual feature properties.
Example expression:
FillLayer fillLayer = new FillLayer("layer-id", "source-id");
fillLayer.setProperties(
fillColor(
interpolate( linear(), zoom(),
stop(12, step(get("stroke-width"),
color(Color.BLACK),
stop(1f, color(Color.RED)),
stop(2f, color(Color.WHITE)),
stop(3f, color(Color.BLUE))
)),
stop(15, step(get("stroke-width"),
color(Color.BLACK),
stop(1f, color(Color.YELLOW)),
stop(2f, color(Color.LTGRAY)),
stop(3f, color(Color.CYAN))
)),
stop(18, step(get("stroke-width"),
color(Color.BLACK),
stop(1f, color(Color.WHITE)),
stop(2f, color(Color.GRAY)),
stop(3f, color(Color.GREEN))
))
)
)
);
Inheritors
Constructors
Types
Functions
FillLayer fillLayer = new FillLayer("layer-id", "source-id");
fillLayer.setProperties(
fillColor(color(Color.GREEN))
);
CircleLayer circleLayer = new CircleLayer("layer-id", "source-id");
circleLayer.setProperties(
circleRadius(sqrt(25.0f))
);
CircleLayer circleLayer = new CircleLayer("layer-id", "source-id");
circleLayer.setProperties(
circleRadius(sqrt(pi()))
);