spatial-monorepo / core/src / Navigation
Class: Navigation
Defined in: packages/core/src/wayfinding/Navigation.ts:365
Stateful Navigation helper (Mappedin Navigation-class API parity) — see module docs above. One instance per map; construct a new Navigation for each SpatialMap/MapLibre instance you render a route on.
Constructors
Constructor
new Navigation(
map):Navigation
Defined in: packages/core/src/wayfinding/Navigation.ts:382
Parameters
map
Map$1
Returns
Navigation
Accessors
activePathIndex
Get Signature
get activePathIndex():
number
Defined in: packages/core/src/wayfinding/Navigation.ts:396
Returns
number
activeRoute
Get Signature
get activeRoute():
NavigationRoute|null
Defined in: packages/core/src/wayfinding/Navigation.ts:387
The currently-active route (index 0 unless setActivePathByIndex was called), or null if nothing is drawn.
Returns
NavigationRoute | null
pathCount
Get Signature
get pathCount():
number
Defined in: packages/core/src/wayfinding/Navigation.ts:392
Number of precomputed paths available (1 + alternates), or 0 if nothing is drawn.
Returns
number
Methods
clear()
clear():
void
Defined in: packages/core/src/wayfinding/Navigation.ts:440
Tear down everything this Navigation instance has drawn on its map — route line, floor-transition symbols, departure/destination markers, and any active highlight. Guarded with getLayer/getSource checks (mirroring WayfindingLayer's teardown) so it is always a safe no-op, including when nothing was ever drawn.
Returns
void
clearHighlight()
clearHighlight():
void
Defined in: packages/core/src/wayfinding/Navigation.ts:498
Remove the current highlight overlay (if any), leaving the base route untouched.
Returns
void
draw()
draw(
route,opts?):void
Defined in: packages/core/src/wayfinding/Navigation.ts:408
Draw route on the map — departure/destination markers, the route line (in the requested style, default flat), and any floor-switch affordances at connection points (via WayfindingLayer's floor-transition symbol layer). Safe to call repeatedly, with or without an intervening clear() (AC1) — any previously-drawn route/markers/highlight are torn down first.
Parameters
route
opts?
Returns
void
highlightPathSection()
highlightPathSection(
fromM,toM):void
Defined in: packages/core/src/wayfinding/Navigation.ts:459
Emphasize the sub-range of the active path between fromM and toM (metres along the path, from its departure end) with a distinct highlight overlay — the base route stays rendered underneath. Calling this again (e.g. to move the highlighted range) updates the existing highlight via setData rather than re-adding the layer.
Parameters
fromM
number
toM
number
Returns
void
onProgress()
onProgress(
listener):Unsubscribe
Defined in: packages/core/src/wayfinding/Navigation.ts:590
Subscribe to progress updates emitted by trackCoordinate. Returns an unsubscribe function.
Parameters
listener
(progress) => void
Returns
Unsubscribe
onRerouteNeeded()
onRerouteNeeded(
listener):Unsubscribe
Defined in: packages/core/src/wayfinding/Navigation.ts:596
Subscribe to reroute-needed events emitted by trackCoordinate's off-route detection. Returns an unsubscribe function.
Parameters
listener
(event) => void
Returns
Unsubscribe
setActivePathByIndex()
setActivePathByIndex(
index):void
Defined in: packages/core/src/wayfinding/Navigation.ts:510
Switch the rendered route to the precomputed alternate at index (0 is the route passed to draw(); 1..n are opts.alternates in order). Updates the route/transition sources via setData only — no source/layer recreation — so there is no redraw flicker (AC4). Any active highlight is cleared, since a sub-range on the previous path may not correspond to the new one. Out-of-range indices are a no-op (logged).
Parameters
index
number
Returns
void
stopTracking()
stopTracking():
void
Defined in: packages/core/src/wayfinding/Navigation.ts:583
Stop the current tracking session (AC4) — subsequent trackCoordinate calls are a no-op, so no further progress/reroute events are emitted, until the next draw(). Does not clear the drawn route/markers; call clear() for that.
Returns
void
trackCoordinate()
trackCoordinate(
position):NavigationProgress|null
Defined in: packages/core/src/wayfinding/Navigation.ts:545
Feed a live position (typically the blue dot's latest fix) for the active path — projects it onto the route geometry to compute walking progress (distanceCoveredM/distanceRemainingM/progressPercent/ currentInstructionIndex) and notifies every onProgress listener with the result (also returned directly for synchronous callers).
Off-route detection: when the projected lateral distance from the path exceeds 5 m continuously for more than 3 s, every onRerouteNeeded listener is notified exactly once (no repeat events while the position stays off-route) — consumers can use this to trigger a fresh getDirections call. The debounce clock resets the moment the position is back within 5 m, so a brief excursion under the 3 s window never fires (AC2/AC3).
A no-op (returns null) when nothing is drawn, or after stopTracking() has been called for the active route (AC4) — call draw() again (a fresh or rerouted path) to re-enable tracking.
Parameters
position
Returns
NavigationProgress | null
