3D Terrain
Enable 3D terrain rendering using MapTiler DEM tiles with elevation. Each library takes its own approach, compared side by side below.
Quick recommendations
MapLibre GL JS: Suits projects that need manual control over the raster-dem source, terrain exaggeration, and sky/atmosphere settings.
MapTiler SDK: Best for the simplest terrain setup, because enableTerrain() is a one-call helper that configures the DEM source automatically.
At a glance
| MapLibre | SDK | |
|---|---|---|
| Coordinates | [lng, lat] | [lng, lat] |
| Rendering | WebGL (GPU, 60fps) | WebGL (GPU, 60fps) |
| Bundle size | ~300 KB gzipped | ~360 KB gzipped (includes MapLibre) |
| Learning curve | Moderate (source/layer model, expressions) | Easy (MapLibre API with convenience helpers) |
| 3D support | Full: terrain, fill-extrusion, globe, sky | Full (same as MapLibre) |
| Code lines | 27 | 10 |
Code snippets
Click a library to expand its code. Each snippet shows only the core logic: the scaffold handles HTML boilerplate.
MapLibre GL JS 27 lines Show code
const map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/outdoor-v4/style.json?key=YOUR_MAPTILER_KEY',
center: [7.66, 45.98],
zoom: 12,
pitch: 60,
bearing: -20,
maxPitch: 85
});
map.addControl(new maplibregl.NavigationControl());
map.on('load', () => {
map.addSource('terrain-dem', {
type: 'raster-dem',
url: 'https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json?key=YOUR_MAPTILER_KEY',
tileSize: 256
});
map.setTerrain({ source: 'terrain-dem', exaggeration: 1.5 });
map.setSky({
'sky-color': '#199EF3',
'horizon-color': '#ffffff',
'fog-color': '#ffffff',
'sky-horizon-blend': 0.5,
'horizon-fog-blend': 0.5,
'fog-ground-blend': 0.5,
'atmosphere-blend': ['interpolate', ['linear'], ['zoom'], 0, 1, 10, 1, 12, 0]
});
}); MapTiler SDK 10 lines Show code
maptilersdk.config.apiKey = 'YOUR_MAPTILER_KEY';
const map = new maptilersdk.Map({
container: 'map',
style: maptilersdk.MapStyle.OUTDOOR,
center: [6.8652, 45.8326],
zoom: 12,
pitch: 60,
terrain: true,
terrainExaggeration: 1.5
}); Things to know
Implementation-specific details that matter for 3d terrain.
Requires adding a raster-dem source and calling setTerrain() after the load event; exaggeration multiplies real elevation values.
enableTerrain() abstracts the DEM source setup into a single method call; terrain: true in the constructor also works.
Which library to use?
Render 3D terrain in MapLibre GL JS from a MapTiler raster-dem source with map.setTerrain() and an exaggeration factor, plus fog via setSky().
Suits projects that need manual control over the raster-dem source, terrain exaggeration, and sky/atmosphere settings.
Turn on 3D terrain in MapTiler SDK with the terrain and terrainExaggeration options of maptilersdk.Map, then tilt the camera with pitch to see the relief.
Best for the simplest terrain setup, because enableTerrain() is a one-call helper that configures the DEM source automatically.
Build maps with AI
Generate code like these examples using mapping library skills in your IDE.