@expofp/wayfinding 0.0.0-experimental.2d6c681
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/dist/core/createWayfindingEngine.d.ts +16 -0
- package/dist/core/createWayfindingEngine.js +87 -0
- package/dist/core/geometry/pointInPolygon.d.ts +17 -0
- package/dist/core/geometry/pointInPolygon.js +50 -0
- package/dist/core/geometry/projectPointOnSegment.d.ts +27 -0
- package/dist/core/geometry/projectPointOnSegment.js +21 -0
- package/dist/core/graph/buildGraph.d.ts +3 -0
- package/dist/core/graph/buildGraph.js +7 -0
- package/dist/core/graph/buildNGraph.d.ts +13 -0
- package/dist/core/graph/buildNGraph.js +24 -0
- package/dist/core/graph/constants.d.ts +20 -0
- package/dist/core/graph/constants.js +19 -0
- package/dist/core/graph/findShortestPath.d.ts +23 -0
- package/dist/core/graph/findShortestPath.js +65 -0
- package/dist/core/graph/graphCache.d.ts +7 -0
- package/dist/core/graph/graphCache.js +23 -0
- package/dist/core/graph/graphHelpers.d.ts +8 -0
- package/dist/core/graph/graphHelpers.js +63 -0
- package/dist/core/graph/linkCost.d.ts +13 -0
- package/dist/core/graph/linkCost.js +24 -0
- package/dist/core/graph/pathfinder/aStarPathFinder.d.ts +3 -0
- package/dist/core/graph/pathfinder/aStarPathFinder.js +64 -0
- package/dist/core/graph/pathfinder/parseNodeId.d.ts +10 -0
- package/dist/core/graph/pathfinder/parseNodeId.js +20 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.js +12 -0
- package/dist/core/position/distanceToRoute.d.ts +3 -0
- package/dist/core/position/distanceToRoute.js +29 -0
- package/dist/core/position/gpsThreshold.d.ts +32 -0
- package/dist/core/position/gpsThreshold.js +48 -0
- package/dist/core/position/rerouteController.d.ts +13 -0
- package/dist/core/position/rerouteController.js +22 -0
- package/dist/core/position/snapToRoute.d.ts +9 -0
- package/dist/core/position/snapToRoute.js +50 -0
- package/dist/core/position/splitRouteByPoint.d.ts +6 -0
- package/dist/core/position/splitRouteByPoint.js +56 -0
- package/dist/core/rendering/computeTrailPoints.d.ts +12 -0
- package/dist/core/rendering/computeTrailPoints.js +35 -0
- package/dist/core/rendering/computeTransitionPoints.d.ts +35 -0
- package/dist/core/rendering/computeTransitionPoints.js +112 -0
- package/dist/core/rendering/getVisibleRouteLines.d.ts +10 -0
- package/dist/core/rendering/getVisibleRouteLines.js +18 -0
- package/dist/core/rendering/routeGeometry.d.ts +9 -0
- package/dist/core/rendering/routeGeometry.js +10 -0
- package/dist/core/routing/buildMultiPointRoute.d.ts +13 -0
- package/dist/core/routing/buildMultiPointRoute.js +36 -0
- package/dist/core/routing/buildRoute.d.ts +12 -0
- package/dist/core/routing/buildRoute.js +19 -0
- package/dist/core/routing/getRouteLength.d.ts +3 -0
- package/dist/core/routing/getRouteLength.js +4 -0
- package/dist/core/routing/graphPointResolvers.d.ts +9 -0
- package/dist/core/routing/graphPointResolvers.js +13 -0
- package/dist/core/routing/optimizeWaypointOrder.d.ts +14 -0
- package/dist/core/routing/optimizeWaypointOrder.js +88 -0
- package/dist/core/routing/resolveWaypointCandidates.d.ts +23 -0
- package/dist/core/routing/resolveWaypointCandidates.js +49 -0
- package/dist/core/routing/routeResult.d.ts +4 -0
- package/dist/core/routing/routeResult.js +2 -0
- package/dist/core/types.d.ts +102 -0
- package/dist/core/types.js +1 -0
- package/dist/createWayfinding.d.ts +81 -0
- package/dist/createWayfinding.js +46 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +16 -0
- package/dist/renderer/createWayfindingRenderer.d.ts +8 -0
- package/dist/renderer/createWayfindingRenderer.js +45 -0
- package/dist/renderer/iconManager.d.ts +58 -0
- package/dist/renderer/iconManager.js +222 -0
- package/dist/renderer/index.d.ts +5 -0
- package/dist/renderer/index.js +2 -0
- package/dist/renderer/layerManager.d.ts +36 -0
- package/dist/renderer/layerManager.js +31 -0
- package/dist/renderer/layers.d.ts +54 -0
- package/dist/renderer/layers.js +66 -0
- package/dist/renderer/lineAnimation.d.ts +25 -0
- package/dist/renderer/lineAnimation.js +196 -0
- package/dist/renderer/routeLineManager.d.ts +45 -0
- package/dist/renderer/routeLineManager.js +153 -0
- package/dist/renderer/trailManager.d.ts +29 -0
- package/dist/renderer/trailManager.js +183 -0
- package/dist/renderer/types.d.ts +163 -0
- package/dist/renderer/types.js +1 -0
- package/dist/runtime/createWayfindingRuntime.d.ts +3 -0
- package/dist/runtime/createWayfindingRuntime.js +237 -0
- package/dist/runtime/endpointView.d.ts +19 -0
- package/dist/runtime/endpointView.js +44 -0
- package/dist/runtime/getRouteLines.d.ts +19 -0
- package/dist/runtime/getRouteLines.js +16 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/positionTrailView.d.ts +51 -0
- package/dist/runtime/positionTrailView.js +35 -0
- package/dist/runtime/positionView.d.ts +22 -0
- package/dist/runtime/positionView.js +34 -0
- package/dist/runtime/routeLinesView.d.ts +16 -0
- package/dist/runtime/routeLinesView.js +10 -0
- package/dist/runtime/routeRenderData.d.ts +31 -0
- package/dist/runtime/routeRenderData.js +44 -0
- package/dist/runtime/routeUpdate.d.ts +17 -0
- package/dist/runtime/routeUpdate.js +17 -0
- package/dist/runtime/snapPositionToRoute.d.ts +10 -0
- package/dist/runtime/snapPositionToRoute.js +36 -0
- package/dist/runtime/trailView.d.ts +19 -0
- package/dist/runtime/trailView.js +43 -0
- package/dist/runtime/transitionView.d.ts +16 -0
- package/dist/runtime/transitionView.js +51 -0
- package/dist/runtime/types.d.ts +81 -0
- package/dist/runtime/types.js +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { Point2Like } from '@expofp/geometry';
|
|
2
|
+
import type { ImageDef, RenderableDef } from '@expofp/renderer';
|
|
3
|
+
/**
|
|
4
|
+
* What the wayfinding renderer needs from whatever is drawing the scene — the rules only the host
|
|
5
|
+
* can answer for. The defs themselves are plain objects this package builds where it uses them.
|
|
6
|
+
*/
|
|
7
|
+
export interface RendererPort {
|
|
8
|
+
/**
|
|
9
|
+
* Declares the host's camera-roll rule on a def that has to stay readable, for
|
|
10
|
+
* {@link IconConfig.cardinalSnap}. The rule is the host's because the plan's own labels turn by
|
|
11
|
+
* it, and one plan turns one way.
|
|
12
|
+
* @param def - The def to keep upright.
|
|
13
|
+
*/
|
|
14
|
+
attachCardinalSnap(def: ImageDef): void;
|
|
15
|
+
/**
|
|
16
|
+
* Commits changed defs.
|
|
17
|
+
*
|
|
18
|
+
* Injected rather than imported: `@expofp/renderer` is a type-only peer here, so the concrete
|
|
19
|
+
* `update` comes from the host.
|
|
20
|
+
*/
|
|
21
|
+
update(...defs: RenderableDef[]): void;
|
|
22
|
+
}
|
|
23
|
+
export interface RouteColors {
|
|
24
|
+
readonly passed: string;
|
|
25
|
+
readonly remaining: string;
|
|
26
|
+
readonly active: string;
|
|
27
|
+
}
|
|
28
|
+
/** What a dot trail draws: one dot image, and the size it is drawn at. */
|
|
29
|
+
export interface TrailOptions {
|
|
30
|
+
/** The dot image. Must stay the same canvas for the life of the trail. */
|
|
31
|
+
readonly canvas: HTMLCanvasElement;
|
|
32
|
+
/**
|
|
33
|
+
* The dot's width in CSS pixels, not its canvas's backing width. Left out, it is read from the
|
|
34
|
+
* canvas's `style.width`; a canvas with neither makes `setTrail` throw.
|
|
35
|
+
*/
|
|
36
|
+
readonly width?: number;
|
|
37
|
+
/** The dot's height in CSS pixels; see {@link width}. */
|
|
38
|
+
readonly height?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface IconConfig {
|
|
41
|
+
readonly canvas: HTMLCanvasElement;
|
|
42
|
+
/**
|
|
43
|
+
* The width the icon is drawn at, in CSS pixels. Not the canvas's `width`: that is its backing
|
|
44
|
+
* store, in the device pixels it was rasterized at, which says how crisp the icon is and nothing
|
|
45
|
+
* about how big.
|
|
46
|
+
*
|
|
47
|
+
* Left out, it is read from the canvas's own `style.width`, which every canvas the SDK creates
|
|
48
|
+
* records. A canvas with neither makes `setIcon` throw.
|
|
49
|
+
*
|
|
50
|
+
* Read when the icon is created or its canvas changes: a later `setIcon` with the same canvas and
|
|
51
|
+
* a different width is ignored.
|
|
52
|
+
*/
|
|
53
|
+
readonly width?: number;
|
|
54
|
+
/** The height the icon is drawn at, in CSS pixels; see {@link width}. */
|
|
55
|
+
readonly height?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Draw the icon on the level above the other icons rather than among them — the live position,
|
|
58
|
+
* which an endpoint pin must never cover. Two icon layers exist because the draw order inside one
|
|
59
|
+
* is the slot a def was given, which no caller can set.
|
|
60
|
+
*
|
|
61
|
+
* Fixed at first setIcon for an icon key: a later call that changes it throws, since moving a def
|
|
62
|
+
* between layers would mean removing it from one and adding it to another.
|
|
63
|
+
*/
|
|
64
|
+
readonly onTop?: boolean;
|
|
65
|
+
readonly x: number;
|
|
66
|
+
readonly y: number;
|
|
67
|
+
/** Rotation in radians. */
|
|
68
|
+
readonly rotation?: number;
|
|
69
|
+
readonly hidden?: boolean;
|
|
70
|
+
readonly dimmed?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Anchor point [0..1, 0..1]. Set at first setIcon for an icon key;
|
|
73
|
+
* ignored on subsequent updates (origin is fixed in ImageDef at creation).
|
|
74
|
+
*/
|
|
75
|
+
readonly origin?: [number, number];
|
|
76
|
+
/**
|
|
77
|
+
* Keeps the icon readable as the camera rolls; the host attaches the rule.
|
|
78
|
+
* The turn is relative — the icon holds its starting heading plus whole quarters — so do NOT
|
|
79
|
+
* enable it where `rotation` carries meaning (position arrow, kiosk heading).
|
|
80
|
+
*
|
|
81
|
+
* Set at first setIcon for an icon key; ignored on subsequent updates.
|
|
82
|
+
*/
|
|
83
|
+
readonly cardinalSnap?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Overrides {@link WayfindingRendererConfig.screenSpaceIcons} for this icon alone.
|
|
86
|
+
*
|
|
87
|
+
* Pass `false` where {@link rotation} carries a plan bearing, such as the position arrow's device
|
|
88
|
+
* heading or a kiosk's facing. A screen-space def spins about the screen's normal rather than the
|
|
89
|
+
* plan's, so such an icon would point at a fixed screen direction instead of at the bearing it
|
|
90
|
+
* was given. Leave it unset for an icon whose rotation means nothing, which is most of them.
|
|
91
|
+
*
|
|
92
|
+
* Set at first setIcon for an icon key, as {@link origin} and {@link cardinalSnap} are. A later
|
|
93
|
+
* call that changes it is ignored unless the canvas changes too, which rebuilds the def.
|
|
94
|
+
*/
|
|
95
|
+
readonly screenSpace?: boolean;
|
|
96
|
+
readonly onClick?: () => void;
|
|
97
|
+
}
|
|
98
|
+
export interface WayfindingRendererConfig {
|
|
99
|
+
/** Optional color overrides; defaults applied if omitted. */
|
|
100
|
+
readonly colors?: Partial<RouteColors>;
|
|
101
|
+
/**
|
|
102
|
+
* Draws every icon facing the camera, through `ImageDef.screenSpace`.
|
|
103
|
+
*
|
|
104
|
+
* Set it when the plan renders in 3D. An icon keeps its plan anchor and the on-screen size
|
|
105
|
+
* `onScale` gives it, and stands up to face the viewer instead of lying on the floor.
|
|
106
|
+
*
|
|
107
|
+
* This takes {@link IconConfig.cardinalSnap} out of use, because billboarding is already what
|
|
108
|
+
* that rule was for. It also changes what {@link IconConfig.rotation} turns about, from the
|
|
109
|
+
* plan's normal to the screen's, so an icon whose rotation carries a plan bearing opts out
|
|
110
|
+
* through {@link IconConfig.screenSpace}.
|
|
111
|
+
*/
|
|
112
|
+
readonly screenSpaceIcons?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* WayfindingRenderer — generic ImageDef/LineDef renderer for wayfinding visuals.
|
|
116
|
+
*
|
|
117
|
+
* Mutators (`setIcon`/`clearIcons`/`setTrail`/`setRouteLines`/`clearRoute`) only
|
|
118
|
+
* mutate scene state; call `flush()` to commit a batch. The route animation tick
|
|
119
|
+
* updates the renderer directly, outside any batch.
|
|
120
|
+
*/
|
|
121
|
+
export interface WayfindingRenderer {
|
|
122
|
+
/**
|
|
123
|
+
* Place or update an icon by `(name, key)`. The first call creates it, later calls mutate it in
|
|
124
|
+
* place, and `config: null` hides it. `config.onTop` must stay stable for a `(name, key)`.
|
|
125
|
+
* Buffered — `flush()` to commit.
|
|
126
|
+
*/
|
|
127
|
+
setIcon(name: string, config: IconConfig | null, key?: string | number): void;
|
|
128
|
+
/** Hide every icon sharing one of `names` (kept alive for reuse). Buffered. */
|
|
129
|
+
clearIcons(names: string | readonly string[]): void;
|
|
130
|
+
/**
|
|
131
|
+
* Place or update a named dot trail between two points; `from/to = null`
|
|
132
|
+
* clears it. `options` required when non-null; `canvas` must stay stable.
|
|
133
|
+
* Buffered — `flush()` to commit.
|
|
134
|
+
*/
|
|
135
|
+
setTrail(name: string, from: Point2Like | null, to: Point2Like | null, options?: TrailOptions): void;
|
|
136
|
+
/**
|
|
137
|
+
* Replace static route lines (passed + remaining) and (re)start the remaining
|
|
138
|
+
* animation. Buffered — `flush()` to commit.
|
|
139
|
+
*/
|
|
140
|
+
setRouteLines(passed: readonly {
|
|
141
|
+
readonly p0: Point2Like;
|
|
142
|
+
readonly p1: Point2Like;
|
|
143
|
+
}[], remaining: readonly {
|
|
144
|
+
readonly p0: Point2Like;
|
|
145
|
+
readonly p1: Point2Like;
|
|
146
|
+
}[], options?: {
|
|
147
|
+
readonly resetAnimation?: boolean;
|
|
148
|
+
}): void;
|
|
149
|
+
/**
|
|
150
|
+
* Fires the def's `onClick`; reports whether it was a clickable icon, so a caller can stop the
|
|
151
|
+
* click going any further.
|
|
152
|
+
*/
|
|
153
|
+
handleClick(def: RenderableDef): boolean;
|
|
154
|
+
/** Whether a def is a clickable icon, which is what a pointer cursor hangs off. */
|
|
155
|
+
handleHover(def: RenderableDef): boolean;
|
|
156
|
+
/** Clear route lines, drop trails, hide icons. Buffered — `flush()` to commit. */
|
|
157
|
+
clearRoute(): void;
|
|
158
|
+
/** Commit buffered mutations to the renderer (via the injected `update`). */
|
|
159
|
+
flush(): void;
|
|
160
|
+
/** Full teardown: empties the host's layers, commits that, and clears the managers. */
|
|
161
|
+
destroy(): void;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { WayfindingRuntime, WayfindingRuntimeConfig } from './types.js';
|
|
2
|
+
export declare function createWayfindingRuntime({ engine, renderer, iconProvider, floorContext, snapThreshold, rerouteThreshold, onTransitionClick, onRouteUpdate, onRouteDistance, }: WayfindingRuntimeConfig): WayfindingRuntime;
|
|
3
|
+
//# sourceMappingURL=createWayfindingRuntime.d.ts.map
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Box } from '@expofp/geometry';
|
|
2
|
+
import { createRerouteController, getRouteLength, } from '../core/index.js';
|
|
3
|
+
import { createEndpointView } from './endpointView.js';
|
|
4
|
+
import { getRouteLines } from './getRouteLines.js';
|
|
5
|
+
import { createPositionTrailView } from './positionTrailView.js';
|
|
6
|
+
import { CURRENT_POSITION_POINT_ID } from './positionView.js';
|
|
7
|
+
import { createRouteLinesView } from './routeLinesView.js';
|
|
8
|
+
import { computeRouteRenderData } from './routeRenderData.js';
|
|
9
|
+
import { computeRouteUpdate } from './routeUpdate.js';
|
|
10
|
+
import { snapPositionToRoute } from './snapPositionToRoute.js';
|
|
11
|
+
import { createTrailView } from './trailView.js';
|
|
12
|
+
import { createTransitionView } from './transitionView.js';
|
|
13
|
+
const linesToPoints = (lines) => lines.flatMap((line) => [line.p0, line.p1]);
|
|
14
|
+
export function createWayfindingRuntime({ engine, renderer, iconProvider, floorContext, snapThreshold, rerouteThreshold, onTransitionClick, onRouteUpdate, onRouteDistance, }) {
|
|
15
|
+
const rerouteController = createRerouteController(rerouteThreshold);
|
|
16
|
+
const endpoints = createEndpointView({ renderer, iconProvider, floorContext });
|
|
17
|
+
const transitions = createTransitionView({
|
|
18
|
+
renderer,
|
|
19
|
+
iconProvider,
|
|
20
|
+
floorContext,
|
|
21
|
+
onTransitionClick,
|
|
22
|
+
});
|
|
23
|
+
const trails = createTrailView({ renderer, iconProvider, floorContext });
|
|
24
|
+
const positionTrails = createPositionTrailView({
|
|
25
|
+
renderer,
|
|
26
|
+
iconProvider,
|
|
27
|
+
floorContext,
|
|
28
|
+
trails,
|
|
29
|
+
snapThreshold,
|
|
30
|
+
});
|
|
31
|
+
const routeLinesView = createRouteLinesView({ renderer });
|
|
32
|
+
let routeLines = [];
|
|
33
|
+
let currentFrom = null;
|
|
34
|
+
let currentTo = null;
|
|
35
|
+
let currentPosition = null;
|
|
36
|
+
let lastVisibleDistance = 0;
|
|
37
|
+
// Sticky-snap: flips to true the first time a CP for the current route snaps. Suppresses the
|
|
38
|
+
// user-location off-graph trail on later drifts back into the snap-gap zone. Reset on setRoute.
|
|
39
|
+
let hasSnappedCurrentRoute = false;
|
|
40
|
+
// Live snap state of the latest tick (not sticky) — drives the greyed-out source variant.
|
|
41
|
+
let snappedToRoute = false;
|
|
42
|
+
function getActiveFloors() {
|
|
43
|
+
if (floorContext.showAllFloors())
|
|
44
|
+
return null;
|
|
45
|
+
return floorContext.getActiveFloors();
|
|
46
|
+
}
|
|
47
|
+
function getVisibleLines() {
|
|
48
|
+
const floors = getActiveFloors();
|
|
49
|
+
if (floors === null)
|
|
50
|
+
return routeLines.filter((line) => !line.virtual);
|
|
51
|
+
return routeLines.filter((line) => floors.includes(line.p0.layer) && !line.virtual);
|
|
52
|
+
}
|
|
53
|
+
// Non-virtual lines across all floors — the same set emitted via `onRouteUpdate`
|
|
54
|
+
// (see `computeRouteUpdate`), so reroute drift is measured against the full route.
|
|
55
|
+
function shouldReroute(position) {
|
|
56
|
+
return rerouteController.shouldReroute(position, routeLines.filter((line) => !line.virtual));
|
|
57
|
+
}
|
|
58
|
+
function getRouteSnapshot() {
|
|
59
|
+
if (!currentFrom || !currentTo)
|
|
60
|
+
return null;
|
|
61
|
+
const visibleLines = getVisibleLines();
|
|
62
|
+
if (!visibleLines.length)
|
|
63
|
+
return null;
|
|
64
|
+
return {
|
|
65
|
+
from: currentFrom,
|
|
66
|
+
to: currentTo,
|
|
67
|
+
routePoints: linesToPoints(visibleLines),
|
|
68
|
+
visibleLines,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function renderVisibleRoute(snap = null, preserveProgress = false) {
|
|
72
|
+
if (!currentFrom || !currentTo)
|
|
73
|
+
return;
|
|
74
|
+
const data = computeRouteRenderData({
|
|
75
|
+
routeLines,
|
|
76
|
+
activeFloors: getActiveFloors(),
|
|
77
|
+
snap,
|
|
78
|
+
});
|
|
79
|
+
routeLinesView.draw(data, preserveProgress);
|
|
80
|
+
lastVisibleDistance = data.distance;
|
|
81
|
+
}
|
|
82
|
+
function syncTrail(snap) {
|
|
83
|
+
const route = getRouteSnapshot();
|
|
84
|
+
if (!route) {
|
|
85
|
+
positionTrails.setTrail(null, null);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// CP and kiosk are mutually exclusive in practice. Pick FROM first; fall through to TO.
|
|
89
|
+
// Sticky-snap suppression only applies to live-CP FROM — kiosk anchors are static.
|
|
90
|
+
const livePosition = currentPosition && snap && !snap.snapped ? currentPosition : null;
|
|
91
|
+
const pickAnchor = (endpoint) => {
|
|
92
|
+
if (endpoint.bounds?.length)
|
|
93
|
+
return null;
|
|
94
|
+
if (endpoint.id === CURRENT_POSITION_POINT_ID)
|
|
95
|
+
return livePosition;
|
|
96
|
+
return endpoint;
|
|
97
|
+
};
|
|
98
|
+
// `hasSnappedCurrentRoute` only flips for a live-CP FROM (booth/kiosk origins never snap),
|
|
99
|
+
// so it already implies a CP origin — no need to re-check the endpoint id here.
|
|
100
|
+
const fromAnchor = hasSnappedCurrentRoute ? null : pickAnchor(route.from);
|
|
101
|
+
// The trail tip is the route's graph endpoint on the same side as its
|
|
102
|
+
// off-graph anchor: first point for FROM, last point for TO.
|
|
103
|
+
if (fromAnchor) {
|
|
104
|
+
positionTrails.setTrail(route.routePoints[0], fromAnchor);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const toAnchor = pickAnchor(route.to);
|
|
108
|
+
positionTrails.setTrail(toAnchor ? route.routePoints[route.routePoints.length - 1] : null, toAnchor);
|
|
109
|
+
}
|
|
110
|
+
function syncRouteVisuals() {
|
|
111
|
+
if (!currentFrom || !currentTo)
|
|
112
|
+
return;
|
|
113
|
+
const route = getRouteSnapshot();
|
|
114
|
+
if (!route) {
|
|
115
|
+
endpoints.hide();
|
|
116
|
+
transitions.clear();
|
|
117
|
+
positionTrails.clearTrail();
|
|
118
|
+
renderVisibleRoute();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
endpoints.place(currentFrom, currentTo, route.routePoints, snappedToRoute);
|
|
122
|
+
transitions.place(routeLines);
|
|
123
|
+
renderVisibleRoute();
|
|
124
|
+
syncTrail(null);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Re-applies source/destination icons only — used when the CP appears/disappears or snaps onto
|
|
128
|
+
* the route, since the source icon's visibility (CP vs kiosk) and grey variant depend on both.
|
|
129
|
+
*/
|
|
130
|
+
function syncEndpoints() {
|
|
131
|
+
if (!currentFrom || !currentTo)
|
|
132
|
+
return;
|
|
133
|
+
const route = getRouteSnapshot();
|
|
134
|
+
if (route)
|
|
135
|
+
endpoints.place(currentFrom, currentTo, route.routePoints, snappedToRoute);
|
|
136
|
+
}
|
|
137
|
+
function snapPosition() {
|
|
138
|
+
snappedToRoute = false;
|
|
139
|
+
if (!currentPosition || !currentFrom || !currentTo)
|
|
140
|
+
return null;
|
|
141
|
+
const nonVirtual = routeLines.filter((line) => !line.virtual);
|
|
142
|
+
if (!nonVirtual.length)
|
|
143
|
+
return null;
|
|
144
|
+
const route = getRouteSnapshot();
|
|
145
|
+
const result = route
|
|
146
|
+
? positionTrails.applyToRoute(currentPosition, route, nonVirtual)
|
|
147
|
+
: // Selected floor doesn't pass through the route — view has nothing
|
|
148
|
+
// to draw, but distance must still update. Snap against the full
|
|
149
|
+
// non-virtual route directly.
|
|
150
|
+
snapPositionToRoute(currentPosition, nonVirtual, currentFrom, currentTo, snapThreshold);
|
|
151
|
+
if (result.snapped)
|
|
152
|
+
hasSnappedCurrentRoute = true;
|
|
153
|
+
snappedToRoute = result.snapped;
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
function emitRouteUpdate() {
|
|
157
|
+
const route = computeRouteUpdate(routeLines, getVisibleLines());
|
|
158
|
+
onRouteUpdate(route.lines, route.bounds);
|
|
159
|
+
return route;
|
|
160
|
+
}
|
|
161
|
+
function setRoute({ from, to, waypoints, accessible }) {
|
|
162
|
+
const newRouteLines = getRouteLines({ engine, from, to, waypoints, accessible });
|
|
163
|
+
if (!newRouteLines.length) {
|
|
164
|
+
clearRoute();
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
hasSnappedCurrentRoute = false;
|
|
168
|
+
currentFrom = from;
|
|
169
|
+
currentTo = to;
|
|
170
|
+
routeLines = newRouteLines;
|
|
171
|
+
syncRouteVisuals();
|
|
172
|
+
const { lines } = emitRouteUpdate();
|
|
173
|
+
const snap = snapPosition();
|
|
174
|
+
syncEndpoints(); // snapPosition may have flipped the snap state — refresh the source variant
|
|
175
|
+
syncTrail(snap);
|
|
176
|
+
if (snap)
|
|
177
|
+
renderVisibleRoute(snap, true);
|
|
178
|
+
onRouteDistance(snap ? lastVisibleDistance : getRouteLength(lines));
|
|
179
|
+
renderer.flush();
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
function onPositionChanged(position) {
|
|
183
|
+
const hadPosition = currentPosition !== null;
|
|
184
|
+
currentPosition = position;
|
|
185
|
+
if (!position) {
|
|
186
|
+
snappedToRoute = false; // no CP → the source reverts from greyed to full-colour
|
|
187
|
+
positionTrails.hideIcon();
|
|
188
|
+
syncTrail(null);
|
|
189
|
+
if (hadPosition)
|
|
190
|
+
syncEndpoints();
|
|
191
|
+
renderVisibleRoute();
|
|
192
|
+
onRouteDistance(lastVisibleDistance);
|
|
193
|
+
renderer.flush();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
positionTrails.placeIcon(position);
|
|
197
|
+
const snap = snapPosition();
|
|
198
|
+
syncEndpoints(); // CP presence / snap state may have changed — refresh source visibility + variant
|
|
199
|
+
syncTrail(snap);
|
|
200
|
+
if (snap)
|
|
201
|
+
renderVisibleRoute(snap, true);
|
|
202
|
+
onRouteDistance(lastVisibleDistance);
|
|
203
|
+
renderer.flush();
|
|
204
|
+
}
|
|
205
|
+
function onFloorChanged() {
|
|
206
|
+
syncRouteVisuals();
|
|
207
|
+
const snap = snapPosition();
|
|
208
|
+
syncEndpoints(); // snap state may differ on the new floor — refresh the source variant
|
|
209
|
+
syncTrail(snap);
|
|
210
|
+
if (snap)
|
|
211
|
+
renderVisibleRoute(snap, true);
|
|
212
|
+
if (routeLines.length)
|
|
213
|
+
emitRouteUpdate();
|
|
214
|
+
onRouteDistance(lastVisibleDistance);
|
|
215
|
+
renderer.flush();
|
|
216
|
+
}
|
|
217
|
+
function clearRoute() {
|
|
218
|
+
hasSnappedCurrentRoute = false;
|
|
219
|
+
routeLines = [];
|
|
220
|
+
currentFrom = null;
|
|
221
|
+
currentTo = null;
|
|
222
|
+
lastVisibleDistance = 0;
|
|
223
|
+
endpoints.hide();
|
|
224
|
+
transitions.clear();
|
|
225
|
+
positionTrails.clearTrail();
|
|
226
|
+
routeLinesView.clear();
|
|
227
|
+
onRouteUpdate([], new Box());
|
|
228
|
+
onRouteDistance(0);
|
|
229
|
+
renderer.flush();
|
|
230
|
+
}
|
|
231
|
+
function destroy() {
|
|
232
|
+
clearRoute();
|
|
233
|
+
currentPosition = null;
|
|
234
|
+
renderer.destroy();
|
|
235
|
+
}
|
|
236
|
+
return { setRoute, onPositionChanged, onFloorChanged, shouldReroute, clearRoute, destroy };
|
|
237
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RouteEndpoint, type RoutePoint } from '../core/index.js';
|
|
2
|
+
import { type WayfindingRenderer } from '../renderer/index.js';
|
|
3
|
+
import { type FloorContext, type IconProvider } from './types.js';
|
|
4
|
+
interface EndpointView {
|
|
5
|
+
/**
|
|
6
|
+
* Place source/destination icons. `snapped` — the live CP is currently on the route, so its
|
|
7
|
+
* source shows greyed-out. A kiosk anchor (off-graph origin that isn't the CP) stays hidden;
|
|
8
|
+
* everything else (booth, CP off-route, no live CP) shows full-colour.
|
|
9
|
+
*/
|
|
10
|
+
place(from: RouteEndpoint, to: RouteEndpoint, visibleRoutePoints: readonly RoutePoint[], snapped: boolean): void;
|
|
11
|
+
hide(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function createEndpointView({ renderer, iconProvider, floorContext, }: {
|
|
14
|
+
renderer: Pick<WayfindingRenderer, 'setIcon'>;
|
|
15
|
+
iconProvider: Pick<IconProvider, 'getIcon'>;
|
|
16
|
+
floorContext: Pick<FloorContext, 'isLayerVisible'>;
|
|
17
|
+
}): EndpointView;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=endpointView.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CURRENT_POSITION_POINT_ID } from './positionView.js';
|
|
2
|
+
function isSourceIconHidden(from, onFloor) {
|
|
3
|
+
// Hide only a kiosk anchor — an off-graph origin that isn't the live current position.
|
|
4
|
+
return !onFloor || (!from.bounds && from.id !== CURRENT_POSITION_POINT_ID);
|
|
5
|
+
}
|
|
6
|
+
export function createEndpointView({ renderer, iconProvider, floorContext, }) {
|
|
7
|
+
return {
|
|
8
|
+
place(from, to, visibleRoutePoints, snapped) {
|
|
9
|
+
if (!visibleRoutePoints.length)
|
|
10
|
+
return;
|
|
11
|
+
const fromOnFloor = floorContext.isLayerVisible(from.layer);
|
|
12
|
+
const toOnFloor = floorContext.isLayerVisible(to.layer);
|
|
13
|
+
const sourcePosition = visibleRoutePoints[0];
|
|
14
|
+
const destPosition = visibleRoutePoints[visibleRoutePoints.length - 1];
|
|
15
|
+
const sourceInactive = from.id === CURRENT_POSITION_POINT_ID && snapped;
|
|
16
|
+
const source = iconProvider.getIcon(sourceInactive ? 'source_inactive' : 'source');
|
|
17
|
+
const destination = iconProvider.getIcon('destination');
|
|
18
|
+
renderer.setIcon('source', {
|
|
19
|
+
canvas: source.canvas,
|
|
20
|
+
width: source.width,
|
|
21
|
+
height: source.height,
|
|
22
|
+
x: sourcePosition.x,
|
|
23
|
+
y: sourcePosition.y,
|
|
24
|
+
hidden: isSourceIconHidden(from, fromOnFloor),
|
|
25
|
+
dimmed: !fromOnFloor,
|
|
26
|
+
cardinalSnap: true,
|
|
27
|
+
});
|
|
28
|
+
renderer.setIcon('destination', {
|
|
29
|
+
canvas: destination.canvas,
|
|
30
|
+
width: destination.width,
|
|
31
|
+
height: destination.height,
|
|
32
|
+
x: destPosition.x,
|
|
33
|
+
y: destPosition.y,
|
|
34
|
+
hidden: !toOnFloor || !to.bounds,
|
|
35
|
+
dimmed: !toOnFloor,
|
|
36
|
+
cardinalSnap: true,
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
hide() {
|
|
40
|
+
renderer.setIcon('source', null);
|
|
41
|
+
renderer.setIcon('destination', null);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RouteEndpoint, type RouteLine, type WayfindingEngine } from '../core/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Choose between `engine.buildRoute` and `engine.buildWaypointsRoute` based on
|
|
4
|
+
* whether intermediate waypoints are supplied, and return the resulting route lines.
|
|
5
|
+
* @param root0
|
|
6
|
+
* @param root0.engine
|
|
7
|
+
* @param root0.from
|
|
8
|
+
* @param root0.to
|
|
9
|
+
* @param root0.waypoints
|
|
10
|
+
* @param root0.accessible
|
|
11
|
+
*/
|
|
12
|
+
export declare function getRouteLines({ engine, from, to, waypoints, accessible, }: {
|
|
13
|
+
readonly engine: WayfindingEngine;
|
|
14
|
+
readonly from: RouteEndpoint;
|
|
15
|
+
readonly to: RouteEndpoint;
|
|
16
|
+
readonly waypoints?: readonly RouteEndpoint[];
|
|
17
|
+
readonly accessible: boolean;
|
|
18
|
+
}): RouteLine[];
|
|
19
|
+
//# sourceMappingURL=getRouteLines.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choose between `engine.buildRoute` and `engine.buildWaypointsRoute` based on
|
|
3
|
+
* whether intermediate waypoints are supplied, and return the resulting route lines.
|
|
4
|
+
* @param root0
|
|
5
|
+
* @param root0.engine
|
|
6
|
+
* @param root0.from
|
|
7
|
+
* @param root0.to
|
|
8
|
+
* @param root0.waypoints
|
|
9
|
+
* @param root0.accessible
|
|
10
|
+
*/
|
|
11
|
+
export function getRouteLines({ engine, from, to, waypoints, accessible, }) {
|
|
12
|
+
if (waypoints?.length) {
|
|
13
|
+
return engine.buildWaypointsRoute([from, ...waypoints, to], { accessible }).lines;
|
|
14
|
+
}
|
|
15
|
+
return engine.buildRoute(from, to, { accessible }).lines;
|
|
16
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createWayfindingRuntime } from './createWayfindingRuntime.js';
|
|
2
|
+
export { CURRENT_POSITION_POINT_ID } from './positionView.js';
|
|
3
|
+
export type { FloorContext, IconAsset, IconName, IconProvider, PositionInput, SetRouteInput, WayfindingRuntime, WayfindingRuntimeConfig, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type RouteEndpoint, type RouteLine, type RoutePoint, type RouteSnapResult } from '../core/index.js';
|
|
2
|
+
import type { WayfindingRenderer } from '../renderer/index.js';
|
|
3
|
+
import type { TrailView } from './trailView.js';
|
|
4
|
+
import type { FloorContext, IconProvider, PositionInput } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Snapshot of the visible route the position-trail view operates on. The runtime computes it
|
|
7
|
+
* (visibility filtering, route-points derivation) and passes it in so the view stays free of
|
|
8
|
+
* route-state knowledge.
|
|
9
|
+
*/
|
|
10
|
+
export interface RouteSnapshot {
|
|
11
|
+
readonly from: RouteEndpoint;
|
|
12
|
+
readonly to: RouteEndpoint;
|
|
13
|
+
readonly routePoints: readonly RoutePoint[];
|
|
14
|
+
readonly visibleLines: readonly RouteLine[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Owns the user-position icon and the single off-graph trail slot. The runtime decides which end of
|
|
18
|
+
* the route needs a trail (kiosk FROM, kiosk TO, or off-route CP FROM — never both at once in
|
|
19
|
+
* practice) and passes the corresponding `tip` + `anchor` here.
|
|
20
|
+
*/
|
|
21
|
+
interface PositionTrailView {
|
|
22
|
+
/** Place the position icon at the raw position. */
|
|
23
|
+
placeIcon(position: PositionInput): void;
|
|
24
|
+
/** Hide the position icon. */
|
|
25
|
+
hideIcon(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Snap the position to `routeLines` (caller-provided — typically the full non-virtual route
|
|
28
|
+
* across all floors) and place the position icon at the snap point or at the raw position.
|
|
29
|
+
* Returns the snap result; the trail is **not** touched — call `setTrail` separately.
|
|
30
|
+
*
|
|
31
|
+
* `routeLines` is decoupled from `route.visibleLines` so the snap stays correct regardless of
|
|
32
|
+
* which floor is currently selected in the UI.
|
|
33
|
+
*/
|
|
34
|
+
applyToRoute(position: PositionInput, route: RouteSnapshot, routeLines: readonly RouteLine[]): RouteSnapResult;
|
|
35
|
+
/**
|
|
36
|
+
* Draw the trail from `tip` (a route's graph endpoint) to `anchor` (the off-graph point).
|
|
37
|
+
* Passing either as null hides the trail.
|
|
38
|
+
*/
|
|
39
|
+
setTrail(tip: RoutePoint | null, anchor: RoutePoint | null): void;
|
|
40
|
+
/** Clear the trail slot (does not touch the icon). */
|
|
41
|
+
clearTrail(): void;
|
|
42
|
+
}
|
|
43
|
+
export declare function createPositionTrailView({ renderer, iconProvider, floorContext, trails, snapThreshold, }: {
|
|
44
|
+
renderer: Pick<WayfindingRenderer, 'setIcon'>;
|
|
45
|
+
iconProvider: Pick<IconProvider, 'getIcon'>;
|
|
46
|
+
floorContext: Pick<FloorContext, 'isLayerVisible'>;
|
|
47
|
+
trails: TrailView;
|
|
48
|
+
snapThreshold: number;
|
|
49
|
+
}): PositionTrailView;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=positionTrailView.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createPositionView } from './positionView.js';
|
|
2
|
+
import { snapPositionToRoute } from './snapPositionToRoute.js';
|
|
3
|
+
const TRAIL_SLOT = 'trail';
|
|
4
|
+
export function createPositionTrailView({ renderer, iconProvider, floorContext, trails, snapThreshold, }) {
|
|
5
|
+
const positionIcon = createPositionView({ renderer, iconProvider });
|
|
6
|
+
return {
|
|
7
|
+
placeIcon(position) {
|
|
8
|
+
const hidden = !floorContext.isLayerVisible(position.layer);
|
|
9
|
+
positionIcon.place(position, hidden);
|
|
10
|
+
},
|
|
11
|
+
hideIcon() {
|
|
12
|
+
positionIcon.hide();
|
|
13
|
+
},
|
|
14
|
+
applyToRoute(position, route, routeLines) {
|
|
15
|
+
const snap = snapPositionToRoute(position, routeLines, route.from, route.to, snapThreshold);
|
|
16
|
+
const hidden = !floorContext.isLayerVisible(position.layer);
|
|
17
|
+
if (snap.snapped) {
|
|
18
|
+
positionIcon.place({ ...position, x: snap.snappedPoint.x, y: snap.snappedPoint.y }, hidden);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
positionIcon.place(position, hidden);
|
|
22
|
+
}
|
|
23
|
+
return snap;
|
|
24
|
+
},
|
|
25
|
+
setTrail(tip, anchor) {
|
|
26
|
+
if (tip && anchor)
|
|
27
|
+
trails.place(TRAIL_SLOT, tip, anchor);
|
|
28
|
+
else
|
|
29
|
+
trails.clear(TRAIL_SLOT);
|
|
30
|
+
},
|
|
31
|
+
clearTrail() {
|
|
32
|
+
trails.clear(TRAIL_SLOT);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type WayfindingRenderer } from '../renderer/index.js';
|
|
2
|
+
import { type IconProvider, type PositionInput } from './types.js';
|
|
3
|
+
export declare const CURRENT_POSITION_POINT_ID = "current-position";
|
|
4
|
+
interface PositionView {
|
|
5
|
+
/**
|
|
6
|
+
* Place or update the current-position icon. The icon variant (dot vs
|
|
7
|
+
* arrow) is derived from `input.heading`: finite heading → arrow, otherwise
|
|
8
|
+
* → dot.
|
|
9
|
+
*
|
|
10
|
+
* `hidden` collapses the monolith's dual (hidden, dimmed) fields into a
|
|
11
|
+
* single boolean — they were always driven by the same
|
|
12
|
+
* `!isLayerVisible(position.layer)` source.
|
|
13
|
+
*/
|
|
14
|
+
place(input: PositionInput, hidden: boolean): void;
|
|
15
|
+
hide(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function createPositionView({ renderer, iconProvider, }: {
|
|
18
|
+
renderer: Pick<WayfindingRenderer, 'setIcon'>;
|
|
19
|
+
iconProvider: Pick<IconProvider, 'getIcon'>;
|
|
20
|
+
}): PositionView;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=positionView.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { degToRad } from '@expofp/geometry';
|
|
2
|
+
export const CURRENT_POSITION_POINT_ID = 'current-position';
|
|
3
|
+
const POSITION_ICON_KEY = 'position';
|
|
4
|
+
export function createPositionView({ renderer, iconProvider, }) {
|
|
5
|
+
return {
|
|
6
|
+
place(input, hidden) {
|
|
7
|
+
const hasHeading = Number.isFinite(input.heading);
|
|
8
|
+
const iconName = hasHeading ? 'current_arrow' : 'current';
|
|
9
|
+
const rotation = hasHeading ? degToRad(input.heading) : undefined;
|
|
10
|
+
const icon = iconProvider.getIcon(iconName);
|
|
11
|
+
renderer.setIcon(POSITION_ICON_KEY, {
|
|
12
|
+
canvas: icon.canvas,
|
|
13
|
+
width: icon.width,
|
|
14
|
+
height: icon.height,
|
|
15
|
+
// Above the route icons: the live position must never end up under an endpoint pin.
|
|
16
|
+
onTop: true,
|
|
17
|
+
x: input.x,
|
|
18
|
+
y: input.y,
|
|
19
|
+
rotation,
|
|
20
|
+
// The arrow points along the device's own heading, which is a direction in the venue, so it
|
|
21
|
+
// stays flat on the plan and turns with it. A screen-space def spins about the screen's
|
|
22
|
+
// normal and would hold one screen direction whatever the plan is turned to. The
|
|
23
|
+
// headingless dot has no direction to lose, so it takes the renderer's own setting.
|
|
24
|
+
screenSpace: hasHeading ? false : undefined,
|
|
25
|
+
hidden,
|
|
26
|
+
dimmed: hidden,
|
|
27
|
+
origin: [0.5, 0.5],
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
hide() {
|
|
31
|
+
renderer.setIcon(POSITION_ICON_KEY, null);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|