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

This example illustrates the process of showcasing a GeoJSON layer in Deck.gl. In this particular instance, we utilize an arc layer to visually represent the connections between the various features of the GeoJSON layer. Simply implement the provided code beneath the map to achieve this visualization.

Hold down the shift key to rotate the 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 { ArcLayer, GeoJsonLayer } from '@deck.gl/layers';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const AIR_PORTS = 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson';

const map = new Map({
  container: 'map', // container id
  style: MapStyle.STREETS, // style URL
  enter: [10.45, 20.47], // starting position [lng, lat]
  zoom: 0.5, // starting zoom
  pitch: 30
});

map.on('load', () => {
  const deckOverlay = new MapboxOverlay({
    interleaved: false,
    layers: [
      new GeoJsonLayer({
        id: 'airports',
        data: AIR_PORTS,
        // Styles
        filled: true,
        pointRadiusMinPixels: 2,
        pointRadiusScale: 2000,
        getPointRadius: f => 11 - f.properties.scalerank,
        getFillColor: [200, 0, 80, 180],
        // Interactive props
        pickable: true,
        autoHighlight: true,
        onClick: info =>
          // eslint-disable-next-line
          info.object && alert(`${info.object.properties.name} (${info.object.properties.abbrev})`)
      }),
      new ArcLayer({
        id: 'arcs',
        data: AIR_PORTS,
        dataTransform: d => d.features.filter(f => f.properties.scalerank < 4),
        // Styles
        getSourcePosition: f => [-0.4531566, 51.4709959], // London
        getTargetPosition: f => f.geometry.coordinates,
        getSourceColor: [0, 128, 200],
        getTargetColor: [200, 0, 80],
        getWidth: 1
      })
    ]
  });

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

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?