@accelint/map-toolkit 0.1.0 → 0.3.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 +103 -0
- package/README.md +91 -18
- package/catalog-info.yaml +16 -10
- package/dist/cursor-coordinates/index.d.ts +3 -0
- package/dist/cursor-coordinates/index.js +3 -0
- package/dist/cursor-coordinates/index.js.map +1 -0
- package/dist/cursor-coordinates/use-cursor-coordinates.d.ts +76 -0
- package/dist/cursor-coordinates/use-cursor-coordinates.js +161 -0
- package/dist/cursor-coordinates/use-cursor-coordinates.js.map +1 -0
- package/dist/deckgl/base-map/events.d.ts +1 -0
- package/dist/deckgl/base-map/events.js +2 -1
- package/dist/deckgl/base-map/events.js.map +1 -1
- package/dist/deckgl/base-map/index.d.ts +91 -8
- package/dist/deckgl/base-map/index.js +93 -33
- package/dist/deckgl/base-map/index.js.map +1 -1
- package/dist/deckgl/base-map/provider.d.ts +129 -0
- package/dist/deckgl/base-map/provider.js +18 -0
- package/dist/deckgl/base-map/provider.js.map +1 -0
- package/dist/deckgl/base-map/types.d.ts +64 -3
- package/dist/deckgl/index.d.ts +3 -2
- package/dist/deckgl/index.js +1 -1
- package/dist/deckgl/text-layer/character-sets.d.ts +27 -0
- package/dist/deckgl/text-layer/character-sets.js +36 -0
- package/dist/deckgl/text-layer/character-sets.js.map +1 -0
- package/dist/deckgl/text-layer/default-settings.d.ts +5 -0
- package/dist/deckgl/text-layer/default-settings.js +23 -0
- package/dist/deckgl/text-layer/default-settings.js.map +1 -0
- package/dist/deckgl/text-layer/fiber.d.ts +31 -0
- package/dist/deckgl/text-layer/fiber.js +6 -0
- package/dist/deckgl/text-layer/fiber.js.map +1 -0
- package/dist/deckgl/text-layer/index.d.ts +43 -0
- package/dist/deckgl/text-layer/index.js +33 -0
- package/dist/deckgl/text-layer/index.js.map +1 -0
- package/dist/decorators/deckgl.d.ts +1 -1
- package/dist/decorators/deckgl.js +3 -1
- package/dist/decorators/deckgl.js.map +1 -1
- package/dist/map-mode/events.d.ts +37 -0
- package/dist/map-mode/events.js +15 -0
- package/dist/map-mode/events.js.map +1 -0
- package/dist/map-mode/index.d.ts +6 -0
- package/dist/map-mode/index.js +5 -0
- package/dist/map-mode/index.js.map +1 -0
- package/dist/map-mode/store.d.ts +48 -0
- package/dist/map-mode/store.js +306 -0
- package/dist/map-mode/store.js.map +1 -0
- package/dist/map-mode/types.d.ts +83 -0
- package/dist/map-mode/types.js +3 -0
- package/dist/map-mode/types.js.map +1 -0
- package/dist/map-mode/use-map-mode.d.ts +52 -0
- package/dist/map-mode/use-map-mode.js +29 -0
- package/dist/map-mode/use-map-mode.js.map +1 -0
- package/dist/maplibre/hooks/use-maplibre.d.ts +34 -0
- package/dist/maplibre/hooks/use-maplibre.js +3 -2
- package/dist/maplibre/hooks/use-maplibre.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/viewport/constants.d.ts +9 -0
- package/dist/viewport/constants.js +11 -0
- package/dist/viewport/constants.js.map +1 -0
- package/dist/viewport/index.d.ts +13 -0
- package/dist/viewport/index.js +6 -0
- package/dist/viewport/index.js.map +1 -0
- package/dist/viewport/types.d.ts +22 -0
- package/dist/viewport/types.js +3 -0
- package/dist/viewport/types.js.map +1 -0
- package/dist/viewport/use-viewport-state.d.ts +85 -0
- package/dist/viewport/use-viewport-state.js +109 -0
- package/dist/viewport/use-viewport-state.js.map +1 -0
- package/dist/viewport/utils.d.ts +37 -0
- package/dist/viewport/utils.js +46 -0
- package/dist/viewport/utils.js.map +1 -0
- package/dist/viewport/viewport-size.d.ts +42 -0
- package/dist/viewport/viewport-size.js +16 -0
- package/dist/viewport/viewport-size.js.map +1 -0
- package/package.json +48 -46
- package/dist/test/setup.d.ts +0 -2
- package/dist/test/setup.js +0 -11
- package/dist/test/setup.js.map +0 -1
|
@@ -1,15 +1,98 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { UniqueId } from '@accelint/core';
|
|
3
3
|
import { DeckglProps } from '@deckgl-fiber-renderer/types';
|
|
4
|
-
import { MapEventType } from './types.js';
|
|
5
|
-
import '@deck.gl/core';
|
|
6
|
-
import 'mjolnir.js';
|
|
7
|
-
import './events.js';
|
|
8
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Props for the BaseMap component.
|
|
7
|
+
* Extends all Deck.gl props and adds additional map-specific properties.
|
|
8
|
+
*/
|
|
9
9
|
type BaseMapProps = DeckglProps & {
|
|
10
|
+
/** Optional CSS class name to apply to the map container element */
|
|
10
11
|
className?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Unique identifier for this map instance (required).
|
|
14
|
+
*
|
|
15
|
+
* Used to isolate map mode state between multiple map instances (e.g., main map vs minimap).
|
|
16
|
+
* This should be a UUID generated using `uuid()` from `@accelint/core`.
|
|
17
|
+
*
|
|
18
|
+
* The same id should be passed to `useMapMode()` when accessing map mode state
|
|
19
|
+
* from components rendered outside of the BaseMap's children (i.e., as siblings).
|
|
20
|
+
*/
|
|
21
|
+
id: UniqueId;
|
|
11
22
|
};
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A React component that provides a Deck.gl-powered base map with MapLibre GL integration.
|
|
25
|
+
*
|
|
26
|
+
* This component serves as the foundation for building interactive map applications with
|
|
27
|
+
* support for click and hover events through a centralized event bus. It integrates
|
|
28
|
+
* Deck.gl for 3D visualizations with MapLibre GL for the base map tiles.
|
|
29
|
+
*
|
|
30
|
+
* **Map Mode Integration**: BaseMap automatically creates a `MapProvider` internally,
|
|
31
|
+
* which sets up the map mode state management for this instance.
|
|
32
|
+
* - **Children**: Only Deck.gl layer components can be rendered as children. Custom Deck.gl
|
|
33
|
+
* layers can use `useMapMode()` without parameters to access context.
|
|
34
|
+
* - **Siblings**: UI components (buttons, toolbars, etc.) must be rendered as siblings
|
|
35
|
+
* and pass `id` to `useMapMode(id)`.
|
|
36
|
+
*
|
|
37
|
+
* **Event Bus**: Click and hover events are emitted through the event bus with the `id`
|
|
38
|
+
* included in the payload, allowing multiple map instances to coexist without interference.
|
|
39
|
+
*
|
|
40
|
+
* @param props - Component props including id (required), className, onClick, onHover, and all Deck.gl props
|
|
41
|
+
* @returns A map component with Deck.gl and MapLibre GL integration
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* Basic usage with id (recommended: module-level constant):
|
|
45
|
+
* ```tsx
|
|
46
|
+
* import { BaseMap } from '@accelint/map-toolkit/deckgl';
|
|
47
|
+
* import { View } from '@deckgl-fiber-renderer/dom';
|
|
48
|
+
* import { uuid } from '@accelint/core';
|
|
49
|
+
*
|
|
50
|
+
* // Create id at module level for stability and easy sharing
|
|
51
|
+
* const MAIN_MAP_ID = uuid();
|
|
52
|
+
*
|
|
53
|
+
* export function MapView() {
|
|
54
|
+
* return (
|
|
55
|
+
* <BaseMap className="w-full h-full" id={MAIN_MAP_ID}>
|
|
56
|
+
* <View id="main" controller />
|
|
57
|
+
* </BaseMap>
|
|
58
|
+
* );
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* With map mode and event handlers (module-level constant for sharing):
|
|
64
|
+
* ```tsx
|
|
65
|
+
* import { BaseMap } from '@accelint/map-toolkit/deckgl';
|
|
66
|
+
* import { useMapMode } from '@accelint/map-toolkit/map-mode';
|
|
67
|
+
* import { uuid } from '@accelint/core';
|
|
68
|
+
* import type { PickingInfo } from '@deck.gl/core';
|
|
69
|
+
* import type { MjolnirGestureEvent } from 'mjolnir.js';
|
|
70
|
+
*
|
|
71
|
+
* // Module-level constant - stable and shareable across all components
|
|
72
|
+
* const MAIN_MAP_ID = uuid();
|
|
73
|
+
*
|
|
74
|
+
* function Toolbar() {
|
|
75
|
+
* // Access map mode using the shared id
|
|
76
|
+
* const { mode, requestModeChange } = useMapMode(MAIN_MAP_ID);
|
|
77
|
+
* return <div>Current mode: {mode}</div>;
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* export function InteractiveMap() {
|
|
81
|
+
* const handleClick = (info: PickingInfo, event: MjolnirGestureEvent) => {
|
|
82
|
+
* console.log('Clicked:', info.object);
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* return (
|
|
86
|
+
* <div className="relative w-full h-full">
|
|
87
|
+
* <BaseMap className="absolute inset-0" id={MAIN_MAP_ID} onClick={handleClick}>
|
|
88
|
+
* <View id="main" controller />
|
|
89
|
+
* </BaseMap>
|
|
90
|
+
* <Toolbar />
|
|
91
|
+
* </div>
|
|
92
|
+
* );
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare function BaseMap({ id, className, children, controller, interleaved, parameters, useDevicePixels, widgets: widgetsProp, onClick, onHover, onViewStateChange, ...rest }: BaseMapProps): react_jsx_runtime.JSX.Element;
|
|
14
97
|
|
|
15
|
-
export { BaseMap,
|
|
98
|
+
export { BaseMap, type BaseMapProps };
|
|
@@ -1,40 +1,56 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import 'client-only';
|
|
3
|
-
import {
|
|
4
|
-
import { useEmit } from '@accelint/bus/react';
|
|
3
|
+
import { useEmit, useEffectEvent } from '@accelint/bus/react';
|
|
5
4
|
import { useDeckgl, Deckgl } from '@deckgl-fiber-renderer/dom';
|
|
6
|
-
import { useId, useCallback } from 'react';
|
|
5
|
+
import { useId, useMemo, useCallback } from 'react';
|
|
7
6
|
import { INITIAL_VIEW_STATE } from '../../maplibre/constants.js';
|
|
8
7
|
import { useMapLibre } from '../../maplibre/hooks/use-maplibre.js';
|
|
9
8
|
import { BASE_MAP_STYLE, PARAMETERS } from './constants.js';
|
|
10
9
|
import { MapEvents } from './events.js';
|
|
10
|
+
import { MapProvider } from './provider.js';
|
|
11
11
|
|
|
12
|
-
const bus = Broadcast.getInstance();
|
|
13
12
|
function BaseMap({
|
|
13
|
+
id,
|
|
14
|
+
className,
|
|
14
15
|
children,
|
|
16
|
+
controller = true,
|
|
17
|
+
interleaved = true,
|
|
18
|
+
parameters = {},
|
|
19
|
+
useDevicePixels = false,
|
|
20
|
+
widgets: widgetsProp = [],
|
|
15
21
|
onClick,
|
|
16
22
|
onHover,
|
|
17
|
-
|
|
18
|
-
parameters,
|
|
23
|
+
onViewStateChange,
|
|
19
24
|
...rest
|
|
20
25
|
}) {
|
|
21
26
|
const deckglInstance = useDeckgl();
|
|
22
27
|
const container = useId();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const mapOptions = useMemo(
|
|
29
|
+
() => ({
|
|
30
|
+
container,
|
|
31
|
+
center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],
|
|
32
|
+
zoom: INITIAL_VIEW_STATE.zoom,
|
|
33
|
+
doubleClickZoom: false,
|
|
34
|
+
dragRotate: false,
|
|
35
|
+
pitchWithRotate: false,
|
|
36
|
+
rollEnabled: false,
|
|
37
|
+
attributionControl: { compact: true }
|
|
38
|
+
}),
|
|
39
|
+
[container]
|
|
40
|
+
);
|
|
41
|
+
useMapLibre(deckglInstance, BASE_MAP_STYLE, mapOptions);
|
|
32
42
|
const emitClick = useEmit(MapEvents.click);
|
|
33
43
|
const emitHover = useEmit(MapEvents.hover);
|
|
34
|
-
const
|
|
44
|
+
const emitViewport = useEmit(MapEvents.viewport);
|
|
45
|
+
const handleClick = useCallback(
|
|
35
46
|
(info, event) => {
|
|
36
47
|
onClick?.(info, event);
|
|
37
|
-
const { viewport, ...infoRest } = info;
|
|
48
|
+
const { viewport, layer, sourceLayer, ...infoRest } = info;
|
|
49
|
+
const infoObject = {
|
|
50
|
+
layerId: layer?.id,
|
|
51
|
+
sourceLayerId: sourceLayer?.id,
|
|
52
|
+
...infoRest
|
|
53
|
+
};
|
|
38
54
|
const {
|
|
39
55
|
stopImmediatePropagation,
|
|
40
56
|
stopPropagation,
|
|
@@ -47,16 +63,22 @@ function BaseMap({
|
|
|
47
63
|
...eventRest
|
|
48
64
|
} = event;
|
|
49
65
|
emitClick({
|
|
50
|
-
info:
|
|
51
|
-
event: eventRest
|
|
66
|
+
info: infoObject,
|
|
67
|
+
event: eventRest,
|
|
68
|
+
id
|
|
52
69
|
});
|
|
53
70
|
},
|
|
54
|
-
[emitClick, onClick]
|
|
71
|
+
[emitClick, id, onClick]
|
|
55
72
|
);
|
|
56
|
-
const
|
|
73
|
+
const handleHover = useCallback(
|
|
57
74
|
(info, event) => {
|
|
58
75
|
onHover?.(info, event);
|
|
59
|
-
const { viewport, ...infoRest } = info;
|
|
76
|
+
const { viewport, layer, sourceLayer, ...infoRest } = info;
|
|
77
|
+
const infoObject = {
|
|
78
|
+
layerId: layer?.id,
|
|
79
|
+
sourceLayerId: sourceLayer?.id,
|
|
80
|
+
...infoRest
|
|
81
|
+
};
|
|
60
82
|
const {
|
|
61
83
|
stopImmediatePropagation,
|
|
62
84
|
stopPropagation,
|
|
@@ -67,27 +89,65 @@ function BaseMap({
|
|
|
67
89
|
...eventRest
|
|
68
90
|
} = event;
|
|
69
91
|
emitHover({
|
|
70
|
-
info:
|
|
71
|
-
event: eventRest
|
|
92
|
+
info: infoObject,
|
|
93
|
+
event: eventRest,
|
|
94
|
+
id
|
|
72
95
|
});
|
|
73
96
|
},
|
|
74
|
-
[emitHover, onHover]
|
|
97
|
+
[emitHover, id, onHover]
|
|
98
|
+
);
|
|
99
|
+
const handleViewStateChange = useEffectEvent(
|
|
100
|
+
(params) => {
|
|
101
|
+
onViewStateChange?.(params);
|
|
102
|
+
const {
|
|
103
|
+
viewId,
|
|
104
|
+
viewState: { latitude, longitude, zoom }
|
|
105
|
+
} = params;
|
|
106
|
+
const viewport = deckglInstance._deck.getViewports()?.find((vp) => vp.id === viewId);
|
|
107
|
+
emitViewport({
|
|
108
|
+
id,
|
|
109
|
+
bounds: viewport?.getBounds(),
|
|
110
|
+
latitude,
|
|
111
|
+
longitude,
|
|
112
|
+
zoom,
|
|
113
|
+
width: viewport?.width ?? 0,
|
|
114
|
+
height: viewport?.height ?? 0
|
|
115
|
+
});
|
|
116
|
+
}
|
|
75
117
|
);
|
|
76
|
-
|
|
118
|
+
const handleLoad = useEffectEvent(() => {
|
|
119
|
+
deckglInstance._deck.getViewports().forEach((vp) => {
|
|
120
|
+
handleViewStateChange({
|
|
121
|
+
viewId: vp.id,
|
|
122
|
+
viewState: {
|
|
123
|
+
latitude: vp.latitude,
|
|
124
|
+
longitude: vp.longitude,
|
|
125
|
+
zoom: vp.zoom,
|
|
126
|
+
id: vp.id,
|
|
127
|
+
bounds: vp.getBounds(),
|
|
128
|
+
width: vp.width,
|
|
129
|
+
height: vp.height
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
return /* @__PURE__ */ jsx("div", { id: container, className, children: /* @__PURE__ */ jsx(MapProvider, { id, children: /* @__PURE__ */ jsx(
|
|
77
135
|
Deckgl,
|
|
78
136
|
{
|
|
79
137
|
...rest,
|
|
80
|
-
controller
|
|
81
|
-
interleaved
|
|
82
|
-
useDevicePixels
|
|
83
|
-
|
|
84
|
-
|
|
138
|
+
controller,
|
|
139
|
+
interleaved,
|
|
140
|
+
useDevicePixels,
|
|
141
|
+
onClick: handleClick,
|
|
142
|
+
onHover: handleHover,
|
|
143
|
+
onLoad: handleLoad,
|
|
144
|
+
onViewStateChange: handleViewStateChange,
|
|
85
145
|
parameters: { ...PARAMETERS, ...parameters },
|
|
86
146
|
children
|
|
87
147
|
}
|
|
88
|
-
) });
|
|
148
|
+
) }) });
|
|
89
149
|
}
|
|
90
150
|
|
|
91
|
-
export { BaseMap
|
|
151
|
+
export { BaseMap };
|
|
92
152
|
//# sourceMappingURL=index.js.map
|
|
93
153
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/deckgl/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AAA;AAAA,IACA,CAAC,WAAW,OAAO;AAAA,GACrB;AAEA,EAAA,MAAM,cAAA,GAAiB,WAAA;AAAA,IACrB,CAAC,MAAmB,KAAA,KAA+B;AAEjD,MAAA,OAAA,GAAU,MAAM,KAAK,CAAA;AAGrB,MAAA,MAAM,EAAE,QAAA,EAAU,GAAG,QAAA,EAAS,GAAI,IAAA;AAClC,MAAA,MAAM;AAAA,QACJ,wBAAA;AAAA,QACA,eAAA;AAAA,QACA,cAAA;AAAA,QACA,QAAA;AAAA,QACA,WAAA;AAAA,QACA,MAAA;AAAA,QACA,GAAG;AAAA,OACL,GAAI,KAAA;AAEJ,MAAA,SAAA,CAAU;AAAA,QACR,IAAA,EAAM,QAAA;AAAA,QACN,KAAA,EAAO;AAAA,OACR,CAAA;AAAA,IACH,CAAA;AAAA,IACA,CAAC,WAAW,OAAO;AAAA,GACrB;AAEA,EAAA,uBACE,GAAA,CAAC,KAAA,EAAA,EAAI,EAAA,EAAI,SAAA,EAAW,SAAA,EAClB,QAAA,kBAAA,GAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACE,GAAG,IAAA;AAAA,MACJ,UAAA,EAAU,IAAA;AAAA,MACV,WAAA,EAAW,IAAA;AAAA,MACX,eAAA,EAAiB,KAAA;AAAA,MACjB,OAAA,EAAS,cAAA;AAAA,MACT,OAAA,EAAS,cAAA;AAAA,MAET,UAAA,EAAY,EAAE,GAAG,UAAA,EAAY,GAAG,UAAA,EAAW;AAAA,MAE1C;AAAA;AAAA,GACH,EACF,CAAA;AAEJ","file":"index.js","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 { Broadcast } from '@accelint/bus';\nimport { useEmit } from '@accelint/bus/react';\nimport { Deckgl, useDeckgl } from '@deckgl-fiber-renderer/dom';\nimport { useCallback, useId } from 'react';\nimport { INITIAL_VIEW_STATE } from '../../maplibre/constants';\nimport { useMapLibre } from '../../maplibre/hooks/use-maplibre';\nimport { BASE_MAP_STYLE, PARAMETERS } from './constants';\nimport { MapEvents } from './events';\nimport type { PickingInfo } from '@deck.gl/core';\nimport type { DeckglProps } from '@deckgl-fiber-renderer/types';\nimport type { IControl } from 'maplibre-gl';\nimport type { MjolnirGestureEvent, MjolnirPointerEvent } from 'mjolnir.js';\nimport type { MapClickEvent, MapEventType, MapHoverEvent } from './types';\n\ntype BaseMapProps = DeckglProps & { className?: string };\n\nexport const bus = Broadcast.getInstance<MapEventType>();\n\nexport function BaseMap({\n children,\n onClick,\n onHover,\n className,\n parameters,\n ...rest\n}: BaseMapProps) {\n const deckglInstance = useDeckgl();\n const container = useId();\n\n // Use the custom hook to handle MapLibre\n useMapLibre(deckglInstance as IControl, BASE_MAP_STYLE, {\n container,\n center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],\n zoom: INITIAL_VIEW_STATE.zoom,\n doubleClickZoom: false,\n dragRotate: false,\n pitchWithRotate: false,\n rollEnabled: false,\n });\n\n const emitClick = useEmit<MapClickEvent>(MapEvents.click);\n const emitHover = useEmit<MapHoverEvent>(MapEvents.hover);\n\n const handleMapClick = useCallback(\n (info: PickingInfo, event: MjolnirGestureEvent) => {\n // send full pickingInfo and event to user-defined onClick\n onClick?.(info, event);\n\n // the bus cannot serialize functions, so we omit them from the event payloads\n const { viewport, ...infoRest } = info;\n const {\n stopImmediatePropagation,\n stopPropagation,\n preventDefault,\n srcEvent,\n rootElement,\n target,\n changedPointers,\n pointers,\n ...eventRest\n } = event;\n\n emitClick({\n info: infoRest,\n event: eventRest,\n });\n },\n [emitClick, onClick],\n );\n\n const handleMapHover = useCallback(\n (info: PickingInfo, event: MjolnirPointerEvent) => {\n // send full pickingInfo and event to user-defined onHover\n onHover?.(info, event);\n\n // the bus cannot serialize functions, so we omit them from the event payloads\n const { viewport, ...infoRest } = info;\n const {\n stopImmediatePropagation,\n stopPropagation,\n preventDefault,\n srcEvent,\n rootElement,\n target,\n ...eventRest\n } = event;\n\n emitHover({\n info: infoRest,\n event: eventRest,\n });\n },\n [emitHover, onHover],\n );\n\n return (\n <div id={container} className={className}>\n <Deckgl\n {...rest}\n controller\n interleaved\n useDevicePixels={false}\n onHover={handleMapHover}\n onClick={handleMapClick}\n // @ts-expect-error TODO: conflict with deckgl type\n parameters={{ ...PARAMETERS, ...parameters }}\n >\n {children}\n </Deckgl>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/deckgl/base-map/index.tsx"],"names":[],"mappings":";;;;;;;;;;;AA0HO,SAAS,OAAA,CAAQ;AAAA,EACtB,EAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA,GAAa,IAAA;AAAA,EACb,WAAA,GAAc,IAAA;AAAA,EACd,aAAa,EAAC;AAAA,EACd,eAAA,GAAkB,KAAA;AAAA,EAClB,OAAA,EAAS,cAAc,EAAC;AAAA,EACxB,OAAA;AAAA,EACA,OAAA;AAAA,EACA,iBAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAiB;AACf,EAAA,MAAM,iBAAiB,SAAA,EAAU;AACjC,EAAA,MAAM,YAAY,KAAA,EAAM;AAGxB,EAAA,MAAM,UAAA,GAAa,OAAA;AAAA,IACjB,OAAO;AAAA,MACL,SAAA;AAAA,MACA,MAAA,EAAQ,CAAC,kBAAA,CAAmB,SAAA,EAAW,mBAAmB,QAAQ,CAAA;AAAA,MAIlE,MAAM,kBAAA,CAAmB,IAAA;AAAA,MACzB,eAAA,EAAiB,KAAA;AAAA,MACjB,UAAA,EAAY,KAAA;AAAA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AAA,MAAM,UAAA,GAAa,eAAe,MAAM;AAGtC,IAAA,cAAA,CAAe,KAAA,CAAM,YAAA,EAAa,CAAE,OAAA,CAAQ,CAAC,EAAA,KAAO;AAClD,MAAA,qBAAA,CAAsB;AAAA,QACpB,QAAQ,EAAA,CAAG,EAAA;AAAA,QACX,SAAA,EAAW;AAAA,UACT,UAAU,EAAA,CAAG,QAAA;AAAA,UACb,WAAW,EAAA,CAAG,SAAA;AAAA,UACd,MAAM,EAAA,CAAG,IAAA;AAAA,UACT,IAAI,EAAA,CAAG,EAAA;AAAA,UACP,MAAA,EAAQ,GAAG,SAAA,EAAU;AAAA,UACrB,OAAO,EAAA,CAAG,KAAA;AAAA,UACV,QAAQ,EAAA,CAAG;AAAA;AACb,OAC4B,CAAA;AAAA,IAChC,CAAC,CAAA;AAAA,EACH,CAAC,CAAA;AAED,EAAA,2BACG,KAAA,EAAA,EAAI,EAAA,EAAI,WAAW,SAAA,EAClB,QAAA,kBAAA,GAAA,CAAC,eAAY,EAAA,EACX,QAAA,kBAAA,GAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACE,GAAG,IAAA;AAAA,MACJ,UAAA;AAAA,MACA,WAAA;AAAA,MACA,eAAA;AAAA,MACA,OAAA,EAAS,WAAA;AAAA,MACT,OAAA,EAAS,WAAA;AAAA,MACT,MAAA,EAAQ,UAAA;AAAA,MACR,iBAAA,EAAmB,qBAAA;AAAA,MAGnB,UAAA,EAAY,EAAE,GAAG,UAAA,EAAY,GAAG,UAAA,EAAW;AAAA,MAE1C;AAAA;AAAA,KAEL,CAAA,EACF,CAAA;AAEJ","file":"index.js","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 { useEffectEvent, useEmit } from '@accelint/bus/react';\nimport { Deckgl, useDeckgl } from '@deckgl-fiber-renderer/dom';\nimport { useCallback, useId, useMemo } from 'react';\nimport { INITIAL_VIEW_STATE } from '../../maplibre/constants';\nimport { useMapLibre } from '../../maplibre/hooks/use-maplibre';\nimport { BASE_MAP_STYLE, PARAMETERS } from './constants';\nimport { MapEvents } from './events';\nimport { MapProvider } from './provider';\nimport type { UniqueId } from '@accelint/core';\nimport type { PickingInfo, ViewStateChangeParameters } from '@deck.gl/core';\nimport type { DeckglProps } from '@deckgl-fiber-renderer/types';\nimport type { IControl } from 'maplibre-gl';\nimport type { MjolnirGestureEvent, MjolnirPointerEvent } from 'mjolnir.js';\nimport type { MapClickEvent, MapHoverEvent, MapViewportEvent } from './types';\n\n/**\n * Props for the BaseMap component.\n * Extends all Deck.gl props and adds additional map-specific properties.\n */\nexport type BaseMapProps = DeckglProps & {\n /** Optional CSS class name to apply to the map container element */\n className?: string;\n /**\n * Unique identifier for this map instance (required).\n *\n * Used to isolate map mode state between multiple map instances (e.g., main map vs minimap).\n * This should be a UUID generated using `uuid()` from `@accelint/core`.\n *\n * The same id should be passed to `useMapMode()` when accessing map mode state\n * from components rendered outside of the BaseMap's children (i.e., as siblings).\n */\n id: UniqueId;\n};\n\n/**\n * A React component that provides a Deck.gl-powered base map with MapLibre GL integration.\n *\n * This component serves as the foundation for building interactive map applications with\n * support for click and hover events through a centralized event bus. It integrates\n * Deck.gl for 3D visualizations with MapLibre GL for the base map tiles.\n *\n * **Map Mode Integration**: BaseMap automatically creates a `MapProvider` internally,\n * which sets up the map mode state management for this instance.\n * - **Children**: Only Deck.gl layer components can be rendered as children. Custom Deck.gl\n * layers can use `useMapMode()` without parameters to access context.\n * - **Siblings**: UI components (buttons, toolbars, etc.) must be rendered as siblings\n * and pass `id` to `useMapMode(id)`.\n *\n * **Event Bus**: Click and hover events are emitted through the event bus with the `id`\n * included in the payload, allowing multiple map instances to coexist without interference.\n *\n * @param props - Component props including id (required), className, onClick, onHover, and all Deck.gl props\n * @returns A map component with Deck.gl and MapLibre GL integration\n *\n * @example\n * Basic usage with id (recommended: module-level constant):\n * ```tsx\n * import { BaseMap } from '@accelint/map-toolkit/deckgl';\n * import { View } from '@deckgl-fiber-renderer/dom';\n * import { uuid } from '@accelint/core';\n *\n * // Create id at module level for stability and easy sharing\n * const MAIN_MAP_ID = uuid();\n *\n * export function MapView() {\n * return (\n * <BaseMap className=\"w-full h-full\" id={MAIN_MAP_ID}>\n * <View id=\"main\" controller />\n * </BaseMap>\n * );\n * }\n * ```\n *\n * @example\n * With map mode and event handlers (module-level constant for sharing):\n * ```tsx\n * import { BaseMap } from '@accelint/map-toolkit/deckgl';\n * import { useMapMode } from '@accelint/map-toolkit/map-mode';\n * import { uuid } from '@accelint/core';\n * import type { PickingInfo } from '@deck.gl/core';\n * import type { MjolnirGestureEvent } from 'mjolnir.js';\n *\n * // Module-level constant - stable and shareable across all components\n * const MAIN_MAP_ID = uuid();\n *\n * function Toolbar() {\n * // Access map mode using the shared id\n * const { mode, requestModeChange } = useMapMode(MAIN_MAP_ID);\n * return <div>Current mode: {mode}</div>;\n * }\n *\n * export function InteractiveMap() {\n * const handleClick = (info: PickingInfo, event: MjolnirGestureEvent) => {\n * console.log('Clicked:', info.object);\n * };\n *\n * return (\n * <div className=\"relative w-full h-full\">\n * <BaseMap className=\"absolute inset-0\" id={MAIN_MAP_ID} onClick={handleClick}>\n * <View id=\"main\" controller />\n * </BaseMap>\n * <Toolbar />\n * </div>\n * );\n * }\n * ```\n */\nexport function BaseMap({\n id,\n className,\n children,\n controller = true,\n interleaved = true,\n parameters = {},\n useDevicePixels = false,\n widgets: widgetsProp = [],\n onClick,\n onHover,\n onViewStateChange,\n ...rest\n}: BaseMapProps) {\n const deckglInstance = useDeckgl();\n const container = useId();\n\n // Memoize MapLibre options to avoid creating new object on every render\n const mapOptions = useMemo(\n () => ({\n container,\n center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude] as [\n number,\n number,\n ],\n zoom: INITIAL_VIEW_STATE.zoom,\n doubleClickZoom: false,\n dragRotate: false,\n pitchWithRotate: false,\n rollEnabled: false,\n attributionControl: { compact: true },\n }),\n [container],\n );\n\n // Use the custom hook to handle MapLibre\n useMapLibre(deckglInstance as IControl, BASE_MAP_STYLE, mapOptions);\n\n const emitClick = useEmit<MapClickEvent>(MapEvents.click);\n const emitHover = useEmit<MapHoverEvent>(MapEvents.hover);\n const emitViewport = useEmit<MapViewportEvent>(MapEvents.viewport);\n\n const handleClick = useCallback(\n (info: PickingInfo, event: MjolnirGestureEvent) => {\n // send full pickingInfo and event to user-defined onClick\n onClick?.(info, event);\n\n // omit viewport, layer, and sourceLayer (contain functions) for event bus serialization\n // extract layerId and sourceLayerId before omission to preserve layer identification\n const { viewport, layer, sourceLayer, ...infoRest } = info;\n const infoObject = {\n layerId: layer?.id,\n sourceLayerId: sourceLayer?.id,\n ...infoRest,\n };\n\n const {\n stopImmediatePropagation,\n stopPropagation,\n preventDefault,\n srcEvent,\n rootElement,\n target,\n changedPointers,\n pointers,\n ...eventRest\n } = event;\n\n emitClick({\n info: infoObject,\n event: eventRest,\n id,\n });\n },\n [emitClick, id, onClick],\n );\n\n const handleHover = useCallback(\n (info: PickingInfo, event: MjolnirPointerEvent) => {\n // send full pickingInfo and event to user-defined onHover\n onHover?.(info, event);\n\n // omit viewport, layer, and sourceLayer (contain functions) for event bus serialization\n // extract layerId and sourceLayerId before omission to preserve layer identification\n const { viewport, layer, sourceLayer, ...infoRest } = info;\n const infoObject = {\n layerId: layer?.id,\n sourceLayerId: sourceLayer?.id,\n ...infoRest,\n };\n\n const {\n stopImmediatePropagation,\n stopPropagation,\n preventDefault,\n srcEvent,\n rootElement,\n target,\n ...eventRest\n } = event;\n\n emitHover({\n info: infoObject,\n event: eventRest,\n id,\n });\n },\n [emitHover, id, onHover],\n );\n\n const handleViewStateChange = useEffectEvent(\n (params: ViewStateChangeParameters) => {\n onViewStateChange?.(params);\n\n const {\n viewId,\n viewState: { latitude, longitude, zoom },\n } = params;\n\n // @ts-expect-error squirrelly deckglInstance typing\n const viewport = deckglInstance._deck\n .getViewports()\n // @ts-expect-error squirrelly deckglInstance typing\n ?.find((vp) => vp.id === viewId);\n\n emitViewport({\n id,\n bounds: viewport?.getBounds(),\n latitude,\n longitude,\n zoom,\n width: viewport?.width ?? 0,\n height: viewport?.height ?? 0,\n });\n },\n );\n\n const handleLoad = useEffectEvent(() => {\n //--- force update viewport state once all viewports initialized ---\n // @ts-expect-error squirrelly deckglInstance typing\n deckglInstance._deck.getViewports().forEach((vp) => {\n handleViewStateChange({\n viewId: vp.id,\n viewState: {\n latitude: vp.latitude,\n longitude: vp.longitude,\n zoom: vp.zoom,\n id: vp.id,\n bounds: vp.getBounds(),\n width: vp.width,\n height: vp.height,\n },\n } as ViewStateChangeParameters);\n });\n });\n\n return (\n <div id={container} className={className}>\n <MapProvider id={id}>\n <Deckgl\n {...rest}\n controller={controller}\n interleaved={interleaved}\n useDevicePixels={useDevicePixels}\n onClick={handleClick}\n onHover={handleHover}\n onLoad={handleLoad}\n onViewStateChange={handleViewStateChange}\n // @ts-expect-error - DeckglProps parameters type is overly strict for WebGL parameter spreading.\n // The merged object is valid at runtime but TypeScript cannot verify all possible parameter combinations.\n parameters={{ ...PARAMETERS, ...parameters }}\n >\n {children}\n </Deckgl>\n </MapProvider>\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { UniqueId } from '@accelint/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* React context for map ID.
|
|
8
|
+
* Use the `useMapMode` hook to access the map mode state.
|
|
9
|
+
*/
|
|
10
|
+
declare const MapContext: react.Context<UniqueId | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Props for the MapProvider component.
|
|
13
|
+
*/
|
|
14
|
+
type MapProviderProps = {
|
|
15
|
+
/** Child components that will have access to map mode context */
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Unique identifier for this map instance.
|
|
19
|
+
*
|
|
20
|
+
* Used to isolate mode changes between different map instances (e.g., main map vs minimap).
|
|
21
|
+
* This is required and should be provided by the parent component (typically BaseMap).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // Multiple independent map instances
|
|
26
|
+
* const mainMapId = uuid();
|
|
27
|
+
* const minimapId = uuid();
|
|
28
|
+
*
|
|
29
|
+
* <MapProvider id={mainMapId}>
|
|
30
|
+
* // Map layers and components
|
|
31
|
+
* </MapProvider>
|
|
32
|
+
*
|
|
33
|
+
* <MapProvider id={minimapId}>
|
|
34
|
+
* // Minimap layers and components
|
|
35
|
+
* </MapProvider>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
id: UniqueId;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Provider component for managing map modes with ownership and authorization.
|
|
42
|
+
*
|
|
43
|
+
* **Note**: This provider is used internally by `BaseMap` and should not be used directly.
|
|
44
|
+
* Consumers should pass the `id` prop to `BaseMap`, which will create this provider automatically.
|
|
45
|
+
*
|
|
46
|
+
* This component uses a hybrid architecture combining React Context (for map instance identity)
|
|
47
|
+
* with module-level state management (for map mode state). The provider:
|
|
48
|
+
* - Provides a unique `id` via Context
|
|
49
|
+
* - Cleans up map mode state when unmounted
|
|
50
|
+
* - Allows components to subscribe to mode changes via `useMapMode` hook (which uses `useSyncExternalStore`)
|
|
51
|
+
*
|
|
52
|
+
* The module-level state management system implements a state machine for map modes where
|
|
53
|
+
* components can request mode changes with ownership. When a mode is owned by a component,
|
|
54
|
+
* other components must request authorization to change to a different mode. The system handles:
|
|
55
|
+
*
|
|
56
|
+
* - Automatic mode changes when no ownership conflicts exist
|
|
57
|
+
* - Authorization flow when switching between owned modes
|
|
58
|
+
* - Per-mode ownership tracking that persists throughout the session
|
|
59
|
+
* - Pending request management (one pending request per requester)
|
|
60
|
+
* - Auto-acceptance of first pending request when mode owner returns to default
|
|
61
|
+
* - Auto-rejection of other pending requests when one is approved
|
|
62
|
+
* - Event emission through a centralized event bus
|
|
63
|
+
* - Instance isolation for multiple map scenarios (main map + minimap)
|
|
64
|
+
* - Always initializes in 'default' mode
|
|
65
|
+
*
|
|
66
|
+
* ## Instance Isolation
|
|
67
|
+
*
|
|
68
|
+
* Each MapProvider instance operates independently. Mode changes in one instance
|
|
69
|
+
* do not affect other instances, even when multiple maps are rendered on the same page.
|
|
70
|
+
* This enables scenarios like:
|
|
71
|
+
* - Main map in "drawing" mode while minimap stays in "view" mode
|
|
72
|
+
* - Multiple independent map views with different interaction modes
|
|
73
|
+
*
|
|
74
|
+
* Events are scoped to specific instances using the `id` prop. The event bus
|
|
75
|
+
* filters events to ensure each provider only responds to events for its own instance.
|
|
76
|
+
*
|
|
77
|
+
* ## Pending Request Behavior
|
|
78
|
+
*
|
|
79
|
+
* - Pending requests are stored by requester ID (not mode owner)
|
|
80
|
+
* - Each requester can have only one pending request at a time
|
|
81
|
+
* - New requests from the same requester auto-replace previous requests
|
|
82
|
+
* - Pending requests persist when mode owner switches between their own modes
|
|
83
|
+
* - When any request is approved, all other pending requests are auto-rejected
|
|
84
|
+
* - When mode owner returns to default mode:
|
|
85
|
+
* - If first pending request is for default mode, all pending requests are rejected (already in requested mode)
|
|
86
|
+
* - If first pending request is for a different mode, that request is auto-approved and others are rejected
|
|
87
|
+
*
|
|
88
|
+
* ## Instance ID Stability and Lifecycle
|
|
89
|
+
*
|
|
90
|
+
* The provider's cleanup mechanism (via `useEffect`) ensures proper state management:
|
|
91
|
+
* - Map mode state is cleaned up when the provider unmounts
|
|
92
|
+
* - Changing the `id` prop will trigger cleanup of the old state via the effect dependency
|
|
93
|
+
* - State is lazily initialized on first subscription (no manual creation needed)
|
|
94
|
+
*
|
|
95
|
+
* While the `id` prop should typically remain stable (created as a module-level constant
|
|
96
|
+
* or with `useState`), changing it will work correctly due to the cleanup mechanism.
|
|
97
|
+
*
|
|
98
|
+
* @param props - Provider props including children and required id
|
|
99
|
+
* @returns Provider component that wraps children with map instance identity context
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* Internal usage within BaseMap:
|
|
103
|
+
* ```tsx
|
|
104
|
+
* // BaseMap automatically creates the provider
|
|
105
|
+
* function BaseMap({ id, children, ...props }: BaseMapProps) {
|
|
106
|
+
* return (
|
|
107
|
+
* <div>
|
|
108
|
+
* <MapProvider id={id}>
|
|
109
|
+
* <Deckgl {...props}>
|
|
110
|
+
* {children}
|
|
111
|
+
* </Deckgl>
|
|
112
|
+
* </MapProvider>
|
|
113
|
+
* </div>
|
|
114
|
+
* );
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* With authorization handling - use id in event payloads:
|
|
120
|
+
* ```tsx
|
|
121
|
+
* useOn(MapModeEvents.changeAuthorization, (event) => {
|
|
122
|
+
* const { authId, id } = event.payload;
|
|
123
|
+
* emitDecision({ authId, approved: true, owner: 'tool', id });
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
declare function MapProvider({ children, id }: MapProviderProps): react_jsx_runtime.JSX.Element;
|
|
128
|
+
|
|
129
|
+
export { MapContext, MapProvider, type MapProviderProps };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import 'client-only';
|
|
3
|
+
import { createContext, useEffect } from 'react';
|
|
4
|
+
import { clearMapModeState } from '../../map-mode/store.js';
|
|
5
|
+
|
|
6
|
+
const MapContext = createContext(null);
|
|
7
|
+
function MapProvider({ children, id }) {
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
return () => {
|
|
10
|
+
clearMapModeState(id);
|
|
11
|
+
};
|
|
12
|
+
}, [id]);
|
|
13
|
+
return /* @__PURE__ */ jsx(MapContext.Provider, { value: id, children });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { MapContext, MapProvider };
|
|
17
|
+
//# sourceMappingURL=provider.js.map
|
|
18
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/deckgl/base-map/provider.tsx"],"names":[],"mappings":";;;;;AAuBO,MAAM,UAAA,GAAa,cAA+B,IAAI;AAuHtD,SAAS,WAAA,CAAY,EAAE,QAAA,EAAU,EAAA,EAAG,EAAqB;AAG9D,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAO,MAAM;AACX,MAAA,iBAAA,CAAkB,EAAE,CAAA;AAAA,IACtB,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,EAAE,CAAC,CAAA;AAEP,EAAA,2BAAQ,UAAA,CAAW,QAAA,EAAX,EAAoB,KAAA,EAAO,IAAK,QAAA,EAAS,CAAA;AACnD","file":"provider.js","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 { createContext, type ReactNode, useEffect } from 'react';\nimport { clearMapModeState } from '../../map-mode/store';\nimport type { UniqueId } from '@accelint/core';\n\n/**\n * React context for map ID.\n * Use the `useMapMode` hook to access the map mode state.\n */\nexport const MapContext = createContext<UniqueId | null>(null);\n\n/**\n * Props for the MapProvider component.\n */\nexport type MapProviderProps = {\n /** Child components that will have access to map mode context */\n children: ReactNode;\n /**\n * Unique identifier for this map instance.\n *\n * Used to isolate mode changes between different map instances (e.g., main map vs minimap).\n * This is required and should be provided by the parent component (typically BaseMap).\n *\n * @example\n * ```tsx\n * // Multiple independent map instances\n * const mainMapId = uuid();\n * const minimapId = uuid();\n *\n * <MapProvider id={mainMapId}>\n * // Map layers and components\n * </MapProvider>\n *\n * <MapProvider id={minimapId}>\n * // Minimap layers and components\n * </MapProvider>\n * ```\n */\n id: UniqueId;\n};\n\n/**\n * Provider component for managing map modes with ownership and authorization.\n *\n * **Note**: This provider is used internally by `BaseMap` and should not be used directly.\n * Consumers should pass the `id` prop to `BaseMap`, which will create this provider automatically.\n *\n * This component uses a hybrid architecture combining React Context (for map instance identity)\n * with module-level state management (for map mode state). The provider:\n * - Provides a unique `id` via Context\n * - Cleans up map mode state when unmounted\n * - Allows components to subscribe to mode changes via `useMapMode` hook (which uses `useSyncExternalStore`)\n *\n * The module-level state management system implements a state machine for map modes where\n * components can request mode changes with ownership. When a mode is owned by a component,\n * other components must request authorization to change to a different mode. The system handles:\n *\n * - Automatic mode changes when no ownership conflicts exist\n * - Authorization flow when switching between owned modes\n * - Per-mode ownership tracking that persists throughout the session\n * - Pending request management (one pending request per requester)\n * - Auto-acceptance of first pending request when mode owner returns to default\n * - Auto-rejection of other pending requests when one is approved\n * - Event emission through a centralized event bus\n * - Instance isolation for multiple map scenarios (main map + minimap)\n * - Always initializes in 'default' mode\n *\n * ## Instance Isolation\n *\n * Each MapProvider instance operates independently. Mode changes in one instance\n * do not affect other instances, even when multiple maps are rendered on the same page.\n * This enables scenarios like:\n * - Main map in \"drawing\" mode while minimap stays in \"view\" mode\n * - Multiple independent map views with different interaction modes\n *\n * Events are scoped to specific instances using the `id` prop. The event bus\n * filters events to ensure each provider only responds to events for its own instance.\n *\n * ## Pending Request Behavior\n *\n * - Pending requests are stored by requester ID (not mode owner)\n * - Each requester can have only one pending request at a time\n * - New requests from the same requester auto-replace previous requests\n * - Pending requests persist when mode owner switches between their own modes\n * - When any request is approved, all other pending requests are auto-rejected\n * - When mode owner returns to default mode:\n * - If first pending request is for default mode, all pending requests are rejected (already in requested mode)\n * - If first pending request is for a different mode, that request is auto-approved and others are rejected\n *\n * ## Instance ID Stability and Lifecycle\n *\n * The provider's cleanup mechanism (via `useEffect`) ensures proper state management:\n * - Map mode state is cleaned up when the provider unmounts\n * - Changing the `id` prop will trigger cleanup of the old state via the effect dependency\n * - State is lazily initialized on first subscription (no manual creation needed)\n *\n * While the `id` prop should typically remain stable (created as a module-level constant\n * or with `useState`), changing it will work correctly due to the cleanup mechanism.\n *\n * @param props - Provider props including children and required id\n * @returns Provider component that wraps children with map instance identity context\n *\n * @example\n * Internal usage within BaseMap:\n * ```tsx\n * // BaseMap automatically creates the provider\n * function BaseMap({ id, children, ...props }: BaseMapProps) {\n * return (\n * <div>\n * <MapProvider id={id}>\n * <Deckgl {...props}>\n * {children}\n * </Deckgl>\n * </MapProvider>\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * With authorization handling - use id in event payloads:\n * ```tsx\n * useOn(MapModeEvents.changeAuthorization, (event) => {\n * const { authId, id } = event.payload;\n * emitDecision({ authId, approved: true, owner: 'tool', id });\n * });\n * ```\n */\nexport function MapProvider({ children, id }: MapProviderProps) {\n // Cleanup when component unmounts\n // State is created automatically on first subscription in useMapMode\n useEffect(() => {\n return () => {\n clearMapModeState(id);\n };\n }, [id]);\n\n return <MapContext.Provider value={id}>{children}</MapContext.Provider>;\n}\n"]}
|
|
@@ -1,21 +1,82 @@
|
|
|
1
1
|
import { Payload } from '@accelint/bus';
|
|
2
|
+
import { UniqueId } from '@accelint/core';
|
|
2
3
|
import { PickingInfo } from '@deck.gl/core';
|
|
3
4
|
import { MjolnirGestureEvent, MjolnirPointerEvent } from 'mjolnir.js';
|
|
4
5
|
import { MapEvents } from './events.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* PickingInfo modified for serialization through the event bus.
|
|
9
|
+
* Omits viewport, layer, and sourceLayer (which contain non-serializable functions),
|
|
10
|
+
* and adds layerId and sourceLayerId extracted from the original layer objects.
|
|
11
|
+
*/
|
|
12
|
+
type NonFuncPickingInfo = Omit<PickingInfo, 'viewport' | 'layer' | 'sourceLayer'> & {
|
|
13
|
+
/** ID of the picked layer (extracted from layer.id before omission) */
|
|
14
|
+
layerId?: NonNullable<PickingInfo['layer']>['id'];
|
|
15
|
+
/** ID of the source layer if applicable (extracted from sourceLayer.id before omission) */
|
|
16
|
+
sourceLayerId?: NonNullable<PickingInfo['sourceLayer']>['id'];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* MjolnirGestureEvent without function properties and non-serializable objects.
|
|
20
|
+
* These properties are omitted to allow the event to be serialized through the event bus.
|
|
21
|
+
*/
|
|
7
22
|
type NonFuncMjolnirGestureEvent = Omit<MjolnirGestureEvent, 'stopPropagation' | 'preventDefault' | 'stopImmediatePropagation' | 'srcEvent' | 'rootElement' | 'target' | 'changedPointers' | 'pointers'>;
|
|
23
|
+
/**
|
|
24
|
+
* MjolnirPointerEvent without function properties and non-serializable objects.
|
|
25
|
+
* These properties are omitted to allow the event to be serialized through the event bus.
|
|
26
|
+
*/
|
|
8
27
|
type NonFuncMjolnirPointerEvent = Omit<MjolnirPointerEvent, 'stopPropagation' | 'preventDefault' | 'stopImmediatePropagation' | 'srcEvent' | 'rootElement' | 'target'>;
|
|
28
|
+
/**
|
|
29
|
+
* Payload for map click events emitted through the event bus.
|
|
30
|
+
* Contains picking information about what was clicked and the gesture event details.
|
|
31
|
+
*/
|
|
9
32
|
type MapClickPayload = {
|
|
33
|
+
/** Information about the picked object and its properties */
|
|
10
34
|
info: NonFuncPickingInfo;
|
|
35
|
+
/** The gesture event that triggered the click */
|
|
11
36
|
event: NonFuncMjolnirGestureEvent;
|
|
37
|
+
/** The map instance the event occurred within */
|
|
38
|
+
id: UniqueId;
|
|
12
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Payload for map hover events emitted through the event bus.
|
|
42
|
+
* Contains picking information about what is being hovered and the pointer event details.
|
|
43
|
+
*/
|
|
13
44
|
type MapHoverPayload = {
|
|
45
|
+
/** Information about the picked object and its properties */
|
|
14
46
|
info: NonFuncPickingInfo;
|
|
47
|
+
/** The pointer event that triggered the hover */
|
|
15
48
|
event: NonFuncMjolnirPointerEvent;
|
|
49
|
+
/** The map instance the event occurred within */
|
|
50
|
+
id: UniqueId;
|
|
51
|
+
};
|
|
52
|
+
type Bounds = [
|
|
53
|
+
minLon: number,
|
|
54
|
+
minLat: number,
|
|
55
|
+
maxLon: number,
|
|
56
|
+
maxLat: number
|
|
57
|
+
];
|
|
58
|
+
type MapViewportPayload = {
|
|
59
|
+
bounds: Bounds;
|
|
60
|
+
latitude: number;
|
|
61
|
+
longitude: number;
|
|
62
|
+
zoom: number;
|
|
63
|
+
/** Viewport width in pixels */
|
|
64
|
+
width: number;
|
|
65
|
+
/** Viewport height in pixels */
|
|
66
|
+
height: number;
|
|
67
|
+
id: UniqueId;
|
|
16
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Type for map click events in the event bus.
|
|
71
|
+
* Combines the event name with the click payload.
|
|
72
|
+
*/
|
|
17
73
|
type MapClickEvent = Payload<typeof MapEvents.click, MapClickPayload>;
|
|
74
|
+
/**
|
|
75
|
+
* Type for map hover events in the event bus.
|
|
76
|
+
* Combines the event name with the hover payload.
|
|
77
|
+
*/
|
|
18
78
|
type MapHoverEvent = Payload<typeof MapEvents.hover, MapHoverPayload>;
|
|
19
|
-
type
|
|
79
|
+
type MapViewportEvent = Payload<typeof MapEvents.viewport, MapViewportPayload>;
|
|
80
|
+
type MapEventType = MapClickEvent | MapHoverEvent | MapViewportEvent;
|
|
20
81
|
|
|
21
|
-
export type { MapClickEvent, MapClickPayload, MapEventType, MapHoverEvent, MapHoverPayload };
|
|
82
|
+
export type { Bounds, MapClickEvent, MapClickPayload, MapEventType, MapHoverEvent, MapHoverPayload, MapViewportEvent, MapViewportPayload };
|
package/dist/deckgl/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
export { BaseMap,
|
|
1
|
+
export { BaseMap, BaseMapProps } from './base-map/index.js';
|
|
2
2
|
export { BASE_MAP_STYLE, PARAMETERS } from './base-map/constants.js';
|
|
3
3
|
export { MapEvents, MapEventsNamespace } from './base-map/events.js';
|
|
4
4
|
export { SymbolLayer, SymbolLayerProps } from './symbol-layer/index.js';
|
|
5
5
|
export { MapClickEvent, MapClickPayload, MapEventType, MapHoverEvent, MapHoverPayload } from './base-map/types.js';
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
|
-
import '@accelint/
|
|
7
|
+
import '@accelint/core';
|
|
8
8
|
import '@deckgl-fiber-renderer/types';
|
|
9
9
|
import '@deck.gl/layers';
|
|
10
10
|
import 'milsymbol';
|
|
11
11
|
import '@deck.gl/core';
|
|
12
|
+
import '@accelint/bus';
|
|
12
13
|
import 'mjolnir.js';
|
package/dist/deckgl/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BaseMap
|
|
1
|
+
export { BaseMap } from './base-map/index.js';
|
|
2
2
|
export { BASE_MAP_STYLE, PARAMETERS } from './base-map/constants.js';
|
|
3
3
|
export { MapEvents, MapEventsNamespace } from './base-map/events.js';
|
|
4
4
|
export { SymbolLayer } from './symbol-layer/index.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type CharacterSetsKeys = keyof typeof CHARACTER_SETS;
|
|
2
|
+
/**
|
|
3
|
+
* Predefined character sets for TextLayer.
|
|
4
|
+
*
|
|
5
|
+
* Use smaller character sets (ASCII_ALL, ASCII_ALPHA_NUMERIC) for better performance,
|
|
6
|
+
* or use AUTO for dynamic optimization based on content.
|
|
7
|
+
* EXPANDED includes ASCII and Latin characters with diacritics for international text.
|
|
8
|
+
*/
|
|
9
|
+
declare const CHARACTER_SETS: Readonly<{
|
|
10
|
+
readonly ALL_NUMBERS: "1234567890";
|
|
11
|
+
readonly ASCII_ALL: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 !\"#$%&'()*+,-./:;<=>?@[]^_`{|}~";
|
|
12
|
+
readonly ASCII_ALPHA_NUMERIC: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
|
13
|
+
readonly ASCII_LETTERS: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
14
|
+
readonly ASCII_LETTERS_LOWERCASE: "abcdefghijklmnopqrstuvwxyz";
|
|
15
|
+
readonly ASCII_LETTERS_UPPERCASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
16
|
+
readonly ASCII_SYMBOLS: " !\"#$%&'()*+,-./:;<=>?@[]^_`{|}~";
|
|
17
|
+
readonly AUTO: "auto";
|
|
18
|
+
readonly EXPANDED: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 !\"#$%&'()*+,-./:;<=>?@[]^_`{|}~àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿßÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ1234567890 ¡¿¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿×÷";
|
|
19
|
+
readonly LATIN_ALL: "àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿßÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ1234567890 ¡¿¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿×÷";
|
|
20
|
+
readonly LATIN_ALPHA_NUMERIC: "àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿßÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ1234567890";
|
|
21
|
+
readonly LATIN_LETTERS: "àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿßÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ";
|
|
22
|
+
readonly LATIN_LETTERS_LOWERCASE: "àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿß";
|
|
23
|
+
readonly LATIN_LETTERS_UPPERCASE: "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ";
|
|
24
|
+
readonly LATIN_SYMBOLS: " ¡¿¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿×÷";
|
|
25
|
+
}>;
|
|
26
|
+
|
|
27
|
+
export { CHARACTER_SETS, type CharacterSetsKeys };
|