Extrude polygons for 3D indoor mapping

Create a 3D indoor map with the fill-extrude-height paint property.

NPM module setup


npm install --save @maptiler/sdk
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
    container: 'map',
    style: MapStyle.STREETS,
    center: [-87.61694, 41.86625],
    zoom: 15.99,
    pitch: 40,
    bearing: 20,
    antialias: true
});

map.on('load', function() {
    map.addSource('floorplan', {
        // GeoJSON Data source used in vector tiles, documented at
        // https://gist.github.com/ryanbaumann/a7d970386ce59d11c16278b90dde094d
        'type': 'geojson',
        'data': 'https://docs.maptiler.com/sdk-js/assets/indoor-3d-map.geojson'
    });
    map.addLayer({
        'id': 'room-extrusion',
        'type': 'fill-extrusion',
        'source': 'floorplan',
        'paint': {
            // See the Style Specification for details on data expressions.
            // https://docs.maptiler.com/gl-style-specification/expressions/

            // Get the fill-extrusion-color from the source 'color' property.
            'fill-extrusion-color': ['get', 'color'],

            // Get fill-extrusion-height from the source 'height' property.
            'fill-extrusion-height': ['get', 'height'],

            // Get fill-extrusion-base from the source 'base_height' property.
            'fill-extrusion-base': ['get', 'base_height'],

            // Make extrusions slightly opaque for see through indoor walls.
            'fill-extrusion-opacity': 0.5
        }
    });
});
Display buildings in 3D

Display buildings in 3D

Examples

Use extrusions to display height of buildings in 3D.

Add a 3D model with three.js

Add a 3D model with three.js

Examples

Add 3D models using custom layers and three.js.

Was this helpful?