@accelint/map-toolkit 0.6.0 → 1.1.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.
- package/CHANGELOG.md +81 -0
- package/catalog-info.yaml +7 -6
- package/dist/camera/events.js.map +1 -1
- package/dist/camera/index.d.ts +2 -2
- package/dist/camera/index.js +2 -2
- package/dist/camera/store.d.ts +120 -0
- package/dist/camera/store.js +279 -0
- package/dist/camera/store.js.map +1 -0
- package/dist/cursor-coordinates/index.d.ts +4 -2
- package/dist/cursor-coordinates/index.js +3 -2
- package/dist/cursor-coordinates/store.d.ts +48 -0
- package/dist/cursor-coordinates/store.js +92 -0
- package/dist/cursor-coordinates/store.js.map +1 -0
- package/dist/cursor-coordinates/types.d.ts +87 -0
- package/dist/cursor-coordinates/types.js +12 -0
- package/dist/cursor-coordinates/use-cursor-coordinates.d.ts +41 -37
- package/dist/cursor-coordinates/use-cursor-coordinates.js +131 -202
- package/dist/cursor-coordinates/use-cursor-coordinates.js.map +1 -1
- package/dist/deckgl/base-map/constants.d.ts +1 -6
- package/dist/deckgl/base-map/constants.js +1 -6
- package/dist/deckgl/base-map/constants.js.map +1 -1
- package/dist/deckgl/base-map/controls.js +2 -0
- package/dist/deckgl/base-map/controls.js.map +1 -1
- package/dist/deckgl/base-map/events.js.map +1 -1
- package/dist/deckgl/base-map/index.d.ts +2 -2
- package/dist/deckgl/base-map/index.js +10 -11
- package/dist/deckgl/base-map/index.js.map +1 -1
- package/dist/deckgl/base-map/provider.d.ts +2 -2
- package/dist/deckgl/base-map/provider.js +1 -1
- package/dist/deckgl/base-map/provider.js.map +1 -1
- package/dist/deckgl/index.d.ts +4 -4
- package/dist/deckgl/index.js +4 -4
- package/dist/deckgl/saved-viewports/index.js.map +1 -1
- package/dist/deckgl/saved-viewports/storage.js +10 -2
- package/dist/deckgl/saved-viewports/storage.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/constants.js +5 -8
- package/dist/deckgl/shapes/display-shape-layer/constants.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/fiber.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/index.d.ts +18 -14
- package/dist/deckgl/shapes/display-shape-layer/index.js +63 -30
- package/dist/deckgl/shapes/display-shape-layer/index.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.js +2 -16
- package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/store.js +58 -272
- package/dist/deckgl/shapes/display-shape-layer/store.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/types.d.ts +22 -11
- package/dist/deckgl/shapes/display-shape-layer/{use-shape-selection.d.ts → use-select-shape.d.ts} +9 -9
- package/dist/deckgl/shapes/display-shape-layer/{use-shape-selection.js → use-select-shape.js} +12 -12
- package/dist/deckgl/shapes/display-shape-layer/use-select-shape.js.map +1 -0
- package/dist/deckgl/shapes/display-shape-layer/utils/display-style.js +5 -66
- package/dist/deckgl/shapes/display-shape-layer/utils/display-style.js.map +1 -1
- package/dist/deckgl/shapes/display-shape-layer/utils/labels.d.ts +2 -65
- package/dist/deckgl/shapes/display-shape-layer/utils/labels.js +3 -121
- package/dist/deckgl/shapes/display-shape-layer/utils/labels.js.map +1 -1
- package/dist/deckgl/shapes/draw-shape-layer/constants.js +46 -0
- package/dist/deckgl/shapes/draw-shape-layer/constants.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/events.d.ts +92 -0
- package/dist/deckgl/shapes/draw-shape-layer/events.js +56 -0
- package/dist/deckgl/shapes/draw-shape-layer/events.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/fiber.d.ts +11 -0
- package/dist/{maplibre/constants.js → deckgl/shapes/draw-shape-layer/fiber.js} +6 -12
- package/dist/deckgl/shapes/draw-shape-layer/fiber.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/index.d.ts +53 -0
- package/dist/deckgl/shapes/draw-shape-layer/index.js +95 -0
- package/dist/deckgl/shapes/draw-shape-layer/index.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-circle-mode-with-tooltip.js +51 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-circle-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-ellipse-mode-with-tooltip.js +73 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-ellipse-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-line-string-mode-with-tooltip.js +87 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-line-string-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-polygon-mode-with-tooltip.js +88 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-polygon-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-rectangle-mode-with-tooltip.js +77 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/draw-rectangle-mode-with-tooltip.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/index.js +64 -0
- package/dist/deckgl/shapes/draw-shape-layer/modes/index.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/store.js +175 -0
- package/dist/deckgl/shapes/draw-shape-layer/store.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/types.d.ts +86 -0
- package/dist/{viewport/constants.js → deckgl/shapes/draw-shape-layer/types.js} +1 -12
- package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.d.ts +82 -0
- package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.js +112 -0
- package/dist/deckgl/shapes/draw-shape-layer/use-draw-shape.js.map +1 -0
- package/dist/deckgl/shapes/draw-shape-layer/utils/feature-conversion.js +147 -0
- package/dist/deckgl/shapes/draw-shape-layer/utils/feature-conversion.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/constants.js +41 -0
- package/dist/deckgl/shapes/edit-shape-layer/constants.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/events.d.ts +92 -0
- package/dist/deckgl/shapes/edit-shape-layer/events.js +56 -0
- package/dist/deckgl/shapes/edit-shape-layer/events.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/fiber.d.ts +13 -0
- package/dist/deckgl/shapes/edit-shape-layer/fiber.js +14 -0
- package/dist/deckgl/shapes/edit-shape-layer/index.d.ts +63 -0
- package/dist/deckgl/shapes/edit-shape-layer/index.js +162 -0
- package/dist/deckgl/shapes/edit-shape-layer/index.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/base-transform-mode.js +154 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/base-transform-mode.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/bounding-transform-mode.js +147 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/bounding-transform-mode.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/circle-transform-mode.js +87 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/circle-transform-mode.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/index.js +61 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/index.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/rotate-mode-with-snap.js +109 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/rotate-mode-with-snap.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/scale-mode-with-free-transform.js +289 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/scale-mode-with-free-transform.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/vertex-transform-mode.js +121 -0
- package/dist/deckgl/shapes/edit-shape-layer/modes/vertex-transform-mode.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/store.js +194 -0
- package/dist/deckgl/shapes/edit-shape-layer/store.js.map +1 -0
- package/dist/deckgl/shapes/edit-shape-layer/types.d.ts +93 -0
- package/dist/deckgl/shapes/edit-shape-layer/types.js +14 -0
- package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.d.ts +82 -0
- package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.js +114 -0
- package/dist/deckgl/shapes/edit-shape-layer/use-edit-shape.js.map +1 -0
- package/dist/deckgl/shapes/index.d.ts +15 -6
- package/dist/deckgl/shapes/index.js +12 -5
- package/dist/deckgl/shapes/shared/constants.d.ts +27 -32
- package/dist/deckgl/shapes/shared/constants.js +189 -25
- package/dist/deckgl/shapes/shared/constants.js.map +1 -1
- package/dist/deckgl/shapes/shared/events.d.ts +1 -20
- package/dist/deckgl/shapes/shared/events.js +1 -31
- package/dist/deckgl/shapes/shared/events.js.map +1 -1
- package/dist/deckgl/shapes/shared/hooks/use-shift-zoom-disable.js +84 -0
- package/dist/deckgl/shapes/shared/hooks/use-shift-zoom-disable.js.map +1 -0
- package/dist/deckgl/shapes/shared/types.d.ts +187 -28
- package/dist/deckgl/shapes/shared/types.js +55 -1
- package/dist/deckgl/shapes/shared/types.js.map +1 -1
- package/dist/deckgl/shapes/shared/utils/geometry-measurements.js +128 -0
- package/dist/deckgl/shapes/shared/utils/geometry-measurements.js.map +1 -0
- package/dist/deckgl/shapes/shared/utils/layer-config.js +50 -0
- package/dist/deckgl/shapes/shared/utils/layer-config.js.map +1 -0
- package/dist/deckgl/shapes/shared/utils/mode-utils.js +113 -0
- package/dist/deckgl/shapes/shared/utils/mode-utils.js.map +1 -0
- package/dist/deckgl/shapes/shared/utils/pick-filtering.js +57 -0
- package/dist/deckgl/shapes/shared/utils/pick-filtering.js.map +1 -0
- package/dist/deckgl/shapes/shared/utils/style-utils.d.ts +64 -0
- package/dist/deckgl/shapes/shared/utils/style-utils.js +101 -0
- package/dist/deckgl/shapes/shared/utils/style-utils.js.map +1 -0
- package/dist/deckgl/symbol-layer/fiber.js.map +1 -1
- package/dist/deckgl/symbol-layer/index.js.map +1 -1
- package/dist/deckgl/text-layer/character-sets.js.map +1 -1
- package/dist/deckgl/text-layer/default-settings.js +4 -24
- package/dist/deckgl/text-layer/default-settings.js.map +1 -1
- package/dist/deckgl/text-layer/fiber.js.map +1 -1
- package/dist/deckgl/text-layer/index.js.map +1 -1
- package/dist/deckgl/text-settings.d.ts +77 -0
- package/dist/deckgl/text-settings.js +83 -0
- package/dist/deckgl/text-settings.js.map +1 -0
- package/dist/map-cursor/events.js.map +1 -1
- package/dist/map-cursor/index.d.ts +2 -2
- package/dist/map-cursor/index.js +2 -2
- package/dist/map-cursor/store.d.ts +32 -61
- package/dist/map-cursor/store.js +165 -294
- package/dist/map-cursor/store.js.map +1 -1
- package/dist/map-cursor/use-map-cursor.d.ts +5 -2
- package/dist/map-cursor/use-map-cursor.js +33 -15
- package/dist/map-cursor/use-map-cursor.js.map +1 -1
- package/dist/map-mode/events.js.map +1 -1
- package/dist/map-mode/index.d.ts +2 -2
- package/dist/map-mode/index.js +2 -2
- package/dist/map-mode/store.d.ts +36 -37
- package/dist/map-mode/store.js +131 -237
- package/dist/map-mode/store.js.map +1 -1
- package/dist/map-mode/use-map-mode.js +6 -5
- package/dist/map-mode/use-map-mode.js.map +1 -1
- package/dist/maplibre/hooks/use-maplibre.js.map +1 -1
- package/dist/maplibre/index.d.ts +2 -2
- package/dist/maplibre/index.js +2 -2
- package/dist/shared/constants.d.ts +19 -0
- package/dist/shared/constants.js +33 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/create-map-store.d.ts +202 -0
- package/dist/shared/create-map-store.js +223 -0
- package/dist/shared/create-map-store.js.map +1 -0
- package/dist/shared/units.d.ts +39 -0
- package/dist/shared/units.js +49 -0
- package/dist/shared/units.js.map +1 -0
- package/dist/viewport/index.d.ts +3 -3
- package/dist/viewport/index.js +3 -3
- package/dist/viewport/store.d.ts +69 -0
- package/dist/viewport/store.js +125 -0
- package/dist/viewport/store.js.map +1 -0
- package/dist/viewport/types.d.ts +2 -2
- package/dist/viewport/utils.js +2 -2
- package/dist/viewport/utils.js.map +1 -1
- package/dist/viewport/viewport-size.d.ts +2 -2
- package/dist/viewport/viewport-size.js +2 -2
- package/dist/viewport/viewport-size.js.map +1 -1
- package/package.json +39 -19
- package/dist/camera/use-camera-state.d.ts +0 -153
- package/dist/camera/use-camera-state.js +0 -418
- package/dist/camera/use-camera-state.js.map +0 -1
- package/dist/deckgl/shapes/display-shape-layer/constants.d.ts +0 -44
- package/dist/deckgl/shapes/display-shape-layer/shape-label-layer.d.ts +0 -66
- package/dist/deckgl/shapes/display-shape-layer/store.d.ts +0 -87
- package/dist/deckgl/shapes/display-shape-layer/use-shape-selection.js.map +0 -1
- package/dist/deckgl/shapes/display-shape-layer/utils/display-style.d.ts +0 -61
- package/dist/maplibre/constants.d.ts +0 -13
- package/dist/maplibre/constants.js.map +0 -1
- package/dist/viewport/constants.d.ts +0 -11
- package/dist/viewport/constants.js.map +0 -1
- package/dist/viewport/use-viewport-state.d.ts +0 -100
- package/dist/viewport/use-viewport-state.js +0 -222
- package/dist/viewport/use-viewport-state.js.map +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
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 { createMapStore } from "../shared/create-map-store.js";
|
|
15
|
+
import { MapEvents } from "../deckgl/base-map/events.js";
|
|
16
|
+
import { Broadcast } from "@accelint/bus";
|
|
17
|
+
|
|
18
|
+
//#region src/cursor-coordinates/store.ts
|
|
19
|
+
/**
|
|
20
|
+
* Cursor Coordinates Store
|
|
21
|
+
*
|
|
22
|
+
* Manages cursor coordinate state for map instances using the shared store factory.
|
|
23
|
+
* Subscribes to hover events from the map and stores the current cursor position.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { cursorCoordinateStore } from './store';
|
|
28
|
+
*
|
|
29
|
+
* // Use in a component
|
|
30
|
+
* function CoordinateDisplay({ mapId }) {
|
|
31
|
+
* const { state, setFormat } = cursorCoordinateStore.use(mapId);
|
|
32
|
+
* return <div>{state.coordinate ? `${state.coordinate[0]}, ${state.coordinate[1]}` : '--'}</div>;
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* // Or use the selector for specific values
|
|
36
|
+
* const coord = cursorCoordinateStore.useSelector(mapId, (s) => s.coordinate);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
const bus = Broadcast.getInstance();
|
|
40
|
+
/**
|
|
41
|
+
* Type guard to validate that a value is a proper coordinate tuple.
|
|
42
|
+
* Checks that the value is an array with exactly two finite numbers.
|
|
43
|
+
*
|
|
44
|
+
* @param value - Value to validate as a coordinate
|
|
45
|
+
* @returns True if value is a valid [longitude, latitude] tuple
|
|
46
|
+
*/
|
|
47
|
+
function isValidCoordinate(value) {
|
|
48
|
+
return Array.isArray(value) && value.length === 2 && value.every(Number.isFinite);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Cursor coordinates store
|
|
52
|
+
*
|
|
53
|
+
* Stores the current cursor position and display format for each map instance.
|
|
54
|
+
* Automatically subscribes to hover events when first React subscriber mounts.
|
|
55
|
+
*/
|
|
56
|
+
const cursorCoordinateStore = createMapStore({
|
|
57
|
+
defaultState: {
|
|
58
|
+
coordinate: null,
|
|
59
|
+
format: "dd"
|
|
60
|
+
},
|
|
61
|
+
actions: (_mapId, { set }) => ({ setFormat: (format) => {
|
|
62
|
+
set({ format });
|
|
63
|
+
} }),
|
|
64
|
+
bus: (mapId, { set }) => {
|
|
65
|
+
return bus.on(MapEvents.hover, (data) => {
|
|
66
|
+
if (mapId !== data.payload.id) return;
|
|
67
|
+
const coords = data.payload.info.coordinate;
|
|
68
|
+
if (isValidCoordinate(coords)) set({ coordinate: coords });
|
|
69
|
+
else set({ coordinate: null });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Clear cursor coordinate state for a specific map instance.
|
|
75
|
+
* This is typically not needed as cleanup happens automatically when all subscribers unmount.
|
|
76
|
+
* Use this only in advanced scenarios where manual cleanup is required.
|
|
77
|
+
*
|
|
78
|
+
* @param instanceId - The unique identifier for the map to clear
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* // Manual cleanup (rarely needed)
|
|
83
|
+
* clearCursorCoordinateState('my-map-instance');
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
function clearCursorCoordinateState(instanceId) {
|
|
87
|
+
cursorCoordinateStore.clear(instanceId);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
export { clearCursorCoordinateState, cursorCoordinateStore };
|
|
92
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","names":[],"sources":["../../src/cursor-coordinates/store.ts"],"sourcesContent":["/*\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\n/**\n * Cursor Coordinates Store\n *\n * Manages cursor coordinate state for map instances using the shared store factory.\n * Subscribes to hover events from the map and stores the current cursor position.\n *\n * @example\n * ```tsx\n * import { cursorCoordinateStore } from './store';\n *\n * // Use in a component\n * function CoordinateDisplay({ mapId }) {\n * const { state, setFormat } = cursorCoordinateStore.use(mapId);\n * return <div>{state.coordinate ? `${state.coordinate[0]}, ${state.coordinate[1]}` : '--'}</div>;\n * }\n *\n * // Or use the selector for specific values\n * const coord = cursorCoordinateStore.useSelector(mapId, (s) => s.coordinate);\n * ```\n */\n\nimport { Broadcast } from '@accelint/bus';\nimport { MapEvents } from '../deckgl/base-map/events';\nimport { createMapStore } from '../shared/create-map-store';\nimport type { UniqueId } from '@accelint/core';\nimport type { MapEventType, MapHoverEvent } from '../deckgl/base-map/types';\nimport type { CoordinateFormatTypes, CursorCoordinateState } from './types';\n\nconst bus = Broadcast.getInstance<MapEventType>();\n\n/**\n * Type guard to validate that a value is a proper coordinate tuple.\n * Checks that the value is an array with exactly two finite numbers.\n *\n * @param value - Value to validate as a coordinate\n * @returns True if value is a valid [longitude, latitude] tuple\n */\nfunction isValidCoordinate(value?: number[]): value is [number, number] {\n return (\n Array.isArray(value) && value.length === 2 && value.every(Number.isFinite)\n );\n}\n\n/**\n * Actions for cursor coordinate management\n */\ntype CursorCoordinateActions = {\n /** Set the coordinate display format */\n setFormat: (format: CoordinateFormatTypes) => void;\n};\n\n/**\n * Cursor coordinates store\n *\n * Stores the current cursor position and display format for each map instance.\n * Automatically subscribes to hover events when first React subscriber mounts.\n */\nexport const cursorCoordinateStore = createMapStore<\n CursorCoordinateState,\n CursorCoordinateActions\n>({\n defaultState: {\n coordinate: null,\n format: 'dd',\n },\n\n actions: (_mapId, { set }) => ({\n setFormat: (format: CoordinateFormatTypes) => {\n set({ format });\n },\n }),\n\n bus: (mapId, { set }) => {\n return bus.on(MapEvents.hover, (data: MapHoverEvent) => {\n const eventId = data.payload.id;\n\n // Ignore hover events from other map instances\n if (mapId !== eventId) {\n return;\n }\n\n const coords = data.payload.info.coordinate;\n\n // Update coordinate if valid, or clear if invalid\n if (isValidCoordinate(coords)) {\n set({ coordinate: coords as [number, number] });\n } else {\n set({ coordinate: null });\n }\n });\n },\n});\n\n/**\n * Clear cursor coordinate state for a specific map instance.\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 map to clear\n *\n * @example\n * ```tsx\n * // Manual cleanup (rarely needed)\n * clearCursorCoordinateState('my-map-instance');\n * ```\n */\nexport function clearCursorCoordinateState(instanceId: UniqueId): void {\n cursorCoordinateStore.clear(instanceId);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAM,MAAM,UAAU,aAA2B;;;;;;;;AASjD,SAAS,kBAAkB,OAA6C;AACtE,QACE,MAAM,QAAQ,MAAM,IAAI,MAAM,WAAW,KAAK,MAAM,MAAM,OAAO,SAAS;;;;;;;;AAkB9E,MAAa,wBAAwB,eAGnC;CACA,cAAc;EACZ,YAAY;EACZ,QAAQ;EACT;CAED,UAAU,QAAQ,EAAE,WAAW,EAC7B,YAAY,WAAkC;AAC5C,MAAI,EAAE,QAAQ,CAAC;IAElB;CAED,MAAM,OAAO,EAAE,UAAU;AACvB,SAAO,IAAI,GAAG,UAAU,QAAQ,SAAwB;AAItD,OAAI,UAHY,KAAK,QAAQ,GAI3B;GAGF,MAAM,SAAS,KAAK,QAAQ,KAAK;AAGjC,OAAI,kBAAkB,OAAO,CAC3B,KAAI,EAAE,YAAY,QAA4B,CAAC;OAE/C,KAAI,EAAE,YAAY,MAAM,CAAC;IAE3B;;CAEL,CAAC;;;;;;;;;;;;;;AAeF,SAAgB,2BAA2B,YAA4B;AACrE,uBAAsB,MAAM,WAAW"}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 { coordinateSystems } from "@accelint/geo";
|
|
14
|
+
|
|
15
|
+
//#region src/cursor-coordinates/types.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* Supported coordinate format types for displaying map coordinates.
|
|
18
|
+
*
|
|
19
|
+
* @typedef {'dd' | 'ddm' | 'dms' | 'mgrs' | 'utm'} CoordinateFormatTypes
|
|
20
|
+
* @property dd - Decimal Degrees (e.g., "45.500000° N, 30.250000° E")
|
|
21
|
+
* @property ddm - Degrees Decimal Minutes (e.g., "45° 30.0000' N, 30° 15.0000' E")
|
|
22
|
+
* @property dms - Degrees Minutes Seconds (e.g., "45° 30' 0.00" N, 30° 15' 0.00" E")
|
|
23
|
+
* @property mgrs - Military Grid Reference System (e.g., "31U DQ 48251 11932")
|
|
24
|
+
* @property utm - Universal Transverse Mercator (e.g., "31N 448251 5411932")
|
|
25
|
+
*/
|
|
26
|
+
type CoordinateFormatTypes = keyof typeof coordinateSystems;
|
|
27
|
+
/**
|
|
28
|
+
* Raw coordinate data returned by the hook.
|
|
29
|
+
* Always in longitude/latitude format, matching the order from map hover events.
|
|
30
|
+
*
|
|
31
|
+
* Returns `null` when cursor is not over the map or coordinates are invalid.
|
|
32
|
+
*/
|
|
33
|
+
type RawCoordinate = {
|
|
34
|
+
/** Longitude value in degrees (-180 to 180, normalized) */
|
|
35
|
+
longitude: number;
|
|
36
|
+
/** Latitude value in degrees (-90 to 90) */
|
|
37
|
+
latitude: number;
|
|
38
|
+
} | null;
|
|
39
|
+
/**
|
|
40
|
+
* Custom formatter function signature.
|
|
41
|
+
* Receives the raw coordinate data and returns a formatted string.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const customFormatter: CoordinateFormatter = (coord) =>
|
|
46
|
+
* `Lat: ${coord.latitude.toFixed(6)}° Lng: ${coord.longitude.toFixed(6)}°`;
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
type CoordinateFormatter = (coordinate: NonNullable<RawCoordinate>) => string;
|
|
50
|
+
/**
|
|
51
|
+
* Options for configuring cursor coordinate behavior.
|
|
52
|
+
*/
|
|
53
|
+
type UseCursorCoordinatesOptions = {
|
|
54
|
+
/**
|
|
55
|
+
* Custom formatter function. When provided, this takes precedence
|
|
56
|
+
* over the built-in format for the `formattedCoord` return value.
|
|
57
|
+
*
|
|
58
|
+
* The `setFormat` function still works and affects `currentFormat`,
|
|
59
|
+
* but won't affect `formattedCoord` when a custom formatter is active.
|
|
60
|
+
*/
|
|
61
|
+
formatter?: CoordinateFormatter;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Return type for useCursorCoordinates hook.
|
|
65
|
+
*/
|
|
66
|
+
type UseCursorCoordinatesReturn = {
|
|
67
|
+
/** Formatted coordinate string using current format or custom formatter */
|
|
68
|
+
formattedCoord: string;
|
|
69
|
+
/** Function to change the coordinate format system */
|
|
70
|
+
setFormat: (format: CoordinateFormatTypes) => void;
|
|
71
|
+
/** Raw coordinate data (always available when cursor is over map) */
|
|
72
|
+
rawCoord: RawCoordinate;
|
|
73
|
+
/** Current active format type */
|
|
74
|
+
currentFormat: CoordinateFormatTypes;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Internal state stored for each map instance's cursor coordinates.
|
|
78
|
+
*/
|
|
79
|
+
type CursorCoordinateState = {
|
|
80
|
+
/** Raw coordinate tuple [longitude, latitude] or null */
|
|
81
|
+
coordinate: [number, number] | null;
|
|
82
|
+
/** Current format type */
|
|
83
|
+
format: CoordinateFormatTypes;
|
|
84
|
+
};
|
|
85
|
+
//#endregion
|
|
86
|
+
export { CoordinateFormatTypes, CoordinateFormatter, CursorCoordinateState, RawCoordinate, UseCursorCoordinatesOptions, UseCursorCoordinatesReturn };
|
|
87
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
|
|
@@ -10,35 +10,11 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { UseCursorCoordinatesOptions, UseCursorCoordinatesReturn } from "./types.js";
|
|
14
14
|
import { UniqueId } from "@accelint/core";
|
|
15
15
|
|
|
16
16
|
//#region src/cursor-coordinates/use-cursor-coordinates.d.ts
|
|
17
|
-
|
|
18
|
-
* Supported coordinate format types for displaying map coordinates.
|
|
19
|
-
*
|
|
20
|
-
* @typedef {'dd' | 'ddm' | 'dms' | 'mgrs' | 'utm'} CoordinateFormatTypes
|
|
21
|
-
* @property dd - Decimal Degrees (e.g., "45.50000000 E / 30.25000000 N")
|
|
22
|
-
* @property ddm - Degrees Decimal Minutes (e.g., "45° 30' E / 30° 15' N")
|
|
23
|
-
* @property dms - Degrees Minutes Seconds (e.g., "45° 30' 0\" E / 30° 15' 0\" N")
|
|
24
|
-
* @property mgrs - Military Grid Reference System (e.g., "31U DQ 48251 11932")
|
|
25
|
-
* @property utm - Universal Transverse Mercator (e.g., "31N 448251 5411932")
|
|
26
|
-
*/
|
|
27
|
-
type CoordinateFormatTypes = keyof typeof coordinateSystems;
|
|
28
|
-
/**
|
|
29
|
-
* Manually clear cursor coordinate state for a specific instanceId.
|
|
30
|
-
* This is typically not needed as cleanup happens automatically when all subscribers unmount.
|
|
31
|
-
* Use this only in advanced scenarios where manual cleanup is required.
|
|
32
|
-
*
|
|
33
|
-
* @param instanceId - The unique identifier for the map to clear
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```tsx
|
|
37
|
-
* // Manual cleanup (rarely needed)
|
|
38
|
-
* clearCursorCoordinateState('my-map-instance');
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
declare function clearCursorCoordinateState(instanceId: UniqueId): void;
|
|
17
|
+
|
|
42
18
|
/**
|
|
43
19
|
* React hook that tracks and formats the cursor hover position coordinates on a map.
|
|
44
20
|
*
|
|
@@ -46,17 +22,15 @@ declare function clearCursorCoordinateState(instanceId: UniqueId): void;
|
|
|
46
22
|
* geographic formats (Decimal Degrees, DMS, MGRS, UTM, etc.). The hook automatically
|
|
47
23
|
* filters events to only process those from the specified map instance.
|
|
48
24
|
*
|
|
49
|
-
* Uses
|
|
50
|
-
* where multiple components can subscribe to the same map's coordinates with a single
|
|
51
|
-
* bus listener.
|
|
25
|
+
* Uses the shared store factory for efficient state management and automatic cleanup.
|
|
52
26
|
*
|
|
53
27
|
* @param id - Optional map instance ID. If not provided, attempts to use the ID from MapProvider context.
|
|
54
|
-
* @
|
|
55
|
-
* @
|
|
56
|
-
* @property setFormat - Function to change the coordinate format system
|
|
28
|
+
* @param options - Optional configuration options
|
|
29
|
+
* @returns Object containing the formatted coordinate string, raw coordinate, format setter, and current format
|
|
57
30
|
* @throws {Error} When no id is provided and hook is used outside MapProvider context
|
|
58
31
|
*
|
|
59
32
|
* @example
|
|
33
|
+
* Basic usage:
|
|
60
34
|
* ```tsx
|
|
61
35
|
* import { uuid } from '@accelint/core';
|
|
62
36
|
* import { useCursorCoordinates } from '@accelint/map-toolkit/cursor-coordinates';
|
|
@@ -80,11 +54,41 @@ declare function clearCursorCoordinateState(instanceId: UniqueId): void;
|
|
|
80
54
|
* );
|
|
81
55
|
* }
|
|
82
56
|
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* With custom formatter:
|
|
60
|
+
* ```tsx
|
|
61
|
+
* function CustomCoordinateDisplay() {
|
|
62
|
+
* const { formattedCoord, rawCoord } = useCursorCoordinates(MAP_ID, {
|
|
63
|
+
* formatter: (coord) =>
|
|
64
|
+
* `Lat: ${coord.latitude.toFixed(6)}° Lng: ${coord.longitude.toFixed(6)}°`,
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* return <div>{formattedCoord}</div>;
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* Accessing raw coordinates:
|
|
73
|
+
* ```tsx
|
|
74
|
+
* function RawCoordinateDisplay() {
|
|
75
|
+
* const { rawCoord, currentFormat } = useCursorCoordinates(MAP_ID);
|
|
76
|
+
*
|
|
77
|
+
* if (!rawCoord) {
|
|
78
|
+
* return <div>Move cursor over map</div>;
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* return (
|
|
82
|
+
* <div>
|
|
83
|
+
* <div>Longitude: {rawCoord.longitude}</div>
|
|
84
|
+
* <div>Latitude: {rawCoord.latitude}</div>
|
|
85
|
+
* <div>Format: {currentFormat}</div>
|
|
86
|
+
* </div>
|
|
87
|
+
* );
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
83
90
|
*/
|
|
84
|
-
declare function useCursorCoordinates(id?: UniqueId):
|
|
85
|
-
formattedCoord: string;
|
|
86
|
-
setFormat: (format: CoordinateFormatTypes) => void;
|
|
87
|
-
};
|
|
91
|
+
declare function useCursorCoordinates(id?: UniqueId, options?: UseCursorCoordinatesOptions): UseCursorCoordinatesReturn;
|
|
88
92
|
//#endregion
|
|
89
|
-
export {
|
|
93
|
+
export { useCursorCoordinates };
|
|
90
94
|
//# sourceMappingURL=use-cursor-coordinates.d.ts.map
|