Skip to content

Expressions

Filters and property values are MapLibre expressions: JSON arrays like ["get", "name"]. mapterm evaluates the subset that makes sense in a terminal, and rejects anything else with an error, so a style falls back to the property’s default (or hides a layer whose filter it can’t understand) instead of drawing the wrong thing.

Group Operators
Data get, has, !has, literal, geometry-type, zoom, feature-state
Comparison ==, !=, <, <=, >, >=
Logic all, any, none, !, in, !in
Choice match, case, coalesce
Ramps interpolate (linear, exponential, cubic-bezier), interpolate-hcl, interpolate-lab, step
Math +, -, *, /, %, min, max
Strings concat, format (text only), upcase, downcase, index-of, slice, length
Types to-string, to-number, to-boolean, to-color, typeof, string, number, boolean

Colors can be CSS hex (#rgb, #rrggbb, with alpha), rgb(), rgba(), hsl(), hsla(), or common CSS names (cyan, orange, navy, …).

Older styles still work:

  • Legacy filters: ["==", "class", "park"], ["in", "class", "a", "b"], ["has", "name"]
  • Zoom functions: {"stops": [[5, 1], [10, 4]], "base": 1.2}
  • Token strings in text-field: "{name}"

Color roads by class, with a default:

["match", ["get", "class"],
"motorway", "#eb6e3c",
"trunk", "#e1a046",
"primary", "#d2c36e",
"#5a5a5a"]

Only show small places once zoomed in:

["any",
["in", ["get", "class"], ["literal", ["city", "country"]]],
[">=", ["zoom"], 11]]

Fade a fill in between zoom 10 and 13:

["interpolate", ["linear"], ["zoom"], 10, 0, 13, 1]

Tidy US route shields, as the built-in style does:

["case",
["==", ["get", "network"], "us-interstate"], ["concat", "I-", ["get", "ref"]],
["==", ["get", "network"], "us-highway"], ["concat", "US ", ["get", "ref"]],
["get", "ref"]]

Light a feature up while the pointer is over it, with feature state:

["case", ["boolean", ["feature-state", "hover"], false], "#ffcc00", "#204060"]

Expressions that use zoom are evaluated at the camera’s zoom, including fractional zooms and overzoom past a source’s maximum tile level, so ramps change smoothly as you zoom.