@accelint/map-toolkit 0.4.1 → 0.6.0

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +3 -0
  3. package/catalog-info.yaml +6 -3
  4. package/dist/camera/events.d.ts +15 -0
  5. package/dist/camera/events.js +29 -0
  6. package/dist/camera/events.js.map +1 -0
  7. package/dist/camera/index.d.ts +16 -0
  8. package/dist/camera/index.js +17 -0
  9. package/dist/camera/types.d.ts +84 -0
  10. package/dist/{decorators/deckgl.d.ts → camera/types.js} +0 -7
  11. package/dist/camera/use-camera-state.d.ts +153 -0
  12. package/dist/camera/use-camera-state.js +418 -0
  13. package/dist/camera/use-camera-state.js.map +1 -0
  14. package/dist/cursor-coordinates/use-cursor-coordinates.js +1 -1
  15. package/dist/deckgl/base-map/constants.d.ts +14 -2
  16. package/dist/deckgl/base-map/constants.js +14 -2
  17. package/dist/deckgl/base-map/constants.js.map +1 -1
  18. package/dist/deckgl/base-map/controls.d.ts +34 -0
  19. package/dist/deckgl/base-map/controls.js +50 -0
  20. package/dist/deckgl/base-map/controls.js.map +1 -0
  21. package/dist/deckgl/base-map/events.d.ts +4 -0
  22. package/dist/deckgl/base-map/events.js +5 -1
  23. package/dist/deckgl/base-map/events.js.map +1 -1
  24. package/dist/deckgl/base-map/index.d.ts +10 -23
  25. package/dist/deckgl/base-map/index.js +81 -42
  26. package/dist/deckgl/base-map/index.js.map +1 -1
  27. package/dist/deckgl/base-map/types.d.ts +48 -2
  28. package/dist/deckgl/index.d.ts +11 -4
  29. package/dist/deckgl/index.js +7 -2
  30. package/dist/deckgl/saved-viewports/index.d.ts +32 -0
  31. package/dist/deckgl/saved-viewports/index.js +51 -0
  32. package/dist/deckgl/saved-viewports/index.js.map +1 -0
  33. package/dist/deckgl/saved-viewports/storage.d.ts +21 -0
  34. package/dist/deckgl/saved-viewports/storage.js +39 -0
  35. package/dist/deckgl/saved-viewports/storage.js.map +1 -0
  36. package/dist/deckgl/shapes/display-shape-layer/constants.d.ts +44 -0
  37. package/dist/deckgl/shapes/display-shape-layer/constants.js +61 -0
  38. package/dist/deckgl/shapes/display-shape-layer/constants.js.map +1 -0
  39. package/dist/deckgl/shapes/display-shape-layer/fiber.d.ts +25 -0
  40. package/dist/deckgl/shapes/display-shape-layer/fiber.js +21 -0
  41. package/dist/deckgl/shapes/display-shape-layer/fiber.js.map +1 -0
  42. package/dist/deckgl/shapes/display-shape-layer/index.d.ts +206 -0
  43. package/dist/deckgl/shapes/display-shape-layer/index.js +416 -0
  44. package/dist/deckgl/shapes/display-shape-layer/index.js.map +1 -0
  45. package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.d.ts +66 -0
  46. package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.js +116 -0
  47. package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.js.map +1 -0
  48. package/dist/deckgl/shapes/display-shape-layer/store.d.ts +87 -0
  49. package/dist/deckgl/shapes/display-shape-layer/store.js +316 -0
  50. package/dist/deckgl/shapes/display-shape-layer/store.js.map +1 -0
  51. package/dist/deckgl/shapes/display-shape-layer/types.d.ts +115 -0
  52. package/dist/deckgl/shapes/display-shape-layer/types.js +12 -0
  53. package/dist/deckgl/shapes/display-shape-layer/use-shape-selection.d.ts +89 -0
  54. package/dist/deckgl/shapes/display-shape-layer/use-shape-selection.js +88 -0
  55. package/dist/deckgl/shapes/display-shape-layer/use-shape-selection.js.map +1 -0
  56. package/dist/deckgl/shapes/display-shape-layer/utils/display-style.d.ts +61 -0
  57. package/dist/deckgl/shapes/display-shape-layer/utils/display-style.js +111 -0
  58. package/dist/deckgl/shapes/display-shape-layer/utils/display-style.js.map +1 -0
  59. package/dist/deckgl/shapes/display-shape-layer/utils/labels.d.ts +196 -0
  60. package/dist/deckgl/shapes/display-shape-layer/utils/labels.js +368 -0
  61. package/dist/deckgl/shapes/display-shape-layer/utils/labels.js.map +1 -0
  62. package/dist/deckgl/shapes/index.d.ts +20 -0
  63. package/dist/deckgl/shapes/index.js +20 -0
  64. package/dist/deckgl/shapes/shared/constants.d.ts +78 -0
  65. package/dist/deckgl/shapes/shared/constants.js +109 -0
  66. package/dist/deckgl/shapes/shared/constants.js.map +1 -0
  67. package/dist/deckgl/shapes/shared/events.d.ts +73 -0
  68. package/dist/deckgl/shapes/shared/events.js +58 -0
  69. package/dist/deckgl/shapes/shared/events.js.map +1 -0
  70. package/dist/deckgl/shapes/shared/types.d.ts +158 -0
  71. package/dist/{decorators/deckgl.js → deckgl/shapes/shared/types.js} +12 -15
  72. package/dist/deckgl/shapes/shared/types.js.map +1 -0
  73. package/dist/deckgl/symbol-layer/index.d.ts +1 -1
  74. package/dist/maplibre/hooks/use-maplibre.d.ts +2 -2
  75. package/dist/maplibre/hooks/use-maplibre.js +2 -2
  76. package/dist/maplibre/hooks/use-maplibre.js.map +1 -1
  77. package/dist/viewport/viewport-size.d.ts +2 -2
  78. package/package.json +50 -23
  79. package/dist/decorators/deckgl.js.map +0 -1
