Style Expression
Quick answer
A style expression is an array-form mini language: the first element names the operator and the remaining elements are arguments, evaluated per feature or per camera. Use interpolate with zoom for scale-dependent values, and get for feature-driven properties. Expressions replace the deprecated function objects in paint and layout.
['interpolate', ['linear'], ['zoom'], 4 , 1, 10 , 6]
Key points
- Data expressions read properties with ['get', 'name'].
- Camera expressions may use ['zoom'] but never ['get'].
- Literal arrays are wrapped as ['literal', [...]] to avoid operator parsing.
Example
/* 按属性分类着色,未命中的走默认色 */
map.setPaintProperty('world-fill', 'fill-color', [
'match', ['get', 'CONTINENT'],
'Asia', '#dbe7f3',
'Europe', '#e6e0f3',
'Africa', '#f3ecdb',
'#e9ecef'
]);
/* 线宽随缩放连续变化 */
map.setPaintProperty('world-line', 'line-width', [
'interpolate', ['linear'], ['zoom'],
2, 0.5,
6, 2,
10, 5
]);
/* 数值分段,避免连续插值造成图标忽大忽小 */
map.setPaintProperty('city-dot', 'circle-radius', [
'step', ['to-number', ['get', 'pop']],
3,
1000000, 6
]);
/* 缺属性时的兜底 */
map.setLayoutProperty('city-label', 'text-field', [
'coalesce', ['get', 'NAME'], ['get', 'name'], '未命名'
]);
Notes
- Mixing camera and data expressions inside one expression is rejected.
- Returning the wrong type, such as a number for a color property, fails validation.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Style Expression. https://www.jingweizhi.com/en/maplibre/api/style-expression.html (accessed 2026-11-03).