Skip to content

@diginestai/core — Core React SDK

@diginestai/core is the primary entry point for the DigiNest Maps SDK. It wires together MapLibre GL JS, deck.gl, PMTiles, and Zustand into a composable React component and hook API for building indoor and outdoor mapping applications.


Installation

bash
pnpm add @diginestai/core

Requires a fine-grained GitHub PAT with read:packages scope. See the Installation guide for .npmrc setup.


Quick Start

tsx
import { SpatialProvider, SpatialMap } from '@diginestai/core';

export default function App() {
  return (
    <SpatialProvider>
      <SpatialMap
        style="pmtiles://https://tiles.example.com/basemap.pmtiles"
        center={[-122.4, 37.78]}
        zoom={16}
        onFloorChange={(floor) => console.log('active floor:', floor.ordinal)}
      />
    </SpatialProvider>
  );
}

<SpatialProvider>

Mounts the root Zustand store and registers the pmtiles:// MapLibre protocol (module-level singleton — safe to render once at app root).

Props

PropTypeDefaultDescription
childrenReactNodeApp tree.
workerConfigWorkerConfig{}Override Comlink worker URLs for IMDF, navigation, RTLS, and PMTiles workers.
persistKeystring'spatial'IndexedDB key for zustand/middleware/persist state hydration.

<SpatialMap>

The top-level map container. Hosts the MapLibre GL JS instance and exposes an imperative ref handle.

Key Props

PropTypeDefaultDescription
stylestring | StyleSpecificationMapLibre style URL or inline style object. Supports pmtiles:// prefix.
center[number, number][0, 0]Initial longitude/latitude.
zoomnumber14Initial zoom level.
pitchnumber0Initial pitch in degrees.
bearingnumber0Initial bearing in degrees.
onLoad(map: MapLibreMap) => voidFires after MapLibre's load event.
onFloorChange(floor: LevelFeature) => voidFires when the active floor changes.
renderOptionsRenderOptionsControls exploded view, satellite basemap blend, and label visibility.
themeSpatialThemelightThemeTheme applied via CSS custom properties.

Hooks

useMap()

Returns the live MapLibre Map instance and spatial store reference.

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

const { map, store } = useMap();
map.flyTo({ center: [-122.4, 37.78], zoom: 18 });
ReturnTypeDescription
mapMapLibreMap | nullRaw MapLibre GL JS map instance.
storeSpatialStoreZustand store handle.

useFloor()

Subscribes to the active floor state.

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

const { activeFloor, floors, setFloor } = useFloor();
ReturnTypeDescription
activeFloorLevelFeature | nullCurrently displayed floor.
floorsLevelFeature[]All floors in the loaded building.
setFloor(id: string) => voidSwitch the active floor.

useRTLS(options?)

Connects an RTLS adapter and surfaces live position updates.

tsx
import { useRTLS } from '@diginestai/core';
import { SewioAdapter } from '@diginestai/rtls';

const { positions, health } = useRTLS({
  adapter: new SewioAdapter({ url: 'wss://sewio.example.com/realtime' }),
});
OptionTypeDescription
adapterRTLSAdapterAny adapter from @diginestai/rtls.
floorFilterbooleanOnly surface positions matching the active floor (default: true).

useEditor()

Accesses Terra Draw editor state and undo/redo controls (powered by zundo, 50-step cap).

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

const { mode, setMode, undo, redo, features } = useEditor();
ReturnTypeDescription
modeEditorModeActive draw mode ('wall', 'door', 'select', etc.).
setMode(mode: EditorMode) => voidSwitch draw mode.
undo() => voidUndo last edit.
redo() => voidRedo last undone edit.
featuresDrawFeature[]Current feature collection.

Rendering Pipeline

MapLibre GL JS hosts the base layer stack (z 0–990). deck.gl layers interleave via @deck.gl/mapbox MapboxOverlay — one shared WebGL context, no double-buffer.

Z-orderLayer
0Basemap
300Floor fills (IMDF)
700Data layers
800Heatmap
950RTLS trails
980BlueDot
990Selection highlight

Critical rule: Never recreate a MapLibre source or layer on re-render. Updates use setData, setPaintProperty, or setFeatureState. Live sensor updates use setFeatureState (not setData); batched per requestAnimationFrame. Feature state map is capped at ~10k keys (LRU) to avoid MapLibre issue #6633 zoom lag.


State Slices (Zustand)

SliceKey state
buildingSliceActive building, IMDF data, PMTiles archive URL
floorSliceActive floor ordinal, floor list, exploded view offset
cameraSliceViewport center/zoom/pitch, camera mode
dataLayerSliceLayer registry, visibility flags, color scale configs
selectionSliceSelected feature ID, selection highlight state
editorSliceDraw mode, feature collection, zundo temporal state
rtlsSliceAdapter registry, position cache, health map
themeSliceActive SpatialTheme, mode ('light' | 'dark')
wayfindingSliceOrigin/destination, active route, floor transitions

State persists to IndexedDB via zustand/middleware/persist.

Released under commercial licensing.