@@ -0,0 +1,418 @@
1
+ /*
2
+ * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at https://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+
14
+ import { CameraEventTypes } from "./events.js";
15
+ import { Broadcast } from "@accelint/bus";
16
+ import { fitBounds } from "@math.gl/web-mercator";
17
+ import { useMemo, useSyncExternalStore } from "react";
18
+
19
+ //#region src/camera/use-camera-state.ts
20
+ /**
21
+ * Typed event bus instance for camera events.
22
+ * Provides type-safe event emission and listening for all camera state changes.
23
+ */
24
+ const cameraBus = Broadcast.getInstance();
25
+ /**
26
+ * Store for camera state keyed by instanceId
27
+ */
28
+ const cameraStore = /* @__PURE__ */ new Map();
29
+ /**
30
+ * Track React component subscribers per instanceId (for fan-out notifications).
31
+ * Each Set contains onStoreChange callbacks from useSyncExternalStore.
32
+ */
33
+ const componentSubscribers = /* @__PURE__ */ new Map();
34
+ /**
35
+ * Cache of bus unsubscribe functions (1 per instanceId).
36
+ * This ensures we only have one bus listener per camera, regardless of
37
+ * how many React components subscribe to it.
38
+ */
39
+ const busUnsubscribers = /* @__PURE__ */ new Map();
40
+ /**
41
+ * Cache of subscription functions per instanceId to avoid recreating on every render
42
+ */
43
+ const subscriptionCache = /* @__PURE__ */ new Map();
44
+ /**
45
+ * Cache of snapshot functions per instanceId to maintain referential stability
46
+ */
47
+ const snapshotCache = /* @__PURE__ */ new Map();
48
+ /**
49
+ * Cache of fallback snapshots per instanceId to maintain referential stability.
50
+ * This prevents unnecessary re-renders when no camera data exists yet.
51
+ */
52
+ const fallbackCache = /* @__PURE__ */ new Map();
53
+ function buildInitialCameraState(initialCameraState) {
54
+ if (!initialCameraState) return {
55
+ latitude: 0,
56
+ longitude: 0,
57
+ zoom: 0,
58
+ pitch: 0,
59
+ rotation: 0,
60
+ projection: "mercator",
61
+ view: "2D"
62
+ };
63
+ const is2Point5D = initialCameraState.view === "2.5D";
64
+ const is3D = initialCameraState.view === "3D" || initialCameraState.projection === "globe";
65
+ let projection;
66
+ let view;
67
+ if (is3D) {
68
+ projection = "globe";
69
+ view = "3D";
70
+ } else if (is2Point5D) {
71
+ projection = "mercator";
72
+ view = "2.5D";
73
+ } else {
74
+ projection = initialCameraState.projection ?? "mercator";
75
+ view = initialCameraState.view ?? "2D";
76
+ }
77
+ return {
78
+ latitude: initialCameraState.latitude ?? 0,
79
+ longitude: initialCameraState.longitude ?? 0,
80
+ zoom: initialCameraState.zoom ?? 0,
81
+ pitch: is2Point5D ? initialCameraState.pitch ?? 45 : 0,
82
+ rotation: is3D ? 0 : initialCameraState.rotation ?? 0,
83
+ projection,
84
+ view
85
+ };
86
+ }
87
+ function getOrCreateState(instanceId, initialCameraState) {
88
+ if (!cameraStore.has(instanceId)) cameraStore.set(instanceId, buildInitialCameraState(initialCameraState));
89
+ return cameraStore.get(instanceId);
90
+ }
91
+ /**
92
+ * Notify all React subscribers for a given instanceId
93
+ */
94
+ function notifySubscribers(instanceId) {
95
+ const subscribers = componentSubscribers.get(instanceId);
96
+ if (subscribers) for (const onStoreChange of subscribers) onStoreChange();
97
+ }
98
+ /**
99
+ * Ensures a single bus listener exists for the given instanceId.
100
+ * All React subscribers will be notified via fan-out when the bus event fires.
101
+ * This prevents creating N bus listeners for N React components.
102
+ *
103
+ * @param instanceId - The unique identifier for the camera
104
+ * @param initialCameraState - Optional initial camera state to set when creating the listener
105
+ */
106
+ function ensureBusListener(instanceId, initialCameraState) {
107
+ if (busUnsubscribers.has(instanceId)) return;
108
+ const unsubResetCamera = cameraBus.on(CameraEventTypes.reset, ({ payload }) => {
109
+ if (instanceId === payload.id) {
110
+ const state = getOrCreateState(instanceId, initialCameraState);
111
+ const newState = { ...buildInitialCameraState({
112
+ ...state,
113
+ zoom: payload.zoom === false ? state.zoom : initialCameraState?.zoom,
114
+ pitch: payload.pitch === false ? state.pitch : initialCameraState?.pitch,
115
+ rotation: payload.rotation === false ? state.rotation : initialCameraState?.rotation
116
+ }) };
117
+ cameraStore.set(instanceId, newState);
118
+ notifySubscribers(instanceId);
119
+ }
120
+ });
121
+ const unsubSetCenter = cameraBus.on(CameraEventTypes.setCenter, ({ payload }) => {
122
+ if (instanceId === payload.id) {
123
+ const state = getOrCreateState(instanceId, initialCameraState);
124
+ const newState = {
125
+ ...state,
126
+ latitude: payload.latitude,
127
+ longitude: payload.longitude,
128
+ zoom: payload.zoom ?? state.zoom,
129
+ rotation: payload.heading ?? state.rotation,
130
+ pitch: payload.pitch ?? state.pitch
131
+ };
132
+ cameraStore.set(instanceId, newState);
133
+ notifySubscribers(instanceId);
134
+ }
135
+ });
136
+ const unsubFitBounds = cameraBus.on(CameraEventTypes.fitBounds, ({ payload }) => {
137
+ if (instanceId === payload.id) {
138
+ const state = getOrCreateState(instanceId, initialCameraState);
139
+ const { longitude, latitude, zoom } = fitBounds({
140
+ width: payload.width,
141
+ height: payload.height,
142
+ bounds: [[payload.bounds[0], payload.bounds[1]], [payload.bounds[2], payload.bounds[3]]],
143
+ padding: payload.padding
144
+ });
145
+ const newState = {
146
+ ...state,
147
+ latitude,
148
+ longitude,
149
+ zoom,
150
+ rotation: payload.heading ?? state.rotation,
151
+ pitch: payload.pitch ?? state.pitch
152
+ };
153
+ cameraStore.set(instanceId, newState);
154
+ notifySubscribers(instanceId);
155
+ }
156
+ });
157
+ const unsubSetProjection = cameraBus.on(CameraEventTypes.setProjection, ({ payload }) => {
158
+ if (instanceId === payload.id) {
159
+ const newState = { ...getOrCreateState(instanceId, initialCameraState) };
160
+ newState.projection = payload.projection;
161
+ if (payload.projection === "globe") newState.view = "3D";
162
+ else {
163
+ newState.view = "2D";
164
+ newState.pitch = 0;
165
+ }
166
+ cameraStore.set(instanceId, newState);
167
+ notifySubscribers(instanceId);
168
+ }
169
+ });
170
+ const unsubSetView = cameraBus.on(CameraEventTypes.setView, ({ payload }) => {
171
+ if (instanceId === payload.id) {
172
+ const newState = { ...getOrCreateState(instanceId, initialCameraState) };
173
+ newState.view = payload.view;
174
+ if (payload.view === "3D") {
175
+ newState.projection = "globe";
176
+ newState.pitch = 0;
177
+ } else newState.projection = "mercator";
178
+ if (payload.view === "2.5D") newState.pitch = 45;
179
+ cameraStore.set(instanceId, newState);
180
+ notifySubscribers(instanceId);
181
+ }
182
+ });
183
+ const unsubSetZoom = cameraBus.on(CameraEventTypes.setZoom, ({ payload }) => {
184
+ if (instanceId === payload.id) {
185
+ const newState = { ...getOrCreateState(instanceId, initialCameraState) };
186
+ newState.zoom = payload.zoom;
187
+ cameraStore.set(instanceId, newState);
188
+ notifySubscribers(instanceId);
189
+ }
190
+ });
191
+ const unsubSetRotation = cameraBus.on(CameraEventTypes.setRotation, ({ payload }) => {
192
+ const state = getOrCreateState(instanceId, initialCameraState);
193
+ if (instanceId === payload.id && state.view !== "3D") {
194
+ const newState = { ...state };
195
+ newState.rotation = payload.rotation;
196
+ cameraStore.set(instanceId, newState);
197
+ notifySubscribers(instanceId);
198
+ }
199
+ });
200
+ const unsubSetPitch = cameraBus.on(CameraEventTypes.setPitch, ({ payload }) => {
201
+ const state = getOrCreateState(instanceId, initialCameraState);
202
+ if (instanceId === payload.id && state.view === "2.5D") {
203
+ const newState = { ...state };
204
+ newState.pitch = payload.pitch;
205
+ cameraStore.set(instanceId, newState);
206
+ notifySubscribers(instanceId);
207
+ }
208
+ });
209
+ busUnsubscribers.set(instanceId, () => {
210
+ unsubResetCamera();
211
+ unsubSetCenter();
212
+ unsubFitBounds();
213
+ unsubSetProjection();
214
+ unsubSetView();
215
+ unsubSetZoom();
216
+ unsubSetRotation();
217
+ unsubSetPitch();
218
+ });
219
+ }
220
+ /**
221
+ * Cleans up the bus listener if no React subscribers remain.
222
+ *
223
+ * @param instanceId - The unique identifier for the camera
224
+ */
225
+ function cleanupBusListenerIfNeeded(instanceId) {
226
+ const subscribers = componentSubscribers.get(instanceId);
227
+ if (!subscribers || subscribers.size === 0) {
228
+ const unsub = busUnsubscribers.get(instanceId);
229
+ if (unsub) {
230
+ unsub();
231
+ busUnsubscribers.delete(instanceId);
232
+ }
233
+ [
234
+ cameraStore,
235
+ componentSubscribers,
236
+ subscriptionCache,
237
+ snapshotCache,
238
+ fallbackCache
239
+ ].forEach((map) => {
240
+ map.delete(instanceId);
241
+ });
242
+ }
243
+ }
244
+ /**
245
+ * Creates or retrieves a cached subscription function for a given instanceId.
246
+ * Uses a fan-out pattern: 1 bus listener -> N React subscribers.
247
+ * Automatically cleans up camera state when the last subscriber unsubscribes.
248
+ *
249
+ * @param instanceId - The unique identifier for the camera
250
+ * @param initialCameraState - Optional initial camera state to set when creating the listener
251
+ * @returns A subscription function for useSyncExternalStore
252
+ */
253
+ function getOrCreateSubscription(instanceId, initialCameraState) {
254
+ const subscription = subscriptionCache.get(instanceId) ?? ((onStoreChange) => {
255
+ ensureBusListener(instanceId, initialCameraState);
256
+ let subscriberSet = componentSubscribers.get(instanceId);
257
+ if (!subscriberSet) {
258
+ subscriberSet = /* @__PURE__ */ new Set();
259
+ componentSubscribers.set(instanceId, subscriberSet);
260
+ }
261
+ subscriberSet.add(onStoreChange);
262
+ return () => {
263
+ const currentSubscriberSet = componentSubscribers.get(instanceId);
264
+ if (currentSubscriberSet) currentSubscriberSet.delete(onStoreChange);
265
+ cleanupBusListenerIfNeeded(instanceId);
266
+ };
267
+ });
268
+ subscriptionCache.set(instanceId, subscription);
269
+ return subscription;
270
+ }
271
+ /**
272
+ * Creates or retrieves a cached snapshot function for a given instanceId.
273
+ * The object returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.
274
+ *
275
+ * @param instanceId - The unique identifier for the camera
276
+ * @param initialCameraState - Initialize the snapshot with camera view information
277
+ * @returns A snapshot function for useSyncExternalStore
278
+ */
279
+ function getOrCreateSnapshot(instanceId, initialCameraState) {
280
+ const fallback = fallbackCache.get(instanceId) ?? (() => {
281
+ const newFallback = {
282
+ latitude: initialCameraState?.latitude ?? 0,
283
+ longitude: initialCameraState?.longitude ?? 0,
284
+ zoom: initialCameraState?.zoom ?? 0,
285
+ pitch: 0,
286
+ rotation: 0,
287
+ projection: "mercator",
288
+ view: "2D"
289
+ };
290
+ fallbackCache.set(instanceId, newFallback);
291
+ return newFallback;
292
+ })();
293
+ const snapshot = snapshotCache.get(instanceId) ?? (() => cameraStore.get(instanceId) ?? fallback);
294
+ snapshotCache.set(instanceId, snapshot);
295
+ return snapshot;
296
+ }
297
+ /**
298
+ * Updates the camera state for a given map instance and notifies subscribers.
299
+ *
300
+ * @param instanceId - The unique identifier for the map
301
+ * @param state - The new state to set, will be merged with existing state
302
+ *
303
+ * @example
304
+ * ```tsx
305
+ * // Update camera state manually
306
+ * setCameraState('my-map-instance', {
307
+ * latitude: 37.7749,
308
+ * longitude: -122.4194,
309
+ * zoom: 10,
310
+ * pitch: 30,
311
+ * rotation: 0,
312
+ * projection: 'mercator',
313
+ * });
314
+ * ```
315
+ */
316
+ function setCameraState(instanceId, state) {
317
+ const currentState = getOrCreateState(instanceId);
318
+ cameraStore.set(instanceId, {
319
+ ...currentState,
320
+ ...state
321
+ });
322
+ notifySubscribers(instanceId);
323
+ }
324
+ /**
325
+ * Hook to access camera state actions.
326
+ *
327
+ * This hook uses `useSyncExternalStore` to subscribe to camera state changes,
328
+ * providing concurrent-safe mode state updates. Uses a fan-out pattern where
329
+ * a single bus listener per map instance notifies N React component subscribers.
330
+ *
331
+ * A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).
332
+ *
333
+ * @param instanceId - Unique identifier for the camera to track
334
+ * @param initialCameraState - Optional initial camera state to set
335
+ * @param subscribe - Optional custom subscription function
336
+ * @param getSnapshot - Optional custom snapshot getter
337
+ * @param getServerSnapshot - Optional server-side snapshot getter
338
+ * @returns Current camera state including latitude, longitude, zoom, pitch, rotation, projection
339
+ *
340
+ * @example
341
+ * ```tsx
342
+ * function MapInfo({ instanceId }) {
343
+ * const { latitude, longitude, zoom } = useCameraState({
344
+ * instanceId
345
+ * });
346
+ *
347
+ * return (
348
+ * <div>
349
+ * Lat: {latitude?.toFixed(2)}, Lon: {longitude?.toFixed(2)}, Zoom: {zoom}
350
+ * </div>
351
+ * );
352
+ * }
353
+ * ```
354
+ *
355
+ * @example
356
+ * ```tsx
357
+ * // With custom subscribe/getSnapshot for advanced use cases
358
+ * function CustomMapInfo() {
359
+ * const customSubscribe = (onStoreChange) => {
360
+ * // Custom subscription logic
361
+ * return () => { // cleanup }
362
+ * }
363
+ *
364
+ * const customGetSnapshot = () => {
365
+ * // Custom snapshot logic
366
+ * return { latitude: 0, longitude: 0, zoom: 1 };
367
+ * };
368
+ *
369
+ * const viewState = useCameraState({
370
+ * instanceId: 'some-uuid',
371
+ * subscribe: customSubscribe,
372
+ * getSnapshot: customGetSnapshot,
373
+ * });
374
+ *
375
+ * return <div>Custom camera state</div>;
376
+ * }
377
+ * ```
378
+ */
379
+ function useCameraState({ instanceId, initialCameraState, subscribe, getSnapshot, getServerSnapshot }) {
380
+ const cameraState = useSyncExternalStore(subscribe ?? getOrCreateSubscription(instanceId, initialCameraState), getSnapshot ?? getOrCreateSnapshot(instanceId, initialCameraState), getServerSnapshot);
381
+ return useMemo(() => ({
382
+ cameraState,
383
+ setCameraState
384
+ }), [cameraState]);
385
+ }
386
+ /**
387
+ * Manually clear camera state for a specific instanceId.
388
+ * This is typically not needed as cleanup happens automatically when all subscribers unmount.
389
+ * Use this only in advanced scenarios where manual cleanup is required.
390
+ *
391
+ * @param instanceId - The unique identifier for the camera to clear
392
+ *
393
+ * @example
394
+ * ```tsx
395
+ * // Manual cleanup (rarely needed)
396
+ * clearCameraState('my-map-instance');
397
+ * ```
398
+ */
399
+ function clearCameraState(instanceId) {
400
+ const unsub = busUnsubscribers.get(instanceId);
401
+ if (unsub) {
402
+ unsub();
403
+ busUnsubscribers.delete(instanceId);
404
+ }
405
+ [
406
+ cameraStore,
407
+ componentSubscribers,
408
+ subscriptionCache,
409
+ snapshotCache,
410
+ fallbackCache
411
+ ].forEach((map) => {
412
+ map.delete(instanceId);
413
+ });
414
+ }
415
+
416
+ //#endregion
417
+ export { clearCameraState, useCameraState };
418
+ //# sourceMappingURL=use-camera-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-camera-state.js","names":["projection: ProjectionType","view: ViewType","newFallback: CameraState"],"sources":["../../src/camera/use-camera-state.ts"],"sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { Broadcast } from '@accelint/bus';\nimport { fitBounds } from '@math.gl/web-mercator';\nimport { useMemo, useSyncExternalStore } from 'react';\nimport { CameraEventTypes } from './events';\nimport type { UniqueId } from '@accelint/core';\nimport type { CameraEvent, ProjectionType, ViewType } from './types';\n\n/**\n * Typed event bus instance for camera events.\n * Provides type-safe event emission and listening for all camera state changes.\n */\nconst cameraBus = Broadcast.getInstance<CameraEvent>();\n\ntype CameraState2D = {\n latitude: number;\n longitude: number;\n zoom: number;\n pitch: 0;\n rotation: number;\n projection: 'mercator';\n view: '2D';\n};\n\ntype CameraState3D = {\n latitude: number;\n longitude: number;\n zoom: number;\n pitch: 0;\n rotation: number;\n projection: 'globe';\n view: '3D';\n};\n\ntype CameraState2Point5D = {\n latitude: number;\n longitude: number;\n zoom: number;\n pitch: number;\n rotation: number;\n projection: 'mercator';\n view: '2.5D';\n};\n\nexport type CameraState = CameraState2D | CameraState3D | CameraState2Point5D;\n\nexport type UseCameraStateProps = {\n instanceId: UniqueId;\n initialCameraState?: Partial<CameraState>;\n subscribe?: Parameters<typeof useSyncExternalStore<CameraState>>[0];\n getSnapshot?: Parameters<typeof useSyncExternalStore<CameraState>>[1];\n getServerSnapshot?: Parameters<typeof useSyncExternalStore<CameraState>>[2];\n};\n\n/**\n * Store for camera state keyed by instanceId\n */\nconst cameraStore = new Map<UniqueId, CameraState>();\n\n/**\n * Track React component subscribers per instanceId (for fan-out notifications).\n * Each Set contains onStoreChange callbacks from useSyncExternalStore.\n */\nconst componentSubscribers = new Map<UniqueId, Set<() => void>>();\n\n/**\n * Cache of bus unsubscribe functions (1 per instanceId).\n * This ensures we only have one bus listener per camera, regardless of\n * how many React components subscribe to it.\n */\nconst busUnsubscribers = new Map<UniqueId, () => void>();\n\ntype Subscription = (onStoreChange: () => void) => () => void;\n/**\n * Cache of subscription functions per instanceId to avoid recreating on every render\n */\nconst subscriptionCache = new Map<UniqueId, Subscription>();\n\n/**\n * Cache of snapshot functions per instanceId to maintain referential stability\n */\nconst snapshotCache = new Map<UniqueId, () => CameraState>();\n\n/**\n * Cache of fallback snapshots per instanceId to maintain referential stability.\n * This prevents unnecessary re-renders when no camera data exists yet.\n */\nconst fallbackCache = new Map<UniqueId, CameraState>();\n\n/*\n * Helper to build initial camera state from partial input\n */\nfunction buildInitialCameraState(\n initialCameraState?: Partial<CameraState>,\n): CameraState {\n if (!initialCameraState) {\n return {\n latitude: 0,\n longitude: 0,\n zoom: 0,\n pitch: 0,\n rotation: 0,\n projection: 'mercator',\n view: '2D',\n };\n }\n\n const is2Point5D = initialCameraState.view === '2.5D';\n const is3D =\n initialCameraState.view === '3D' ||\n initialCameraState.projection === 'globe';\n\n let projection: ProjectionType;\n let view: ViewType;\n\n if (is3D) {\n projection = 'globe';\n view = '3D';\n } else if (is2Point5D) {\n projection = 'mercator';\n view = '2.5D';\n } else {\n projection = initialCameraState.projection ?? 'mercator';\n view = initialCameraState.view ?? '2D';\n }\n\n return {\n latitude: initialCameraState.latitude ?? 0,\n longitude: initialCameraState.longitude ?? 0,\n zoom: initialCameraState.zoom ?? 0,\n pitch: is2Point5D ? (initialCameraState.pitch ?? 45) : 0,\n rotation: is3D ? 0 : (initialCameraState.rotation ?? 0),\n projection,\n view,\n } as CameraState;\n}\n\n/*\n * Get or create camera state for a given instanceId\n */\nfunction getOrCreateState(\n instanceId: UniqueId,\n initialCameraState?: Partial<CameraState>,\n): CameraState {\n if (!cameraStore.has(instanceId)) {\n cameraStore.set(instanceId, buildInitialCameraState(initialCameraState));\n }\n // biome-ignore lint/style/noNonNullAssertion: State guaranteed to exist after has() check above\n return cameraStore.get(instanceId)!;\n}\n\n/**\n * Notify all React subscribers for a given instanceId\n */\nfunction notifySubscribers(instanceId: UniqueId): void {\n const subscribers = componentSubscribers.get(instanceId);\n\n if (subscribers) {\n for (const onStoreChange of subscribers) {\n onStoreChange();\n }\n }\n}\n\n/**\n * Ensures a single bus listener exists for the given instanceId.\n * All React subscribers will be notified via fan-out when the bus event fires.\n * This prevents creating N bus listeners for N React components.\n *\n * @param instanceId - The unique identifier for the camera\n * @param initialCameraState - Optional initial camera state to set when creating the listener\n */\nfunction ensureBusListener(\n instanceId: UniqueId,\n initialCameraState?: Partial<CameraState>,\n): void {\n if (busUnsubscribers.has(instanceId)) {\n return; // Already listening\n }\n\n const unsubResetCamera = cameraBus.on(\n CameraEventTypes.reset,\n ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = {\n ...buildInitialCameraState({\n ...state,\n zoom:\n payload.zoom === false ? state.zoom : initialCameraState?.zoom,\n pitch:\n payload.pitch === false ? state.pitch : initialCameraState?.pitch,\n rotation:\n payload.rotation === false\n ? state.rotation\n : initialCameraState?.rotation,\n } as Partial<CameraState>),\n };\n\n cameraStore.set(instanceId, newState);\n\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubSetCenter = cameraBus.on(\n CameraEventTypes.setCenter,\n ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = {\n ...state,\n latitude: payload.latitude,\n longitude: payload.longitude,\n zoom: payload.zoom ?? state.zoom,\n rotation: payload.heading ?? state.rotation,\n pitch: payload.pitch ?? state.pitch,\n } as CameraState;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubFitBounds = cameraBus.on(\n CameraEventTypes.fitBounds,\n ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const { longitude, latitude, zoom } = fitBounds({\n width: payload.width,\n height: payload.height,\n bounds: [\n [payload.bounds[0], payload.bounds[1]],\n [payload.bounds[2], payload.bounds[3]],\n ],\n padding: payload.padding,\n });\n const newState = {\n ...state,\n latitude: latitude,\n longitude: longitude,\n zoom: zoom,\n rotation: payload.heading ?? state.rotation,\n pitch: payload.pitch ?? state.pitch,\n } as CameraState;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubSetProjection = cameraBus.on(\n CameraEventTypes.setProjection,\n ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = { ...state };\n newState.projection = payload.projection;\n if (payload.projection === 'globe') {\n newState.view = '3D';\n } else {\n newState.view = '2D';\n newState.pitch = 0;\n }\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubSetView = cameraBus.on(CameraEventTypes.setView, ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = { ...state };\n newState.view = payload.view;\n if (payload.view === '3D') {\n newState.projection = 'globe';\n newState.pitch = 0;\n } else {\n newState.projection = 'mercator';\n }\n\n if (payload.view === '2.5D') {\n newState.pitch = 45;\n }\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n });\n\n const unsubSetZoom = cameraBus.on(CameraEventTypes.setZoom, ({ payload }) => {\n if (instanceId === payload.id) {\n const state = getOrCreateState(instanceId, initialCameraState);\n const newState = { ...state };\n newState.zoom = payload.zoom;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n });\n\n const unsubSetRotation = cameraBus.on(\n CameraEventTypes.setRotation,\n ({ payload }) => {\n const state = getOrCreateState(instanceId, initialCameraState);\n if (instanceId === payload.id && state.view !== '3D') {\n const newState = { ...state };\n newState.rotation = payload.rotation;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n const unsubSetPitch = cameraBus.on(\n CameraEventTypes.setPitch,\n ({ payload }) => {\n const state = getOrCreateState(instanceId, initialCameraState);\n if (instanceId === payload.id && state.view === '2.5D') {\n const newState = { ...state };\n newState.pitch = payload.pitch;\n cameraStore.set(instanceId, newState);\n notifySubscribers(instanceId);\n }\n },\n );\n\n busUnsubscribers.set(instanceId, () => {\n unsubResetCamera();\n unsubSetCenter();\n unsubFitBounds();\n unsubSetProjection();\n unsubSetView();\n unsubSetZoom();\n unsubSetRotation();\n unsubSetPitch();\n });\n}\n\n/**\n * Cleans up the bus listener if no React subscribers remain.\n *\n * @param instanceId - The unique identifier for the camera\n */\nfunction cleanupBusListenerIfNeeded(instanceId: UniqueId): void {\n const subscribers = componentSubscribers.get(instanceId);\n\n if (!subscribers || subscribers.size === 0) {\n // No more React subscribers - clean up bus listener\n const unsub = busUnsubscribers.get(instanceId);\n if (unsub) {\n unsub();\n busUnsubscribers.delete(instanceId);\n }\n\n // Clean up all state\n [\n cameraStore,\n componentSubscribers,\n subscriptionCache,\n snapshotCache,\n fallbackCache,\n ].forEach((map) => {\n map.delete(instanceId);\n });\n }\n}\n\n/**\n * Creates or retrieves a cached subscription function for a given instanceId.\n * Uses a fan-out pattern: 1 bus listener -> N React subscribers.\n * Automatically cleans up camera state when the last subscriber unsubscribes.\n *\n * @param instanceId - The unique identifier for the camera\n * @param initialCameraState - Optional initial camera state to set when creating the listener\n * @returns A subscription function for useSyncExternalStore\n */\nfunction getOrCreateSubscription(\n instanceId: UniqueId,\n initialCameraState?: Partial<CameraState>,\n): (onStoreChange: () => void) => () => void {\n const subscription =\n subscriptionCache.get(instanceId) ??\n ((onStoreChange: () => void) => {\n // Ensure single bus listener exists for this instanceId\n ensureBusListener(instanceId, initialCameraState);\n\n // Get or create the subscriber set for this map instance, then add this component's callback\n let subscriberSet = componentSubscribers.get(instanceId);\n if (!subscriberSet) {\n subscriberSet = new Set();\n componentSubscribers.set(instanceId, subscriberSet);\n }\n subscriberSet.add(onStoreChange);\n\n // Return cleanup function to remove this component's subscription\n return () => {\n const currentSubscriberSet = componentSubscribers.get(instanceId);\n if (currentSubscriberSet) {\n currentSubscriberSet.delete(onStoreChange);\n }\n\n // Clean up bus listener if this was the last React subscriber\n cleanupBusListenerIfNeeded(instanceId);\n };\n });\n\n subscriptionCache.set(instanceId, subscription);\n\n return subscription;\n}\n\n/**\n * Creates or retrieves a cached snapshot function for a given instanceId.\n * The object returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.\n *\n * @param instanceId - The unique identifier for the camera\n * @param initialCameraState - Initialize the snapshot with camera view information\n * @returns A snapshot function for useSyncExternalStore\n */\nfunction getOrCreateSnapshot(\n instanceId: UniqueId,\n initialCameraState?: Partial<CameraState>,\n): () => CameraState {\n // Get or create stable fallback reference for this instanceId\n const fallback =\n fallbackCache.get(instanceId) ??\n (() => {\n const newFallback: CameraState = {\n latitude: initialCameraState?.latitude ?? 0,\n longitude: initialCameraState?.longitude ?? 0,\n zoom: initialCameraState?.zoom ?? 0,\n pitch: 0,\n rotation: 0,\n projection: 'mercator',\n view: '2D',\n };\n fallbackCache.set(instanceId, newFallback);\n return newFallback;\n })();\n\n const snapshot =\n snapshotCache.get(instanceId) ??\n (() => cameraStore.get(instanceId) ?? fallback);\n\n snapshotCache.set(instanceId, snapshot);\n\n return snapshot;\n}\n\n/**\n * Updates the camera state for a given map instance and notifies subscribers.\n *\n * @param instanceId - The unique identifier for the map\n * @param state - The new state to set, will be merged with existing state\n *\n * @example\n * ```tsx\n * // Update camera state manually\n * setCameraState('my-map-instance', {\n * latitude: 37.7749,\n * longitude: -122.4194,\n * zoom: 10,\n * pitch: 30,\n * rotation: 0,\n * projection: 'mercator',\n * });\n * ```\n */\nfunction setCameraState(\n instanceId: UniqueId,\n state: Partial<CameraState>,\n): void {\n const currentState = getOrCreateState(instanceId);\n cameraStore.set(instanceId, { ...currentState, ...state } as CameraState);\n notifySubscribers(instanceId);\n}\n\n/**\n * Hook to access camera state actions.\n *\n * This hook uses `useSyncExternalStore` to subscribe to camera state changes,\n * providing concurrent-safe mode state updates. Uses a fan-out pattern where\n * a single bus listener per map instance notifies N React component subscribers.\n *\n * A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).\n *\n * @param instanceId - Unique identifier for the camera to track\n * @param initialCameraState - Optional initial camera state to set\n * @param subscribe - Optional custom subscription function\n * @param getSnapshot - Optional custom snapshot getter\n * @param getServerSnapshot - Optional server-side snapshot getter\n * @returns Current camera state including latitude, longitude, zoom, pitch, rotation, projection\n *\n * @example\n * ```tsx\n * function MapInfo({ instanceId }) {\n * const { latitude, longitude, zoom } = useCameraState({\n * instanceId\n * });\n *\n * return (\n * <div>\n * Lat: {latitude?.toFixed(2)}, Lon: {longitude?.toFixed(2)}, Zoom: {zoom}\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With custom subscribe/getSnapshot for advanced use cases\n * function CustomMapInfo() {\n * const customSubscribe = (onStoreChange) => {\n * // Custom subscription logic\n * return () => { // cleanup }\n * }\n *\n * const customGetSnapshot = () => {\n * // Custom snapshot logic\n * return { latitude: 0, longitude: 0, zoom: 1 };\n * };\n *\n * const viewState = useCameraState({\n * instanceId: 'some-uuid',\n * subscribe: customSubscribe,\n * getSnapshot: customGetSnapshot,\n * });\n *\n * return <div>Custom camera state</div>;\n * }\n * ```\n */\nexport function useCameraState({\n instanceId,\n initialCameraState,\n subscribe,\n getSnapshot,\n getServerSnapshot,\n}: UseCameraStateProps) {\n const cameraState = useSyncExternalStore<CameraState>(\n subscribe ?? getOrCreateSubscription(instanceId, initialCameraState),\n getSnapshot ?? getOrCreateSnapshot(instanceId, initialCameraState),\n getServerSnapshot,\n );\n\n return useMemo(\n () => ({\n cameraState,\n setCameraState,\n }),\n [cameraState],\n );\n}\n\n/**\n * Manually clear camera state for a specific instanceId.\n * This is typically not needed as cleanup happens automatically when all subscribers unmount.\n * Use this only in advanced scenarios where manual cleanup is required.\n *\n * @param instanceId - The unique identifier for the camera to clear\n *\n * @example\n * ```tsx\n * // Manual cleanup (rarely needed)\n * clearCameraState('my-map-instance');\n * ```\n */\nexport function clearCameraState(instanceId: UniqueId): void {\n // Unsubscribe from bus if listening\n const unsub = busUnsubscribers.get(instanceId);\n if (unsub) {\n unsub();\n busUnsubscribers.delete(instanceId);\n }\n\n // Clear all state\n [\n cameraStore,\n componentSubscribers,\n subscriptionCache,\n snapshotCache,\n fallbackCache,\n ].forEach((map) => {\n map.delete(instanceId);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,YAAY,UAAU,aAA0B;;;;AA6CtD,MAAM,8BAAc,IAAI,KAA4B;;;;;AAMpD,MAAM,uCAAuB,IAAI,KAAgC;;;;;;AAOjE,MAAM,mCAAmB,IAAI,KAA2B;;;;AAMxD,MAAM,oCAAoB,IAAI,KAA6B;;;;AAK3D,MAAM,gCAAgB,IAAI,KAAkC;;;;;AAM5D,MAAM,gCAAgB,IAAI,KAA4B;AAKtD,SAAS,wBACP,oBACa;AACb,KAAI,CAAC,mBACH,QAAO;EACL,UAAU;EACV,WAAW;EACX,MAAM;EACN,OAAO;EACP,UAAU;EACV,YAAY;EACZ,MAAM;EACP;CAGH,MAAM,aAAa,mBAAmB,SAAS;CAC/C,MAAM,OACJ,mBAAmB,SAAS,QAC5B,mBAAmB,eAAe;CAEpC,IAAIA;CACJ,IAAIC;AAEJ,KAAI,MAAM;AACR,eAAa;AACb,SAAO;YACE,YAAY;AACrB,eAAa;AACb,SAAO;QACF;AACL,eAAa,mBAAmB,cAAc;AAC9C,SAAO,mBAAmB,QAAQ;;AAGpC,QAAO;EACL,UAAU,mBAAmB,YAAY;EACzC,WAAW,mBAAmB,aAAa;EAC3C,MAAM,mBAAmB,QAAQ;EACjC,OAAO,aAAc,mBAAmB,SAAS,KAAM;EACvD,UAAU,OAAO,IAAK,mBAAmB,YAAY;EACrD;EACA;EACD;;AAMH,SAAS,iBACP,YACA,oBACa;AACb,KAAI,CAAC,YAAY,IAAI,WAAW,CAC9B,aAAY,IAAI,YAAY,wBAAwB,mBAAmB,CAAC;AAG1E,QAAO,YAAY,IAAI,WAAW;;;;;AAMpC,SAAS,kBAAkB,YAA4B;CACrD,MAAM,cAAc,qBAAqB,IAAI,WAAW;AAExD,KAAI,YACF,MAA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O,cAAc;AAI5C,8BAA2B,WAAW;;;AAI5C,mBAAkB,IAAI,YAAY,aAAa;AAE/C,QAAO;;;;;;;;;;AAWT,SAAS,oBACP,YACA,oBACmB;CAEnB,MAAM,WACJ,cAAc,IAAI,WAAW,WACtB;EACL,MAAMC,cAA2B;GAC/B,UAAU,oBAAoB,YAAY;GAC1C,WAAW,oBAAoB,aAAa;GAC5C,MAAM,oBAAoB,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GACZ,MAAM;GACP;AACD,gBAAc,IAAI,YAAY,YAAY;AAC1C,SAAO;KACL;CAEN,MAAM,WACJ,cAAc,IAAI,WAAW,WACtB,YAAY,IAAI,WAAW,IAAI;AAExC,eAAc,IAAI,YAAY,SAAS;AAEvC,QAAO;;;;;;;;;;;;;;;;;;;;;AAsBT,SAAS,eACP,YACA,OACM;CACN,MAAM,eAAe,iBAAiB,WAAW;AACjD,aAAY,IAAI,YAAY;EAAE,GAAG;EAAc,GAAG;EAAO,CAAgB;AACzE,mBAAkB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0D/B,SAAgB,eAAe,EAC7B,YACA,oBACA,WACA,aACA,qBACsB;CACtB,MAAM,cAAc,qBAClB,aAAa,wBAAwB,YAAY,mBAAmB,EACpE,eAAe,oBAAoB,YAAY,mBAAmB,EAClE,kBACD;AAED,QAAO,eACE;EACL;EACA;EACD,GACD,CAAC,YAAY,CACd;;;;;;;;;;;;;;;AAgBH,SAAgB,iBAAiB,YAA4B;CAE3D,MAAM,QAAQ,iBAAiB,IAAI,WAAW;AAC9C,KAAI,OAAO;AACT,SAAO;AACP,mBAAiB,OAAO,WAAW;;AAIrC;EACE;EACA;EACA;EACA;EACA;EACD,CAAC,SAAS,QAAQ;AACjB,MAAI,OAAO,WAAW;GACtB"}
@@ -16,8 +16,8 @@
16
16
  import { MapEvents } from "../deckgl/base-map/events.js";
