What is @deck.gl/mapbox?
@deck.gl/mapbox is a package that integrates Deck.gl visualizations with Mapbox GL maps. It allows you to create complex and performant visualizations on top of Mapbox maps, leveraging the power of Deck.gl's GPU-accelerated rendering.
Integrate Deck.gl Layers with Mapbox
This feature allows you to add Deck.gl layers to a Mapbox map. The code sample demonstrates how to create a Mapbox map and add a Deck.gl ScatterplotLayer to it.
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
center: [-74.5, 40],
zoom: 9
});
const deckLayer = new deck.MapboxLayer({
id: 'my-deck-layer',
type: deck.ScatterplotLayer,
data: [{position: [-74.5, 40], size: 100}],
getPosition: d => d.position,
getRadius: d => d.size,
getColor: [255, 0, 0]
});
map.on('load', () => {
map.addLayer(deckLayer);
});
Synchronize Deck.gl Layers with Mapbox Camera
This feature ensures that Deck.gl layers stay in sync with the Mapbox camera. The code sample shows how to update the Deck.gl layer's view state whenever the Mapbox map is moved.
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
center: [-74.5, 40],
zoom: 9
});
const deckLayer = new deck.MapboxLayer({
id: 'my-deck-layer',
type: deck.ScatterplotLayer,
data: [{position: [-74.5, 40], size: 100}],
getPosition: d => d.position,
getRadius: d => d.size,
getColor: [255, 0, 0]
});
map.on('load', () => {
map.addLayer(deckLayer);
});
map.on('move', () => {
deckLayer.setProps({
viewState: {
longitude: map.getCenter().lng,
latitude: map.getCenter().lat,
zoom: map.getZoom(),
bearing: map.getBearing(),
pitch: map.getPitch()
}
});
});