3D Building Extrusions
Add 3D extruded buildings from vector tile data using fill-extrusion layers. Each library takes its own approach, compared side by side below.
Quick recommendations
MapLibre GL JS: Best when you need full control over fill-extrusion paint properties, light direction, and data-driven height expressions.
MapTiler SDK: Combines MapLibre's fill-extrusion layers with automatic access to MapTiler building data.
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 | 37 | 37 |
Code snippets
Click a library to expand its code. Each snippet shows only the core logic: the scaffold handles HTML boilerplate.
MapLibre GL JS 37 lines Show code
const map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY',
center: [14.4205, 50.0875],
zoom: 16,
pitch: 55,
bearing: -20,
canvasContextAttributes: { antialias: true }
});
map.addControl(new maplibregl.NavigationControl());
map.on('load', () => {
const style = map.getStyle();
// Skip attribution-only vector sources (no url/tiles) such as maptiler_attribution.
const vectorSrc = Object.keys(style.sources).find(k =>
style.sources[k].type === 'vector' && (style.sources[k].url || style.sources[k].tiles));
if (!vectorSrc) return;
// Insert the 3D layer BEFORE the first label layer so labels stay on top.
const labelLayerId = style.layers.find(l => l.type === 'symbol' && l.layout && l.layout['text-field'])?.id;
map.addLayer({
id: '3d-buildings',
source: vectorSrc,
'source-layer': 'building',
type: 'fill-extrusion',
minzoom: 14,
filter: ['!=', ['get', 'hide_3d'], true],
paint: {
'fill-extrusion-color': '#aaa',
'fill-extrusion-height': [
'interpolate', ['linear'], ['zoom'],
14, 0,
16, ['coalesce', ['get', 'render_height'], 0]
],
'fill-extrusion-base': ['coalesce', ['get', 'render_min_height'], 0],
'fill-extrusion-opacity': 0.7
}
}, labelLayerId);
}); MapTiler SDK 37 lines Show code
maptilersdk.config.apiKey = 'YOUR_MAPTILER_KEY';
const map = new maptilersdk.Map({
container: 'map',
style: maptilersdk.MapStyle.STREETS,
center: [2.3488, 48.8534],
zoom: 15.5,
pitch: 60,
bearing: -17,
canvasContextAttributes: { antialias: true }
});
map.on('load', () => {
const style = map.getStyle();
// Skip attribution-only vector sources (no url/tiles) such as maptiler_attribution.
const src = Object.keys(style.sources).find(k =>
style.sources[k].type === 'vector' && (style.sources[k].url || style.sources[k].tiles));
if (!src) return;
// Insert above basemap but below labels so labels stay on top.
const labelLayerId = style.layers.find(l => l.type === 'symbol' && l.layout && l.layout['text-field'])?.id;
map.addLayer({
id: 'buildings-3d',
type: 'fill-extrusion',
source: src,
'source-layer': 'building',
minzoom: 14,
filter: ['!=', ['get', 'hide_3d'], true],
paint: {
'fill-extrusion-color': '#9C27B0',
'fill-extrusion-height': [
'interpolate', ['linear'], ['zoom'],
14, 0,
16, ['coalesce', ['get', 'render_height'], 0]
],
'fill-extrusion-base': ['coalesce', ['get', 'render_min_height'], 0],
'fill-extrusion-opacity': 0.8
}
}, labelLayerId);
}); Things to know
Implementation-specific details that matter for 3d building extrusions.
Fill-extrusion layers read height from vector tile properties; light settings (anchor, color, intensity) control the 3D appearance.
Identical fill-extrusion configuration to MapLibre; the SDK provides no extra 3D building helpers.
Which library to use?
Extrude MapTiler building footprints in MapLibre GL JS with a fill-extrusion layer whose fill-extrusion-height reads each feature's render_height.
Best when you need full control over fill-extrusion paint properties, light direction, and data-driven height expressions.
Extrude 3D buildings on a MapTiler SDK map with a fill-extrusion layer that reads render_height from the building source layer of the vector tiles.
Combines MapLibre's fill-extrusion layers with automatic access to MapTiler building data.
Build maps with AI
Generate code like these examples using mapping library skills in your IDE.