Skip to content

@diginestai/deckgl-bridge — deck.gl Bridge

@diginestai/deckgl-bridge bridges deck.gl layers into MapLibre GL JS via @deck.gl/mapbox MapboxOverlay. Both renderers share a single WebGL context — no double-buffer, no visual seam.


Installation

bash
pnpm add @diginestai/deckgl-bridge

Architecture

  • A MapboxOverlay (with interleaved: true) is added as a MapLibre control on first use.
  • The overlay is cached in a WeakMap keyed by the MapLibre map instance — calling getOrCreateOverlay(map) with the same map reference always returns the same handle (singleton per map).
  • Layer constructors are resolved lazily from @deck.gl/* packages and cached in a module-level Map to avoid repeated dynamic imports.

Quick Start

tsx
import { getOrCreateOverlay, createHeatmapLayerSpec } from '@diginestai/deckgl-bridge';
import { useMap } from '@diginestai/core';

function HeatLayer() {
  const { map } = useMap();

  useEffect(() => {
    if (!map) return;
    const overlay = getOrCreateOverlay(map);
    overlay.addLayer(createHeatmapLayerSpec('my-heat', points));
    return () => overlay.removeLayer('my-heat');
  }, [map]);

  return null;
}

getOrCreateOverlay(map)

Returns (or creates) the DeckGLOverlayHandle for a given MapLibre map instance.

ParameterTypeDescription
mapMapLibreMapLikeMapLibre Map instance (or any object implementing addControl/removeControl).

DeckGLOverlayHandle API

MethodSignatureDescription
addLayer(spec: DeckGLLayerSpec) => Promise<void>Adds a deck.gl layer (lazily imports the constructor).
removeLayer(id: string) => Promise<void>Removes the layer by ID.
updateLayer(id: string, partial: Partial<DeckGLLayerSpec>) => Promise<void>Merges new props into an existing layer.
destroy() => voidRemoves the overlay from the map and clears the registry entry.

Layer Spec Factories

All factories return a DeckGLLayerSpec object ready to pass to overlay.addLayer().

createHeatmapLayerSpec(id, data, opts?)

Creates a deck.gl HeatmapLayer spec.

ParameterTypeDescription
idstringUnique layer ID.
data[lon, lat, weight][]Point array with weight.
opts.radiusPixelsnumberHeatmap radius in pixels (default: 30).
opts.colorRange[r,g,b,a][]Custom 6-stop colour ramp.
opts.intensitynumberGlobal intensity multiplier.

createTripsLayerSpec(id, trips, opts?)

Creates a deck.gl TripsLayer spec for animated path playback.

ParameterTypeDescription
idstringUnique layer ID.
trips{ path: [lon,lat][]; timestamps: number[] }[]Trip path and timestamps.
opts.currentTimenumberPlayhead position (ms).
opts.trailLengthnumberLength of the trail in ms.

createShapeLayerSpec(id, shapes)

Creates a spec for 3D extruded shapes (delegates to @diginestai/3d under the hood).


createAnimatedRoutePathSpec(id, route, opts?)

Creates an animated route path spec backed by AnimatedRoute3D.

ParameterTypeDescription
idstringUnique layer ID.
routeRouteRoute with segments: { floor: string; path: [lon, lat][] }[].
opts.color[r,g,b,a]Path colour (default: blue).
opts.widthMetersnumberPath width in metres.

<AnimatedRoute3D> (via @diginestai/core)

AnimatedRoute3D is a React component that wraps createAnimatedRoutePathSpec in a declarative API. Import it from @diginestai/core:

tsx
import { AnimatedRoute3D } from '@diginestai/core';

<AnimatedRoute3D
  route={myRoute}
  color={[0.1, 0.5, 1.0, 1.0]}
  widthMeters={2}
  animationDurationMs={3000}
  loop
/>

AnimatedRoute3DProps

PropTypeDefaultDescription
routeRouteRoute to animate. Required.
color[r,g,b,a][0.15, 0.55, 1, 1]Path colour.
widthMetersnumber2Path width in metres.
animationDurationMsnumber2000Full loop duration in milliseconds.
loopbooleantrueContinuously animate.

Available Layer Types

The DeckGLLayerSpec.type discriminated union supports:

HeatmapLayer · ScatterplotLayer · TripsLayer · IconLayer · GeoJsonLayer · ColumnLayer · PathLayer · TextLayer · ArcLayer · PolygonLayer · SolidPolygonLayer · HexagonLayer · GridLayer · TileLayer · MVTLayer

Released under commercial licensing.