switch
Selects the first output from the given conditions whose corresponding test condition evaluates to true
, or the fallback value otherwise.
Example:
switch(
condition(
test = feature.has("color1") and feature.has("color2"),
output = interpolate(
linear(),
zoom(),
1 to feature.get("color1").convertToColor(),
20 to feature.get("color2").convertToColor()
),
),
condition(
test = feature.has("color"),
output = feature.get("color").convertToColor(),
),
fallback = const(Color.Red),
)
If the feature has both a "color1" and "color2" property, the result is an interpolation between these two colors based on the zoom level. Otherwise, if the feature has a "color" property, that color is returned. If the feature has none of the three, the color red is returned.
Selects the output from the given cases whose label value matches the input, or the fallback value if no match is found.
Each label must be unique. If the input type does not match the type of the labels, the result will be the fallback value.
Example:
switch(
input = feature.get("building_type").asString(),
case(
label = "residential",
output = const(Color.Cyan),
),
case(
label = listOf("commercial", "industrial"),
output = const(Color.Yellow),
),
fallback = const(Color.Red),
)
If the feature has a property "building_type" with the value "residential", cyan is returned. Otherwise, if the value of that property is either "commercial" or "industrial", yellow is returned. If none of that is true, the fallback is returned, i.e. red.