Integrating Mapbox and deck.gl
🎯 Introduction
By the end of this article, you will be able to explain how Mapbox and deck.gl render a map together and choose an integration mode based on layer order and interaction requirements.
🧭 Camera synchronization, layer order, and rendering modes
MapboxOverlay integrates deck.gl layers into Mapbox. Once connected, focus on three questions: how the two layer systems participate in rendering, which system manages camera state, and how map events and graphic events divide responsibilities.
The boundary remains the same: Mapbox manages the map, and deck.gl visualizes application data. Treat their layer systems as separate APIs.
⚡ interleaved and rendering modes
The interleaved: true setting used throughout this course lets deck.gl and Mapbox share the WebGL rendering pipeline, allowing deck.gl layers to participate in the map style's drawing order. Non-interleaved mode draws deck.gl content as an overlay above the Mapbox canvas. This is simpler to understand, but offers less flexibility for mixing layers with the map style.
To share the WebGL rendering pipeline between deck.gl and Mapbox, configure the overlay as follows:
const overlay = new MapboxOverlay({
interleaved: true,
layers,
});
🧭 Camera synchronization and layer order
The Mapbox camera is the single source of camera state:
Mapbox Camera
↓
MapboxOverlay
↓
deck.gl Layer
You do not need to pass viewState to deck.gl manually when panning the map. Use beforeId to control the order of deck.gl layers relative to Mapbox style layers. With Mapbox Standard Style, also consider options such as slot, depending on the style version.
new ScatterplotLayer({
id: 'stations',
data: stations,
beforeId: 'road-label',
getPosition: (item) => item.position,
getRadius: 400,
});
The result is a single map combining the Mapbox basemap, roads, and place names with deck.gl polygons, lines, and points.
A Mapbox map can load a basemap while also displaying deck.gl path and point layers:
🔁 Two layer systems and two event systems
Mapbox layers: use sources, styles, filters, and the map styling system
deck.gl layers: use data, accessors, GPU attributes, and picking
Similarly, map.on('move') is a Mapbox map event, while onHover is a deck.gl layer event. Use both in the same project, but keep track of which system each callback belongs to.
🧾 Summary
MapboxOverlayintegrates deck.gl layers into Mapbox.- This course consistently uses
interleaved: true. - The Mapbox camera drives the map view, and deck.gl follows automatically.
beforeIdand style layer order determine how the two systems' content is stacked.
❓ Questions and answers
Q1: Why no longer maintain a separate deck.gl ViewState?
Mapbox manages the map camera, and the overlay synchronizes camera changes with deck.gl.
Q2: Are Mapbox layers and deck.gl layers interchangeable?
Their use cases overlap, but their underlying capabilities differ. Choose based on data volume, the styling system, animation, and picking requirements.
Q3: When should I use non-interleaved mode?
Consider it when you need a simple overlay or the current Mapbox rendering environment is unsuitable for sharing the WebGL pipeline.
🧪 Exercises
- Add
beforeIdto a deck.gl layer and observe its order relative to Mapbox place labels. - Listen for Mapbox's
zoomendevent and log the current zoom level when zooming ends.
🎉 You now understand the overall rendering architecture of Mapbox + deck.gl.
