Skip to main content

TerrainExtension (Experimental)

This extension is experimental, which means it does not provide the compatibility and stability that one would typically expect from other features. Use with caution and report any issues that you find on GitHub.

The TerrainExtension renders otherwise 2D data along a 3D surface. For example, a GeoJSON of city streets and building footprints can be overlaid on top of a elevation model. It is useful when viewing a mixture of 2D and 3D data sources. The re-positioning of geometries is performed on the GPU.

To use this extension, first define a terrain source with the prop operation: 'terrain' or operation: 'terrain+draw'. A terrain source provides the 3D surface to fit other data on to.

For each layer that should be fitted to the terrain surface, add the TerrainExtension to its extensions prop.

import {GeoJsonLayer} from '';
import {TerrainLayer} from '';
import {_TerrainExtension as TerrainExtension} from '';

const layers = [
new TerrainLayer({
id: 'terrain',
minZoom: 0,
maxZoom: 23,
strategy: 'no-overlap',
elevationDecoder: {
rScaler: 6553.6,
gScaler: 25.6,
bScaler: 0.1,
offset: -10000
elevationData: `{z}/{x}/{y}.png?access_token=${MAPBOX_TOKEN}`,
texture: `{z}/{x}/{y}@2x.png?access_token=${MAPBOX_TOKEN}`,
operation: 'terrain+draw'
new GeoJsonLayer({
getFillColor: [0, 160, 180, 200],
getLineColor: [220, 80, 0],
getLineWidth: 50,
getPointRadius: 150,
extensions: [new TerrainExtension()]


To install the dependencies from NPM:

npm install
# or
npm install
import {_TerrainExtension as TerrainExtension} from '';
new TerrainExtension();

To use pre-bundled scripts:

<script src="^9.0.0/dist.min.js"></script>
<!-- or -->
<script src="^9.0.0/dist.min.js"></script>
<script src="^9.0.0/dist.min.js"></script>
new deck._TerrainExtension();


new TerrainExtension();

Layer Properties

When added to a layer via the extensions prop, the TerrainExtension adds the following properties to the layer:

terrainDrawMode ('offset' | 'drape')

How data should be fitted to the terrain surface. If not specified, will be automatically determined from the layer type.

  • offset: each object is translated vertically by the elevation at its anchor (usually defined by an accessor called getPosition, e.g. icon, scatterplot). This is the desired behavior for layers that render 3D objects.
  • drape: each object is overlaid as a texture over the terrain surface. All altitude and extrusion in the layer will be ignored.

terrainDrawMode: offset

terrainDrawMode: drape