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

This example shows how to create a 3D map in Deck.gl. By utilizing MapTiler’s RGB terrain, you can enhance your maps by incorporating a realistic 3D terrain layer. Implementing the code provided below the map will allow you to achieve this effect.

Hold down the shift key to rotate the map

NPM module setup


npm install --save deck.gl
import { DeckGL } from '@deck.gl/core';
import { TerrainLayer } from '@deck.gl/geo-layers';

const key = 'YOUR_MAPTILER_API_KEY_HERE';

const TERRAIN_IMAGE = `https://api.maptiler.com/tiles/terrain-rgb-v2/{z}/{x}/{y}.webp?key=${key}`;
const SURFACE_IMAGE = `https://api.maptiler.com/maps/satellite-v4/{z}/{x}/{y}.jpg?key=${key}`;

const ELEVATION_DECODER = {
  rScaler: 6553.6,
  gScaler: 25.6,
  bScaler: 0.1,
  offset: -10000
};

// Create deck.gl map
const deckgl = new DeckGL({
  parent: document.getElementById("map"),
  initialViewState: {
    latitude: 46.20,
    longitude: -122.20,
    zoom: 11.5,
    bearing: 140,
    pitch: 60,
    maxPitch: 89
  },
  controller: true,
  layers: [
    new TerrainLayer({
      id: 'terrain',
      minZoom: 0,
      maxZoom: 12,
      elevationDecoder: ELEVATION_DECODER,
      elevationData: TERRAIN_IMAGE,
      texture: SURFACE_IMAGE,
      wireframe: false,
      color: [255, 255, 255]
    }),
  ],
});

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 a MVT layer of buildings in Deck.gl

Buildings Deck.gl MVT layer

Examples

Render extruded building layers in Deck.gl using Vector Tiles.

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.

Was this helpful?