How to display a MVT layer of buildings in Deck.gl

This Deck.gl example demonstrates how to load a Vector Tiles layer. The specific layer showcased in this example is the building layer, which is sourced from the MapTiler Planet tileset. Simply use the code below the map.

In this scenario, the buildings within the layer are visually represented based on the color specified in the colour field, as well as their respective heights indicated in the render_height field.

Hold down the shift key to rotate the map

NPM module setup


npm install --save @maptiler/sdk deck.gl chroma-js
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
import { MapboxOverlay } from '@deck.gl/mapbox';
import { MVTLayer } from '@deck.gl/layers';
import chroma from 'chroma-js';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';

const map = new Map({
  container: 'map', // container id
  style: MapStyle.BASE, // style URL
  center: [-74.0115, 40.7082], // starting position [lng, lat]
  zoom: 14.5, // starting zoom
  pitch: 60
});

map.on('load', () => {
  const deckOverlay = new MapboxOverlay({
    interleaved: false,
    layers: [
      new MVTLayer({
        data: `https://api.maptiler.com/tiles/buildings/{z}/{x}/{y}.pbf?key=${config.apiKey}`,
        loadOptions: {
          mvt: {
            layers: ['building']
          }
        },
        minZoom: 0,
        maxZoom: 15,
        getLineColor: f => {
          return f.properties.facade_color && chroma.valid(f.properties.facade_color) ? chroma(f.properties.facade_color).rgb() : [140, 170, 180]
        },
        getFillColor: f => {
          return f.properties.facade_color && chroma.valid(f.properties.facade_color) ? chroma(f.properties.facade_color).rgb() : [140, 170, 180]
        },
        getLineWidth: 1,
        lineWidthMinPixels: 1,
        getElevation: f => {
          return f.properties.height ? f.properties.height : 0
        },
        extruded: true,
        wireframe: true
      })
    ]
  });

  map.addControl(deckOverlay);
});

Replace YOUR_MAPTILER_API_KEY_HERE with your own API key. Make sure to secure the key before you publish it.

How to display a GeoJSON in Deck.gl and MapTiler SDK JS

GeoJSON in Deck.gl

Examples

Visualize GeoJSON layers and arc connections in Deck.gl.

How to display a Deck.gl layers in MapTiler SDK JS

Interleaved Deck.gl layer

Examples

Interleave Deck.gl layers with MapTiler SDK JS maps.

How to display an MVT layer of POIs and show a tooltip in Deck.gl

POIs info Deck.gl MVT layer

Examples

Display MVT POI layers with tooltips in Deck.gl.

How to display a 3D terrain layer in Deck.gl

3D Terrain

Examples

Display realistic 3D terrain in Deck.gl using MapTiler.

Was this helpful?