Layer
Quick answer
Layer is the declarative draw instruction passed to map.addLayer, pairing a source with a type and paint and layout rules. Type decides geometry handling: fill, line, circle, symbol, heatmap, fill-extrusion, raster, hillshade or background. filter plus minzoom and maxzoom narrow what renders without changing the data.
map.addLayer( layer , beforeId )
Key points
- Required fields are id, type and, for most types, source.
- paint and layout properties accept data-driven style expressions.
- beforeId in addLayer controls stacking; filter hides unmatched features.
Example
map.addLayer({
id: 'zones-fill',
type: 'fill',
source: 'zones',
paint: {
'fill-color': ['get', 'color'],
'fill-opacity': 0.35
}
}, 'labels'); // 插到 labels 图层下面map.addLayer({
id: 'major-roads',
type: 'line',
source: 'base',
'source-layer': 'roads',
filter: ['all',
['==', ['get', 'class'], 'primary'],
['>', ['get', 'length'], 500]
],
minzoom: 8,
paint: { 'line-color': '#c2410c', 'line-width': 2 }
});
Notes
- Reusing an existing layer id throws instead of replacing the layer.
- A symbol layer without icon-image or text-field renders nothing.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Layer. https://www.jingweizhi.com/en/maplibre/api/layer.html (accessed 2026-11-03).