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

This example shows how to use Deck.gl layers within a MapTiler SDK JS map. The purpose of this demonstration is to exhibit the inclusion of a Deck.gl GeoJSON layer and a Deck.gl arc layer on top of your MapTiler maps. Simply use the code below the map.

In this case, Deck.gl renders within the WebGL context of the underlying base map. This advantageous approach enables occlusion between the Deck.gl layers and the labels and/or 3D features of the base map.

NPM module setup


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

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';

const map = new Map({
  container: 'map', // container id
  style: MapStyle.STREETS, // style URL
  center: [-122.4, 37.79], // starting position [lng, lat]
  zoom: 15, // starting zoom
  pitch: 60
});

map.on('load', () => {
  const firstLabelLayerId = map.getStyle().layers.find(layer => layer.type === 'symbol').id;

  const deckOverlay = new MapboxOverlay({
    interleaved: true,
    layers: [
      new ScatterplotLayer({
        id: 'deckgl-circle',
        data: [
          { position: [-122.402, 37.79], color: [255, 0, 0], radius: 1000 }
        ],
        getPosition: d => d.position,
        getFillColor: d => d.color,
        getRadius: d => d.radius,
        opacity: 0.3,
        beforeId: firstLabelLayerId
      }),
      new ArcLayer({
        id: 'deckgl-arc',
        data: [
          { source: [-122.3998664, 37.7883697], target: [-122.403068, 37.7930503] }
        ],
        getSourcePosition: d => d.source,
        getTargetPosition: d => d.target,
        getSourceColor: [255, 0, 128],
        getTargetColor: [0, 200, 255],
        getWidth: 8
      })
    ]
  });

  map.addControl(deckOverlay);

});

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

Learn more

Check out the Deck.gl documentation Base Maps Renderers to learn about the two types of integration between Deck.gl and a base map renderer.

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 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.

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?