Atlaslog
Atlaslog / MapLibre GL JS / Tutorial / Expressions and data-driven styling
MapLibre GL JS · Tutorial

Expressions and data-driven styling

Quick answer

This tutorial explains MapLibre style expressions: JSON arrays whose first element is the operator. It separates data-driven input such as ['get', 'level'] from camera-driven input such as ['interpolate', ['linear'], ['zoom'], ...], then shows match and case for classified colors, step for threshold styling, coalesce for missing attributes, and feature-state for hover highlighting. You will be able to replace fixed paint values with property-aware rules.

Last verified 2026-11-03 · MapLibre GL JS 4.x · Cite this page
Key points
Example
map.addLayer({
  id: 'landuse-fill',
  type: 'fill',
  source: 'base',
  'source-layer': 'landuse',
  paint: {
    'fill-color': ['match', ['get', 'class'],
      'forest',  '#2f6b45',
      'farmland','#c9c07a',
      'urban',   '#c8c2ba',
      '#e8eef4'                       // 兜底
    ],
    'fill-opacity': ['case',
      ['==', ['get', 'class'], 'urban'], 0.55,
      0.35
    ]
  }
});
map.addLayer({
  id: 'sites-circle',
  type: 'circle',
  source: 'sites',
  paint: {
    'circle-radius': ['interpolate', ['linear'], ['zoom'],
      8,  3,
      12, 6,
      16, 14
    ],
    'circle-color': ['step', ['get', 'level'],
      '#9ecae1',           // level 小于 2
      2, '#4292c6',
      4, '#08519c'
    ],
    'circle-stroke-width': 1,
    'circle-stroke-color': '#ffffff'
  }
});
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Expressions and data-driven styling. https://www.jingweizhi.com/en/maplibre/tutorials/expressions.html (accessed 2026-11-03).