Atlaslog / Field Notes / MapLibre styles & layers
Field note · MapLibre styles & layers
setTerrain is accepted but the ground stays flat
Quick answer
map.getTerrain() returns the configuration and no error fires, yet tilting the camera shows no relief because the DEM source is mistyped or mis-encoded. A wrong encoding yields either near-zero heights or huge spikes.
Symptom
- map.setTerrain({ source: 'terrain', exaggeration: 1.5 }) runs, yet setPitch(55) still shows a flat plane.
- Error: Source "terrain" cannot be used as terrain because it is not a raster-dem source.
- fill-extrusion buildings stand on a flat base instead of following the slope.
Checklist
- Print map.getSource('terrain').type and map.getTerrain().
- Check the declared encoding against the DEM producer, terrarium versus mapbox.
- Download one DEM tile and check whether it is 256x256 or 512x512.
- Check maxzoom against the current zoom and whether the view is tilted at all.
Fix
Declare type: 'raster-dem' with encoding 'terrarium', tileSize matching the tiles, minzoom 0 and maxzoom 12, then setTerrain with exaggeration 1.5 and setPitch(55) so relief becomes visible.
Code
Error: Source "terrain" cannot be used as terrain because it is not a raster-dem source.var src = map.getSource('terrain');
console.log('源类型', src.type);
console.log('地形配置', map.getTerrain());
map.on('error', function (e) { console.error(e.error && e.error.message); });
Watch out
- Raising exaggeration from 1.5 to 10 to make mountains appear amplifies wrong decoding into spikes.
- Setting tileSize: 512 for 256-pixel tiles interpolates elevations incorrectly and flattens the terrain.
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Atlaslog (2026). setTerrain is accepted but the ground stays flat. https://www.jingweizhi.com/en/cookbook/maplibre-terrain-not-work.html (accessed 2026-11-03).