@mappedin/blue-dot 6.0.1-beta.57 → 6.0.1-beta.59

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.
@@ -0,0 +1,75 @@
1
+ import {
2
+ BlueDot,
3
+ __name,
4
+ init_define_process
5
+ } from "../chunk-EEQMR2QG.js";
6
+
7
+ // src/react/index.ts
8
+ init_define_process();
9
+
10
+ // src/react/use-blue-dot.tsx
11
+ init_define_process();
12
+ import { useCallback, useState } from "react";
13
+ import { useMap, useMapViewExtension } from "@mappedin/react-sdk";
14
+ function useForceUpdate() {
15
+ const [, setState] = useState({});
16
+ return useCallback(() => setState({}), []);
17
+ }
18
+ __name(useForceUpdate, "useForceUpdate");
19
+ function useBlueDot() {
20
+ const { mapView } = useMap();
21
+ const forceUpdate = useForceUpdate();
22
+ const { register } = useMapViewExtension("blue-dot", {
23
+ onRegister: /* @__PURE__ */ __name(() => {
24
+ const bd = new BlueDot(mapView);
25
+ bd.on("position-update", forceUpdate);
26
+ bd.on("status-change", forceUpdate);
27
+ bd.on("follow-change", forceUpdate);
28
+ bd.on("error", forceUpdate);
29
+ return bd;
30
+ }, "onRegister"),
31
+ onDeregister: /* @__PURE__ */ __name((bd) => {
32
+ bd.off("position-update", forceUpdate);
33
+ bd.off("status-change", forceUpdate);
34
+ bd.off("follow-change", forceUpdate);
35
+ bd.off("error", forceUpdate);
36
+ bd.destroy();
37
+ }, "onDeregister")
38
+ });
39
+ const blueDot = register();
40
+ if (!blueDot) {
41
+ throw new Error("BlueDot failed to initialize.");
42
+ }
43
+ return blueDot;
44
+ }
45
+ __name(useBlueDot, "useBlueDot");
46
+
47
+ // src/react/use-blue-dot-event.tsx
48
+ init_define_process();
49
+ import { useCallback as useCallback2, useEffect, useRef } from "react";
50
+ function useBlueDotEvent(eventName, callback) {
51
+ const instance = useBlueDot();
52
+ const callbackRef = useRef(callback);
53
+ callbackRef.current = callback;
54
+ const handleCallback = useCallback2((payload) => {
55
+ callbackRef.current(payload);
56
+ }, []);
57
+ useEffect(() => {
58
+ if (instance == null) {
59
+ return;
60
+ }
61
+ instance.on(eventName, handleCallback);
62
+ return () => {
63
+ if (instance == null) {
64
+ return;
65
+ }
66
+ instance.off(eventName, handleCallback);
67
+ };
68
+ }, [instance, eventName, handleCallback]);
69
+ }
70
+ __name(useBlueDotEvent, "useBlueDotEvent");
71
+ export {
72
+ useBlueDot,
73
+ useBlueDotEvent
74
+ };
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/react/index.ts", "../../../src/react/use-blue-dot.tsx", "../../../src/react/use-blue-dot-event.tsx"],
4
+ "sourcesContent": ["export { useBlueDot } from './use-blue-dot';\nexport { useBlueDotEvent } from './use-blue-dot-event';\n", "import { useCallback, useState } from 'react';\nimport { BlueDot } from '../blue-dot';\nimport { useMap, useMapViewExtension } from '@mappedin/react-sdk';\n\n/**\n * Simple hook to force a re-render when the returned function is called\n */\nfunction useForceUpdate() {\n\tconst [, setState] = useState({});\n\treturn useCallback(() => setState({}), []);\n}\n\nexport function useBlueDot(): BlueDot {\n\tconst { mapView } = useMap();\n\n\t// Force a re-render on blue-dot state change to sync it up with react render cycle\n\t// The benefit of this is that blue-dot states like position, status, following, etc. changing will update the react component\n\tconst forceUpdate = useForceUpdate();\n\n\t// Register or retrieve the existing instance from the extension registry\n\tconst { register } = useMapViewExtension('blue-dot', {\n\t\tonRegister: () => {\n\t\t\tconst bd = new BlueDot(mapView);\n\t\t\t// when these events are emitted we force a re-render to get the latest blue-dot state\n\t\t\tbd.on('position-update', forceUpdate);\n\t\t\tbd.on('status-change', forceUpdate);\n\t\t\tbd.on('follow-change', forceUpdate);\n\t\t\tbd.on('error', forceUpdate);\n\t\t\treturn bd;\n\t\t},\n\t\tonDeregister: bd => {\n\t\t\tbd.off('position-update', forceUpdate);\n\t\t\tbd.off('status-change', forceUpdate);\n\t\t\tbd.off('follow-change', forceUpdate);\n\t\t\tbd.off('error', forceUpdate);\n\t\t\tbd.destroy();\n\t\t},\n\t});\n\tconst blueDot = register();\n\n\tif (!blueDot) {\n\t\tthrow new Error('BlueDot failed to initialize.');\n\t}\n\n\treturn blueDot;\n}\n", "import { useCallback, useEffect, useRef } from 'react';\nimport type { BlueDotEventPayloads, BlueDotEvents } from '../types';\nimport { useBlueDot } from './use-blue-dot';\n\nexport function useBlueDotEvent<T extends BlueDotEvents>(\n\teventName: T,\n\tcallback: (payload: BlueDotEventPayloads[T]) => void,\n) {\n\tconst instance = useBlueDot();\n\tconst callbackRef = useRef(callback);\n\tcallbackRef.current = callback;\n\n\tconst handleCallback = useCallback(payload => {\n\t\tcallbackRef.current(payload);\n\t}, []);\n\n\tuseEffect(() => {\n\t\tif (instance == null) {\n\t\t\treturn;\n\t\t}\n\t\tinstance.on(eventName, handleCallback);\n\t\treturn () => {\n\t\t\tif (instance == null) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tinstance.off(eventName, handleCallback);\n\t\t};\n\t}, [instance, eventName, handleCallback]);\n}\n"],
5
+ "mappings": ";;;;;;;AAAA;;;ACAA;AAAA,SAAS,aAAa,gBAAgB;AAEtC,SAAS,QAAQ,2BAA2B;AAK5C,SAAS,iBAAiB;AACzB,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAChC,SAAO,YAAY,MAAM,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1C;AAHS;AAKF,SAAS,aAAsB;AACrC,QAAM,EAAE,QAAQ,IAAI,OAAO;AAI3B,QAAM,cAAc,eAAe;AAGnC,QAAM,EAAE,SAAS,IAAI,oBAAoB,YAAY;AAAA,IACpD,YAAY,6BAAM;AACjB,YAAM,KAAK,IAAI,QAAQ,OAAO;AAE9B,SAAG,GAAG,mBAAmB,WAAW;AACpC,SAAG,GAAG,iBAAiB,WAAW;AAClC,SAAG,GAAG,iBAAiB,WAAW;AAClC,SAAG,GAAG,SAAS,WAAW;AAC1B,aAAO;AAAA,IACR,GARY;AAAA,IASZ,cAAc,+BAAM;AACnB,SAAG,IAAI,mBAAmB,WAAW;AACrC,SAAG,IAAI,iBAAiB,WAAW;AACnC,SAAG,IAAI,iBAAiB,WAAW;AACnC,SAAG,IAAI,SAAS,WAAW;AAC3B,SAAG,QAAQ;AAAA,IACZ,GANc;AAAA,EAOf,CAAC;AACD,QAAM,UAAU,SAAS;AAEzB,MAAI,CAAC,SAAS;AACb,UAAM,IAAI,MAAM,+BAA+B;AAAA,EAChD;AAEA,SAAO;AACR;AAjCgB;;;ACZhB;AAAA,SAAS,eAAAA,cAAa,WAAW,cAAc;AAIxC,SAAS,gBACf,WACA,UACC;AACD,QAAM,WAAW,WAAW;AAC5B,QAAM,cAAc,OAAO,QAAQ;AACnC,cAAY,UAAU;AAEtB,QAAM,iBAAiBC,aAAY,aAAW;AAC7C,gBAAY,QAAQ,OAAO;AAAA,EAC5B,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACf,QAAI,YAAY,MAAM;AACrB;AAAA,IACD;AACA,aAAS,GAAG,WAAW,cAAc;AACrC,WAAO,MAAM;AACZ,UAAI,YAAY,MAAM;AACrB;AAAA,MACD;AACA,eAAS,IAAI,WAAW,cAAc;AAAA,IACvC;AAAA,EACD,GAAG,CAAC,UAAU,WAAW,cAAc,CAAC;AACzC;AAxBgB;",
6
+ "names": ["useCallback", "useCallback"]
7
+ }
@@ -0,0 +1,188 @@
1
+ import type { Floor, MapView, Model } from '@mappedin/mappedin-js';
2
+ import { Coordinate } from '@mappedin/mappedin-js';
3
+ import type { MapViewExtension } from '@packages/internal/common/extensions';
4
+ import { PubSub } from '@packages/internal/common/pubsub';
5
+ import type { BlueDotEventPayloads, BlueDotState, BlueDotPositionProcessor, BlueDotPositionUpdate, BlueDotStatus, BlueDotUpdateOptions, FollowCameraOptions, FollowMode, GeolocationPositionExtended, BlueDotUpdateState } from './types';
6
+ import type { ReadonlyDeep } from 'type-fest';
7
+ /**
8
+ * Show a Blue Dot indicating the device's position on the map.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { show3dMap } from '@mappedin/mappedin-js';
13
+ * import { BlueDot } from '@mappedin/blue-dot';
14
+ *
15
+ * const mapView = await show3dMap(...);
16
+ *
17
+ * // Enable BlueDot
18
+ * new BlueDot(mapView).enable();
19
+ *
20
+ * // Option 1: Listen for position updates from the device
21
+ * mapView.BlueDot.on('position-update', (position) => {
22
+ * console.log('User position:', position);
23
+ * });
24
+ *
25
+ * // Option 2: Update position manually
26
+ * new BlueDot(mapView).update({ latitude, longitude, accuracy, floorOrFloorId });
27
+ *
28
+ * ```
29
+ */
30
+ export declare class BlueDot implements MapViewExtension<BlueDotState> {
31
+ #private;
32
+ /**
33
+ * Create a new {@link BlueDot} instance.
34
+ */
35
+ constructor(mapView: MapView);
36
+ /**
37
+ * Get the Model for the BlueDot core element.
38
+ */
39
+ get dotModel(): Model | undefined;
40
+ /**
41
+ * Get the Model for the accuracy ring.
42
+ */
43
+ get accuracyRingModel(): Model | undefined;
44
+ /**
45
+ * Get the Model for the heading cone.
46
+ */
47
+ get headingConeModel(): Model | undefined;
48
+ /**
49
+ * Whether the BlueDot is currently enabled.
50
+ */
51
+ get isEnabled(): boolean;
52
+ /**
53
+ * The current state of the BlueDot. Can be 'hidden', 'active', 'inactive', or 'disabled'.
54
+ * Listen for state changes using the 'status-change' event.
55
+ *
56
+ * @example
57
+ * mapView.BlueDot.on('status-change', ({ status }) => {
58
+ * if (status === 'active') {
59
+ * // BlueDot is visible and tracking
60
+ * }
61
+ * });
62
+ */
63
+ get status(): BlueDotStatus;
64
+ /**
65
+ * Whether the BlueDot is currently following the user (camera follow mode).
66
+ */
67
+ get isFollowing(): boolean;
68
+ /**
69
+ * The direction the user is facing in degrees from north clockwise.
70
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates/heading
71
+ */
72
+ get heading(): GeolocationPosition['coords']['heading'] | undefined;
73
+ /**
74
+ * The accuracy of the current position in metres.
75
+ */
76
+ get accuracy(): GeolocationPosition['coords']['accuracy'] | undefined;
77
+ /**
78
+ * The coordinate of the current position.
79
+ */
80
+ get coordinate(): Coordinate | undefined;
81
+ getState: () => ReadonlyDeep<BlueDotState>;
82
+ /**
83
+ * The floor the Blue Dot is currently on. If undefined, the Blue Dot will appear on every floor.
84
+ */
85
+ get floor(): Floor | undefined;
86
+ /**
87
+ * Enable the Blue Dot. It will be hidden until a position is received either from the browser or by calling {@link BlueDot.update}.
88
+ * @param options - The options to setup the Blue Dot (see {@link BlueDotOptions}).
89
+ *
90
+ * @example Enable with default options
91
+ * mapView.BlueDot.enable();
92
+ *
93
+ * @example Enable with custom color and accuracy ring
94
+ * mapView.BlueDot.enable({ color: '#00ff00', accuracyRing: { color: '#00ff00', opacity: 0.2 } });
95
+ *
96
+ * @see See the [BlueDot Guide](https://developer.mappedin.com/web-sdk/blue-dot) for more information.
97
+ */
98
+ enable: (options?: BlueDotUpdateState) => void;
99
+ /**
100
+ * Disable the Blue Dot. It will be hidden and no longer update.
101
+ */
102
+ disable: () => void;
103
+ /**
104
+ * Subscribe to a BlueDot event.
105
+ * @param eventName The name of the event to listen for.
106
+ * @param fn The function to call when the event is emitted.
107
+ */
108
+ on: PubSub<BlueDotEventPayloads>['on'];
109
+ /**
110
+ * Unsubscribe from a BlueDot event.
111
+ * @param eventName The name of the event to unsubscribe from.
112
+ * @param fn The function to unsubscribe from the event.
113
+ */
114
+ off: PubSub<BlueDotEventPayloads>['off'];
115
+ /**
116
+ * Update the BlueDot state after it has been enabled.
117
+ * This allows overriding previously set values like colors, and other options.
118
+ * @param options - The options to update
119
+ *
120
+ * @example Update color and accuracy ring
121
+ * mapView.BlueDot.updateState({
122
+ * color: '#ff0000',
123
+ * accuracyRing: { color: '#ff0000', opacity: 0.5 }
124
+ * });
125
+ */
126
+ updateState: (options: BlueDotUpdateState) => void;
127
+ /**
128
+ * Enable or disable the devices's geolocation listener to automatically position the Blue Dot.
129
+ * If enabled, the device will request permission to access the user's precise location.
130
+ * @param watch - Whether to enable or disable the listener.
131
+ */
132
+ watchDevicePosition: (watch: boolean) => void;
133
+ /**
134
+ * Manually override some position properties of the Blue Dot.
135
+ * Accepts a full GeolocationPosition object or a partial {@link BlueDotPositionUpdate} object.
136
+ * @example Manually set the accuracy and heading
137
+ * ```ts
138
+ * api.BlueDot.update({ accuracy: 10, heading: 90 });
139
+ * ```
140
+ * @example Reset accuracy and heading to device values
141
+ * ```ts
142
+ * api.BlueDot.update({ accuracy: 'device', heading: 'device' });
143
+ * ```
144
+ */
145
+ update: (position: GeolocationPositionExtended | BlueDotPositionUpdate | undefined, options?: BlueDotUpdateOptions) => void;
146
+ /**
147
+ * Set the camera to follow the BlueDot in various modes. User interaction will cancel following automatically.
148
+ * @param mode The follow mode ('position-only', 'position-and-heading', 'position-and-path-direction', or false to disable).
149
+ * @param cameraOptions Optional camera options (zoom, pitch, etc.).
150
+ *
151
+ * @example
152
+ * mapView.BlueDot.follow('position-and-heading', { zoomLevel: 21, pitch: 45 });
153
+ */
154
+ follow: (mode: FollowMode, cameraOptions?: FollowCameraOptions) => void;
155
+ /**
156
+ * Set a position processor callback that allows intercepting and modifying device/geolocation position updates before they are applied.
157
+ *
158
+ * **Note**: This processor only applies to automatic position updates from device geolocation.
159
+ * Manual position updates via `update()` method bypass the processor and are applied directly.
160
+ *
161
+ * @param processor - A callback function that receives current state and incoming update. Return undefined to discard the update, or return a modified update object.
162
+ *
163
+ * @example Discard inaccurate positions
164
+ * ```ts
165
+ * blueDot.setPositionProcessor((current, incoming) => {
166
+ * if (incoming.accuracy && incoming.accuracy > 50) {
167
+ * return undefined; // Discard update
168
+ * }
169
+ * return incoming; // Accept update
170
+ * });
171
+ * ```
172
+ *
173
+ * @example Modify incoming positions
174
+ * ```ts
175
+ * blueDot.setPositionProcessor((current, incoming) => {
176
+ * // Apply custom smoothing or validation logic
177
+ * return {
178
+ * ...incoming,
179
+ * accuracy: Math.min(incoming.accuracy || 100, 10) // Cap accuracy
180
+ * };
181
+ * });
182
+ * ```
183
+ */
184
+ setPositionProcessor(processor?: BlueDotPositionProcessor): void;
185
+ destroy: () => void;
186
+ private onPositionUpdate;
187
+ private onPositionError;
188
+ }
@@ -0,0 +1,11 @@
1
+ import type { BlueDotState } from './types';
2
+ export declare const POSITION_ANIMATION_DURATION = 1000;
3
+ export declare const SCALE_ANIMATION_DURATION = 150;
4
+ export declare const ROTATION_ANIMATION_DURATION = 150;
5
+ export declare const MIN_BLUEDOT_RADIUS = 0.35;
6
+ export declare const BLUEDOT_RADIUS = 10;
7
+ export declare const BASE_COLOR = "#2266ff";
8
+ export declare const INACTIVE_COLOR = "#808080";
9
+ export declare const HEADING_CONE_OPACITY = 0.7;
10
+ export declare const ACCURACY_RING_OPACITY = 0.3;
11
+ export declare const DEFAULT_BLUEDOT_OPTIONS: BlueDotState;