What Is deck.gl? Your First Visualization

Learn how Mapbox and deck.gl divide responsibilities and add your first ScatterplotLayer to a Mapbox map.

🎯 Introduction

By the end of this article, you will be able to use Mapbox for the map and camera, draw a GPU-rendered point layer with deck.gl, and understand the architecture used throughout this course.

🧱 Where deck.gl fits

deck.gl is a GPU visualization framework for geospatial data. It turns large collections of points, lines, polygons, trips, and aggregated results into interactive graphics. It renders through WebGL on the GPU, with layer configuration focused on how data maps to graphics.

In production WebGIS projects, deck.gl typically works alongside a map engine:

Mapbox: map, basemap, camera, map styles, and map events
deck.gl: application data layers, GPU attributes, picking, aggregation, and animation

deck.gl can also create a standalone canvas, but this course uses Mapbox + MapboxOverlay + deck.gl Layer from the first article onward. This keeps every visualization grounded in its geographic context.

🧩 MapboxOverlay: connecting the two systems

MapboxOverlay, provided by @deck.gl/mapbox, integrates deck.gl layers into an existing Mapbox map. Mapbox continues to manage the basemap and camera, while the overlay receives deck.gl layers and keeps them aligned as the map pans, zooms, and rotates.

In the code, map.addControl(overlay) attaches the adapter to the map, while overlay.setProps({ layers }) tells deck.gl which application data layers to draw. Sharing WebGL, controlling layer order, and dividing event handling also require an understanding of interleaved.

📦 Install dependencies

The examples use Node.js 22.9.0, with mapbox-gl@3.14.0, @deck.gl/core@9.4.0, @deck.gl/layers@9.4.0, and @deck.gl/mapbox@9.4.0 as the main packages:

npm install mapbox-gl@3.14.0 @deck.gl/core@9.4.0 @deck.gl/layers@9.4.0 @deck.gl/mapbox@9.4.0

MAPBOX_TOKEN in the code stands for the Mapbox public access token you have already obtained.

⚖️ Mapbox, deck.gl, and Three.js

Mapbox is a map engine responsible for roads, place names, basemap styles, and the camera. deck.gl is a data visualization framework that draws application data as points, lines, polygons, and 3D graphics. They can coexist, but Mapbox layers and deck.gl layers belong to separate layer systems.

Three.js focuses on general-purpose 3D scenes, giving you freedom to arrange models, lights, materials, and animations. For structured geospatial data such as city locations, paths, administrative areas, heatmaps, and trips, deck.gl's data-driven layers are more direct. Consider Three.js when you need a highly customized 3D scene.

🚀 Your first Mapbox + deck.gl layer

The following code includes the essential Mapbox setup. Focus on MapboxOverlay and ScatterplotLayer:

import mapboxgl from 'mapbox-gl';
import { MapboxOverlay } from '@deck.gl/mapbox';
import { ScatterplotLayer } from '@deck.gl/layers';

mapboxgl.accessToken = MAPBOX_TOKEN;

const map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/light-v11',
    center: [116.42, 39.91],
    zoom: 9.5,
});

const overlay = new MapboxOverlay({
    interleaved: true,
    layers: [],
});

map.addControl(overlay);

overlay.setProps({
    layers: [new ScatterplotLayer({
        id: 'stations',
        data: [
            { position: [116.36, 39.88] },
            { position: [116.42, 39.91] },
            { position: [116.48, 39.94] },
        ],
        getPosition: (item) => item.position,
        getRadius: 500,
        getFillColor: [37, 99, 235, 220],
    })],
});

map displays the basemap and controls the camera. overlay connects Mapbox to deck.gl, while ScatterplotLayer handles only the point data and styling. When you pan, zoom, or rotate the map, the deck.gl layer follows the Mapbox camera.

Here is this same architecture running on the page:

The example requires a Mapbox token to load the basemap. If no token is configured, the component displays a configuration message instead of drawing a standalone canvas without a map.

🧾 Summary

  • Mapbox manages the map and camera; deck.gl visualizes application data.
  • MapboxOverlay integrates deck.gl layers into a Mapbox map.
  • ScatterplotLayer draws points using data and accessors.
  • Subsequent examples use MapboxOverlay by default, with Mapbox managing the map view.

❓ Questions and answers

Q1: Is deck.gl just a regular Mapbox layer?

No. deck.gl is an independent GPU visualization framework. MapboxOverlay simply enables it to work with a Mapbox map.

Q2: Why does the example omit initialViewState?

This example uses Mapbox integration, so camera options such as Mapbox's center and zoom manage the center and zoom level.

Q3: When would you use Deck directly?

Use a standalone Deck when you need a visualization canvas independent of a map engine. The WebGIS examples in this course consistently use MapboxOverlay.

🧪 Exercises

  1. Increase the number of points in ScatterplotLayer to five and observe how they appear over the Mapbox basemap.
  2. Change getFillColor to orange and observe that it affects only the deck.gl points, leaving the Mapbox basemap unchanged.

🎉 You now understand the central idea of this course: Mapbox manages the map, and deck.gl manages the data layers.