17
17
  import { MapContext } from "../deckgl/base-map/provider.js";
18
18
  import { Broadcast } from "@accelint/bus";
19
- import { coordinateSystems, createCoordinate } from "@accelint/geo";
20
19
  import { useContext, useMemo, useSyncExternalStore } from "react";
20
+ import { coordinateSystems, createCoordinate } from "@accelint/geo";
21
21
 
22
22
  //#region src/cursor-coordinates/use-cursor-coordinates.ts
23
23
  const bus = Broadcast.getInstance();
@@ -1,5 +1,12 @@
1
1
  //#region src/deckgl/base-map/constants.d.ts
2
- declare const BASE_MAP_STYLE = "https://tiles.basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json";
2
+ declare const DARK_BASE_MAP_STYLE = "https://tiles.basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json";
3
+ declare const LIGHT_BASE_MAP_STYLE = "https://tiles.basemaps.cartocdn.com/gl/voyager-gl-style/style.json";
4
+ /**
5
+ * Default picking radius in pixels
6
+ * Creates a 5-pixel detection radius around the pointer for pickable objects
7
+ * Makes thin lines and small shapes easier to hover
8
+ */
9
+ declare const PICKING_RADIUS = 5;
3
10
  declare const PARAMETERS: {
4
11
  depthWriteEnabled: boolean;
5
12
  depthCompare: string;
@@ -13,6 +20,11 @@ declare const PARAMETERS: {
13
20
  blendColorOperation: string;
14
21
  blendAlphaOperation: string;
15
22
  };
23
+ declare const DEFAULT_VIEW_STATE: {
24
+ longitude: number;
25
+ latitude: number;
26
+ zoom: number;
27
+ };
16
28
  //#endregion
17
- export { BASE_MAP_STYLE, PARAMETERS };
29
+ export { DARK_BASE_MAP_STYLE, DEFAULT_VIEW_STATE, LIGHT_BASE_MAP_STYLE, PARAMETERS, PICKING_RADIUS };
18
30
  //# sourceMappingURL=constants.d.ts.map
@@ -12,7 +12,14 @@
12
12
 
13
13
 
14
14
  //#region src/deckgl/base-map/constants.ts
15
- const BASE_MAP_STYLE = "https://tiles.basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json";
15
+ const DARK_BASE_MAP_STYLE = "https://tiles.basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json";
16
+ const LIGHT_BASE_MAP_STYLE = "https://tiles.basemaps.cartocdn.com/gl/voyager-gl-style/style.json";
17
+ /**
18
+ * Default picking radius in pixels
19
+ * Creates a 5-pixel detection radius around the pointer for pickable objects
20
+ * Makes thin lines and small shapes easier to hover
21
+ */
22
+ const PICKING_RADIUS = 5;
16
23
  const PARAMETERS = {
17
24
  depthWriteEnabled: true,
18
25
  depthCompare: "always",
@@ -26,7 +33,12 @@ const PARAMETERS = {
26
33
  blendColorOperation: "add",
27
34
  blendAlphaOperation: "add"
28
35
  };
36
+ const DEFAULT_VIEW_STATE = {
37
+ longitude: -77.0369,
38
+ latitude: 38.9072,
39
+ zoom: 4
40
+ };
29
41
 
30
42
  //#endregion
31
- export { BASE_MAP_STYLE, PARAMETERS };
43
+ export { DARK_BASE_MAP_STYLE, DEFAULT_VIEW_STATE, LIGHT_BASE_MAP_STYLE, PARAMETERS, PICKING_RADIUS };
32
44
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../../../src/deckgl/base-map/constants.ts"],"sourcesContent":["// __private-exports\n/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport const BASE_MAP_STYLE =\n 'https://tiles.basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json';\n\nexport const PARAMETERS = {\n depthWriteEnabled: true,\n depthCompare: 'always',\n depthBias: 0,\n blend: true,\n depthTest: false,\n blendColorSrcFactor: 'src-alpha',\n blendColorDstFactor: 'one-minus-src-alpha',\n blendAlphaSrcFactor: 'one',\n blendAlphaDstFactor: 'one-minus-src-alpha',\n blendColorOperation: 'add',\n blendAlphaOperation: 'add',\n};\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,iBACX;AAEF,MAAa,aAAa;CACxB,mBAAmB;CACnB,cAAc;CACd,WAAW;CACX,OAAO;CACP,WAAW;CACX,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACtB"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../../src/deckgl/base-map/constants.ts"],"sourcesContent":["// __private-exports\n/*\n * Copyright 2026 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport const DARK_BASE_MAP_STYLE =\n 'https://tiles.basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json';\n\nexport const LIGHT_BASE_MAP_STYLE =\n 'https://tiles.basemaps.cartocdn.com/gl/voyager-gl-style/style.json';\n\n/**\n * Default picking radius in pixels\n * Creates a 5-pixel detection radius around the pointer for pickable objects\n * Makes thin lines and small shapes easier to hover\n */\nexport const PICKING_RADIUS = 5;\n\nexport const PARAMETERS = {\n depthWriteEnabled: true,\n depthCompare: 'always',\n depthBias: 0,\n blend: true,\n depthTest: false,\n blendColorSrcFactor: 'src-alpha',\n blendColorDstFactor: 'one-minus-src-alpha',\n blendAlphaSrcFactor: 'one',\n blendAlphaDstFactor: 'one-minus-src-alpha',\n blendColorOperation: 'add',\n blendAlphaOperation: 'add',\n};\n\nexport const DEFAULT_VIEW_STATE = {\n longitude: -77.0369,\n latitude: 38.9072,\n zoom: 4,\n};\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,sBACX;AAEF,MAAa,uBACX;;;;;;AAOF,MAAa,iBAAiB;AAE9B,MAAa,aAAa;CACxB,mBAAmB;CACnB,cAAc;CACd,WAAW;CACX,OAAO;CACP,WAAW;CACX,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACtB;AAED,MAAa,qBAAqB;CAChC,WAAW;CACX,UAAU;CACV,MAAM;CACP"}
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at https://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import { RefObject } from "react";
14
+ import { UniqueId } from "@accelint/core";
15
+ import { MapRef } from "react-map-gl/maplibre";
16
+
17
+ //#region src/deckgl/base-map/controls.d.ts
18
+ type MapControlsProps = {
19
+ id: UniqueId;
20
+ mapRef: RefObject<MapRef | null>;
21
+ };
22
+ /**
23
+ * Headless component that listens for map control events and applies them to the MapLibre instance.
24
+ *
25
+ * This component is rendered inside BaseMap to wire up event listeners
26
+ * for pan and zoom control events.
27
+ */
28
+ declare function MapControls({
29
+ id,
30
+ mapRef
31
+ }: MapControlsProps): null;
32
+ //#endregion
33
+ export { MapControls };
34
+ //# sourceMappingURL=controls.d.ts.map
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at https://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+
14
+ 'use client';
15
+
16
+ import { MapEvents } from "./events.js";
17
+ import { useOn } from "@accelint/bus/react";
18
+
19
+ //#region src/deckgl/base-map/controls.tsx
20
+ /**
21
+ * Headless component that listens for map control events and applies them to the MapLibre instance.
22
+ *
23
+ * This component is rendered inside BaseMap to wire up event listeners
24
+ * for pan and zoom control events.
25
+ */
26
+ function MapControls({ id, mapRef }) {
27
+ useOn(MapEvents.enablePan, (event) => {
28
+ if (event.payload.id === id) mapRef.current?.getMap().dragPan.enable();
29
+ });
30
+ useOn(MapEvents.disablePan, (event) => {
31
+ if (event.payload.id === id) mapRef.current?.getMap().dragPan.disable();
32
+ });
33
+ useOn(MapEvents.enableZoom, (event) => {
34
+ if (event.payload.id === id) {
35
+ mapRef.current?.getMap().scrollZoom.enable();
36
+ mapRef.current?.getMap().doubleClickZoom.enable();
37
+ }
38
+ });
39
+ useOn(MapEvents.disableZoom, (event) => {
40
+ if (event.payload.id === id) {
41
+ mapRef.current?.getMap().scrollZoom.disable();
42
+ mapRef.current?.getMap().doubleClickZoom.disable();
43
+ }
44
+ });
45
+ return null;
46
+ }
47
+
48
+ //#endregion
49
+ export { MapControls };
50
+ //# sourceMappingURL=controls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controls.js","names":[],"sources":["../../../src/deckgl/base-map/controls.tsx"],"sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n'use client';\n\nimport 'client-only';\nimport { useOn } from '@accelint/bus/react';\nimport { MapEvents } from './events';\nimport type { UniqueId } from '@accelint/core';\nimport type { RefObject } from 'react';\nimport type { MapRef } from 'react-map-gl/maplibre';\nimport type {\n MapDisablePanEvent,\n MapDisableZoomEvent,\n MapEnablePanEvent,\n MapEnableZoomEvent,\n} from './types';\n\ntype MapControlsProps = {\n id: UniqueId;\n mapRef: RefObject<MapRef | null>;\n};\n\n/**\n * Headless component that listens for map control events and applies them to the MapLibre instance.\n *\n * This component is rendered inside BaseMap to wire up event listeners\n * for pan and zoom control events.\n */\nexport function MapControls({ id, mapRef }: MapControlsProps) {\n useOn<MapEnablePanEvent>(MapEvents.enablePan, (event) => {\n if (event.payload.id === id) {\n mapRef.current?.getMap().dragPan.enable();\n }\n });\n\n useOn<MapDisablePanEvent>(MapEvents.disablePan, (event) => {\n if (event.payload.id === id) {\n mapRef.current?.getMap().dragPan.disable();\n }\n });\n\n useOn<MapEnableZoomEvent>(MapEvents.enableZoom, (event) => {\n if (event.payload.id === id) {\n mapRef.current?.getMap().scrollZoom.enable();\n mapRef.current?.getMap().doubleClickZoom.enable();\n }\n });\n\n useOn<MapDisableZoomEvent>(MapEvents.disableZoom, (event) => {\n if (event.payload.id === id) {\n mapRef.current?.getMap().scrollZoom.disable();\n mapRef.current?.getMap().doubleClickZoom.disable();\n }\n });\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,YAAY,EAAE,IAAI,UAA4B;AAC5D,OAAyB,UAAU,YAAY,UAAU;AACvD,MAAI,MAAM,QAAQ,OAAO,GACvB,QAAO,SAAS,QAAQ,CAAC,QAAQ,QAAQ;GAE3C;AAEF,OAA0B,UAAU,aAAa,UAAU;AACzD,MAAI,MAAM,QAAQ,OAAO,GACvB,QAAO,SAAS,QAAQ,CAAC,QAAQ,SAAS;GAE5C;AAEF,OAA0B,UAAU,aAAa,UAAU;AACzD,MAAI,MAAM,QAAQ,OAAO,IAAI;AAC3B,UAAO,SAAS,QAAQ,CAAC,WAAW,QAAQ;AAC5C,UAAO,SAAS,QAAQ,CAAC,gBAAgB,QAAQ;;GAEnD;AAEF,OAA2B,UAAU,cAAc,UAAU;AAC3D,MAAI,MAAM,QAAQ,OAAO,IAAI;AAC3B,UAAO,SAAS,QAAQ,CAAC,WAAW,SAAS;AAC7C,UAAO,SAAS,QAAQ,CAAC,gBAAgB,SAAS;;GAEpD;AAEF,QAAO"}
@@ -4,6 +4,10 @@ declare const MapEvents: {
4
4
  readonly click: "map:click";
5
5
  readonly hover: "map:hover";
6
6
  readonly viewport: "map:viewport";
7
+ readonly enablePan: "map:enablePan";
8
+ readonly disablePan: "map:disablePan";
9
+ readonly enableZoom: "map:enableZoom";
10
+ readonly disableZoom: "map:disableZoom";
7
11
  };
8
12
  //#endregion
9
13
  export { MapEvents, MapEventsNamespace };
@@ -16,7 +16,11 @@ const MapEventsNamespace = "map";
16
16
  const MapEvents = {
17
17
  click: `${MapEventsNamespace}:click`,
18
18
  hover: `${MapEventsNamespace}:hover`,
19
- viewport: `${MapEventsNamespace}:viewport`
19
+ viewport: `${MapEventsNamespace}:viewport`,
20
+ enablePan: `${MapEventsNamespace}:enablePan`,
21
+ disablePan: `${MapEventsNamespace}:disablePan`,
22
+ enableZoom: `${MapEventsNamespace}:enableZoom`,
23
+ disableZoom: `${MapEventsNamespace}:disableZoom`
20
24
  };
21
25
 
22
26
  //#endregion