@accelint/map-toolkit 0.3.1 → 0.4.1
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 +49 -24
- package/catalog-info.yaml +5 -7
- package/dist/cursor-coordinates/index.d.ts +14 -3
- package/dist/cursor-coordinates/index.js +16 -3
- package/dist/cursor-coordinates/use-cursor-coordinates.d.ts +20 -6
- package/dist/cursor-coordinates/use-cursor-coordinates.js +247 -128
- package/dist/cursor-coordinates/use-cursor-coordinates.js.map +1 -1
- package/dist/deckgl/base-map/constants.d.ts +14 -12
- package/dist/deckgl/base-map/constants.js +26 -12
- package/dist/deckgl/base-map/constants.js.map +1 -1
- package/dist/deckgl/base-map/events.d.ts +6 -4
- package/dist/deckgl/base-map/events.js +18 -4
- package/dist/deckgl/base-map/events.js.map +1 -1
- package/dist/deckgl/base-map/index.d.ts +45 -18
- package/dist/deckgl/base-map/index.js +216 -148
- package/dist/deckgl/base-map/index.js.map +1 -1
- package/dist/deckgl/base-map/provider.d.ts +48 -32
- package/dist/deckgl/base-map/provider.js +122 -11
- package/dist/deckgl/base-map/provider.js.map +1 -1
- package/dist/deckgl/base-map/types.d.ts +49 -39
- package/dist/deckgl/base-map/types.js +11 -2
- package/dist/deckgl/index.d.ts +18 -13
- package/dist/deckgl/index.js +19 -6
- package/dist/deckgl/symbol-layer/fiber.d.ts +21 -10
- package/dist/deckgl/symbol-layer/fiber.js +18 -3
- package/dist/deckgl/symbol-layer/fiber.js.map +1 -1
- package/dist/deckgl/symbol-layer/index.d.ts +68 -54
- package/dist/deckgl/symbol-layer/index.js +105 -85
- package/dist/deckgl/symbol-layer/index.js.map +1 -1
- package/dist/deckgl/text-layer/character-sets.d.ts +19 -17
- package/dist/deckgl/text-layer/character-sets.js +40 -19
- package/dist/deckgl/text-layer/character-sets.js.map +1 -1
- package/dist/deckgl/text-layer/default-settings.d.ts +16 -2
- package/dist/deckgl/text-layer/default-settings.js +42 -18
- package/dist/deckgl/text-layer/default-settings.js.map +1 -1
- package/dist/deckgl/text-layer/fiber.d.ts +38 -27
- package/dist/deckgl/text-layer/fiber.js +18 -3
- package/dist/deckgl/text-layer/fiber.js.map +1 -1
- package/dist/deckgl/text-layer/index.d.ts +39 -25
- package/dist/deckgl/text-layer/index.js +47 -29
- package/dist/deckgl/text-layer/index.js.map +1 -1
- package/dist/decorators/deckgl.d.ts +16 -2
- package/dist/decorators/deckgl.js +25 -7
- package/dist/decorators/deckgl.js.map +1 -1
- package/dist/map-cursor/events.d.ts +16 -0
- package/dist/map-cursor/events.js +27 -0
- package/dist/map-cursor/events.js.map +1 -0
- package/dist/map-cursor/index.d.ts +17 -0
- package/dist/map-cursor/index.js +18 -0
- package/dist/map-cursor/store.d.ts +93 -0
- package/dist/map-cursor/store.js +351 -0
- package/dist/map-cursor/store.js.map +1 -0
- package/dist/map-cursor/types.d.ts +81 -0
- package/dist/map-cursor/types.js +12 -0
- package/dist/map-cursor/use-map-cursor.d.ts +99 -0
- package/dist/map-cursor/use-map-cursor.js +116 -0
- package/dist/map-cursor/use-map-cursor.js.map +1 -0
- package/dist/map-mode/events.d.ts +11 -9
- package/dist/map-mode/events.js +43 -9
- package/dist/map-mode/events.js.map +1 -1
- package/dist/map-mode/index.d.ts +17 -6
- package/dist/map-mode/index.js +18 -5
- package/dist/map-mode/store.d.ts +26 -3
- package/dist/map-mode/store.js +329 -265
- package/dist/map-mode/store.js.map +1 -1
- package/dist/map-mode/types.d.ts +49 -35
- package/dist/map-mode/types.js +11 -2
- package/dist/map-mode/use-map-mode.d.ts +21 -7
- package/dist/map-mode/use-map-mode.js +66 -23
- package/dist/map-mode/use-map-mode.js.map +1 -1
- package/dist/maplibre/constants.d.ts +10 -8
- package/dist/maplibre/constants.js +22 -8
- package/dist/maplibre/constants.js.map +1 -1
- package/dist/maplibre/hooks/use-maplibre.d.ts +17 -2
- package/dist/maplibre/hooks/use-maplibre.js +77 -31
- package/dist/maplibre/hooks/use-maplibre.js.map +1 -1
- package/dist/maplibre/index.d.ts +15 -3
- package/dist/maplibre/index.js +17 -4
- package/dist/viewport/constants.d.ts +8 -6
- package/dist/viewport/constants.js +20 -6
- package/dist/viewport/constants.js.map +1 -1
- package/dist/viewport/index.d.ts +18 -13
- package/dist/viewport/index.js +19 -6
- package/dist/viewport/types.d.ts +27 -17
- package/dist/viewport/types.js +11 -2
- package/dist/viewport/use-viewport-state.d.ts +29 -14
- package/dist/viewport/use-viewport-state.js +200 -87
- package/dist/viewport/use-viewport-state.js.map +1 -1
- package/dist/viewport/utils.d.ts +25 -10
- package/dist/viewport/utils.js +67 -37
- package/dist/viewport/utils.js.map +1 -1
- package/dist/viewport/viewport-size.d.ts +27 -15
- package/dist/viewport/viewport-size.js +54 -11
- package/dist/viewport/viewport-size.js.map +1 -1
- package/package.json +107 -78
- package/dist/cursor-coordinates/index.js.map +0 -1
- package/dist/deckgl/base-map/types.js.map +0 -1
- package/dist/deckgl/index.js.map +0 -1
- package/dist/map-mode/index.js.map +0 -1
- package/dist/map-mode/types.js.map +0 -1
- package/dist/maplibre/index.js.map +0 -1
- package/dist/metafile-esm.json +0 -1
- package/dist/viewport/index.js.map +0 -1
- package/dist/viewport/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"use-maplibre.js","names":["MapLibre"],"sources":["../../../src/maplibre/hooks/use-maplibre.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 { type IControl, Map as MapLibre, type MapOptions } from 'maplibre-gl';\nimport { useEffect, useRef } from 'react';\n\n/**\n * Hook to integrate a MapLibre GL map with a Deck.gl instance.\n *\n * This hook manages the lifecycle of a MapLibre map, including initialization,\n * style updates, and cleanup. It ensures the Deck.gl control is properly added\n * to the map and handles cleanup when the component unmounts.\n *\n * @param deck - The Deck.gl IControl instance to add to the map\n * @param styleUrl - The MapLibre style URL to use for the map\n * @param options - MapLibre map options (container, center, zoom, etc.)\n * @returns The MapLibre map instance, or null if not yet initialized\n *\n * @example\n * ```tsx\n * function MapComponent() {\n * const deckglInstance = useDeckgl();\n * const container = useId();\n *\n * const mapOptions = useMemo(() => ({\n * container,\n * center: [-122.4, 37.8],\n * zoom: 12,\n * }), [container]);\n *\n * useMapLibre(\n * deckglInstance as IControl,\n * 'https://tiles.example.com/style.json',\n * mapOptions\n * );\n *\n * return <div id={container} />;\n * }\n * ```\n */\nexport function useMapLibre(\n deck: IControl | null,\n styleUrl: string,\n options: MapOptions,\n) {\n const mapRef = useRef<MapLibre | null>(null);\n // Using a ref for options to avoid re-creating the map when options object reference changes\n // The map is only created once on mount, options changes after that are ignored\n const optionsRef = useRef(options);\n // using a ref in the initial setup so that it doesn't cause a re-run of the effect on change\n const styleRef = useRef(styleUrl);\n\n // Initialize MapLibre instance once\n useEffect(() => {\n if (deck && !mapRef.current) {\n mapRef.current = new MapLibre({\n ...optionsRef.current,\n style: styleRef.current,\n });\n\n mapRef.current.once('style.load', () => {\n mapRef.current?.setProjection({ type: 'mercator' });\n mapRef.current?.addControl(deck);\n });\n\n return () => {\n if (mapRef.current) {\n mapRef.current.removeControl(deck);\n mapRef.current.remove();\n mapRef.current = null;\n }\n };\n }\n }, [deck]);\n\n // Update style when it changes\n useEffect(() => {\n if (mapRef.current) {\n mapRef.current.setStyle(styleUrl);\n }\n }, [styleUrl]);\n\n return mapRef.current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,YACd,MACA,UACA,SACA;CACA,MAAM,SAAS,OAAwB,KAAK;CAG5C,MAAM,aAAa,OAAO,QAAQ;CAElC,MAAM,WAAW,OAAO,SAAS;AAGjC,iBAAgB;AACd,MAAI,QAAQ,CAAC,OAAO,SAAS;AAC3B,UAAO,UAAU,IAAIA,IAAS;IAC5B,GAAG,WAAW;IACd,OAAO,SAAS;IACjB,CAAC;AAEF,UAAO,QAAQ,KAAK,oBAAoB;AACtC,WAAO,SAAS,cAAc,EAAE,MAAM,YAAY,CAAC;AACnD,WAAO,SAAS,WAAW,KAAK;KAChC;AAEF,gBAAa;AACX,QAAI,OAAO,SAAS;AAClB,YAAO,QAAQ,cAAc,KAAK;AAClC,YAAO,QAAQ,QAAQ;AACvB,YAAO,UAAU;;;;IAItB,CAAC,KAAK,CAAC;AAGV,iBAAgB;AACd,MAAI,OAAO,QACT,QAAO,QAAQ,SAAS,SAAS;IAElC,CAAC,SAAS,CAAC;AAEd,QAAO,OAAO"}
|
package/dist/maplibre/index.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 { INITIAL_VIEW_STATE } from "./constants.js";
|
|
14
|
+
import { useMapLibre } from "./hooks/use-maplibre.js";
|
|
15
|
+
export { INITIAL_VIEW_STATE, useMapLibre };
|
package/dist/maplibre/index.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 { INITIAL_VIEW_STATE } from "./constants.js";
|
|
15
|
+
import { useMapLibre } from "./hooks/use-maplibre.js";
|
|
16
|
+
|
|
17
|
+
export { INITIAL_VIEW_STATE, useMapLibre };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
//#region src/viewport/constants.d.ts
|
|
1
2
|
declare const UNIT_MAP: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
readonly km: "kilometers";
|
|
4
|
+
readonly m: "meters";
|
|
5
|
+
readonly nm: "nauticalmiles";
|
|
6
|
+
readonly mi: "miles";
|
|
7
|
+
readonly ft: "feet";
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
+
//#endregion
|
|
9
10
|
export { UNIT_MAP };
|
|
11
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1,11 +1,25 @@
|
|
|
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
|
+
//#region src/viewport/constants.ts
|
|
1
15
|
const UNIT_MAP = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
16
|
+
km: "kilometers",
|
|
17
|
+
m: "meters",
|
|
18
|
+
nm: "nauticalmiles",
|
|
19
|
+
mi: "miles",
|
|
20
|
+
ft: "feet"
|
|
7
21
|
};
|
|
8
22
|
|
|
23
|
+
//#endregion
|
|
9
24
|
export { UNIT_MAP };
|
|
10
|
-
//# sourceMappingURL=constants.js.map
|
|
11
25
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../src/viewport/constants.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\nexport const UNIT_MAP = {\n km: 'kilometers',\n m: 'meters',\n nm: 'nauticalmiles',\n mi: 'miles',\n ft: 'feet',\n} as const;\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAa,WAAW;CACtB,IAAI;CACJ,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,IAAI;CACL"}
|
package/dist/viewport/index.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import
|
|
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 { UNIT_MAP } from "./constants.js";
|
|
14
|
+
import { UseViewportStateProps, clearViewportState, useViewportState } from "./use-viewport-state.js";
|
|
15
|
+
import { GeoCoordinate, GetViewportSizeArgs, SupportedDistanceUnit } from "./types.js";
|
|
16
|
+
import { getViewportSize } from "./utils.js";
|
|
17
|
+
import { ViewportSize, ViewportSizeProps } from "./viewport-size.js";
|
|
18
|
+
export { type GeoCoordinate, type GetViewportSizeArgs, type SupportedDistanceUnit, UNIT_MAP, type UseViewportStateProps, ViewportSize, type ViewportSizeProps, clearViewportState, getViewportSize, useViewportState };
|
package/dist/viewport/index.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 { UNIT_MAP } from "./constants.js";
|
|
15
|
+
import { clearViewportState, useViewportState } from "./use-viewport-state.js";
|
|
16
|
+
import { getViewportSize } from "./utils.js";
|
|
17
|
+
import { ViewportSize } from "./viewport-size.js";
|
|
18
|
+
|
|
19
|
+
export { UNIT_MAP, ViewportSize, clearViewportState, getViewportSize, useViewportState };
|
package/dist/viewport/types.d.ts
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
*/
|
|
8
12
|
|
|
13
|
+
import { Bounds } from "../deckgl/base-map/types.js";
|
|
14
|
+
import { UNIT_MAP } from "./constants.js";
|
|
15
|
+
|
|
16
|
+
//#region src/viewport/types.d.ts
|
|
9
17
|
type SupportedDistanceUnit = keyof typeof UNIT_MAP;
|
|
10
18
|
type GetViewportSizeArgs = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
/** Geographic bounds, undefined if viewport not yet initialized */
|
|
20
|
+
bounds?: Bounds;
|
|
21
|
+
zoom: number;
|
|
22
|
+
/** Viewport width in pixels */
|
|
23
|
+
width: number;
|
|
24
|
+
/** Viewport height in pixels */
|
|
25
|
+
height: number;
|
|
26
|
+
unit?: SupportedDistanceUnit;
|
|
27
|
+
formatter?: Intl.NumberFormat;
|
|
19
28
|
};
|
|
20
29
|
type GeoCoordinate = [longitude: number, latitude: number];
|
|
21
|
-
|
|
22
|
-
export
|
|
30
|
+
//#endregion
|
|
31
|
+
export { GeoCoordinate, GetViewportSizeArgs, SupportedDistanceUnit };
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/viewport/types.js
CHANGED
|
@@ -1,3 +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
|
+
*/
|
|
1
12
|
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
3
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
*/
|
|
8
12
|
|
|
13
|
+
import { MapViewportPayload } from "../deckgl/base-map/types.js";
|
|
14
|
+
import { useSyncExternalStore } from "react";
|
|
15
|
+
import { UniqueId } from "@accelint/core";
|
|
16
|
+
|
|
17
|
+
//#region src/viewport/use-viewport-state.d.ts
|
|
9
18
|
type UseViewportStateProps = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
instanceId: UniqueId;
|
|
20
|
+
subscribe?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[0];
|
|
21
|
+
getSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[1];
|
|
22
|
+
getServerSnapshot?: Parameters<typeof useSyncExternalStore<MapViewportPayload>>[2];
|
|
14
23
|
};
|
|
15
24
|
/**
|
|
16
25
|
* Hook to subscribe to viewport state changes for a specific view.
|
|
@@ -66,7 +75,12 @@ type UseViewportStateProps = {
|
|
|
66
75
|
* }
|
|
67
76
|
* ```
|
|
68
77
|
*/
|
|
69
|
-
declare function useViewportState({
|
|
78
|
+
declare function useViewportState({
|
|
79
|
+
instanceId,
|
|
80
|
+
subscribe,
|
|
81
|
+
getSnapshot,
|
|
82
|
+
getServerSnapshot
|
|
83
|
+
}: UseViewportStateProps): MapViewportPayload;
|
|
70
84
|
/**
|
|
71
85
|
* Manually clear viewport state for a specific instanceId.
|
|
72
86
|
* This is typically not needed as cleanup happens automatically when all subscribers unmount.
|
|
@@ -81,5 +95,6 @@ declare function useViewportState({ instanceId, subscribe, getSnapshot, getServe
|
|
|
81
95
|
* ```
|
|
82
96
|
*/
|
|
83
97
|
declare function clearViewportState(instanceId: UniqueId): void;
|
|
84
|
-
|
|
85
|
-
export {
|
|
98
|
+
//#endregion
|
|
99
|
+
export { UseViewportStateProps, clearViewportState, useViewportState };
|
|
100
|
+
//# sourceMappingURL=use-viewport-state.d.ts.map
|
|
@@ -1,109 +1,222 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
*/
|
|
4
12
|
|
|
13
|
+
|
|
14
|
+
import { MapEvents } from "../deckgl/base-map/events.js";
|
|
15
|
+
import { Broadcast } from "@accelint/bus";
|
|
16
|
+
import { useSyncExternalStore } from "react";
|
|
17
|
+
|
|
18
|
+
//#region src/viewport/use-viewport-state.ts
|
|
5
19
|
const bus = Broadcast.getInstance();
|
|
20
|
+
/**
|
|
21
|
+
* Store for viewport state keyed by instanceId
|
|
22
|
+
*/
|
|
6
23
|
const viewportStore = /* @__PURE__ */ new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Track React component subscribers per instanceId (for fan-out notifications).
|
|
26
|
+
* Each Set contains onStoreChange callbacks from useSyncExternalStore.
|
|
27
|
+
*/
|
|
7
28
|
const componentSubscribers = /* @__PURE__ */ new Map();
|
|
29
|
+
/**
|
|
30
|
+
* Cache of bus unsubscribe functions (1 per instanceId).
|
|
31
|
+
* This ensures we only have one bus listener per viewport, regardless of
|
|
32
|
+
* how many React components subscribe to it.
|
|
33
|
+
*/
|
|
8
34
|
const busUnsubscribers = /* @__PURE__ */ new Map();
|
|
35
|
+
/**
|
|
36
|
+
* Cache of subscription functions per instanceId to avoid recreating on every render
|
|
37
|
+
*/
|
|
9
38
|
const subscriptionCache = /* @__PURE__ */ new Map();
|
|
39
|
+
/**
|
|
40
|
+
* Cache of snapshot functions per instanceId to maintain referential stability
|
|
41
|
+
*/
|
|
10
42
|
const snapshotCache = /* @__PURE__ */ new Map();
|
|
43
|
+
/**
|
|
44
|
+
* Cache of fallback snapshots per instanceId to maintain referential stability.
|
|
45
|
+
* This prevents unnecessary re-renders when no viewport data exists yet.
|
|
46
|
+
*/
|
|
11
47
|
const fallbackCache = /* @__PURE__ */ new Map();
|
|
48
|
+
/**
|
|
49
|
+
* Ensures a single bus listener exists for the given instanceId.
|
|
50
|
+
* All React subscribers will be notified via fan-out when the bus event fires.
|
|
51
|
+
* This prevents creating N bus listeners for N React components.
|
|
52
|
+
*
|
|
53
|
+
* @param instanceId - The unique identifier for the viewport
|
|
54
|
+
*/
|
|
12
55
|
function ensureBusListener(instanceId) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
onStoreChange();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
busUnsubscribers.set(instanceId, unsub);
|
|
56
|
+
if (busUnsubscribers.has(instanceId)) return;
|
|
57
|
+
const unsub = bus.on(MapEvents.viewport, ({ payload }) => {
|
|
58
|
+
if (instanceId === payload.id) {
|
|
59
|
+
viewportStore.set(instanceId, payload);
|
|
60
|
+
const subscribers = componentSubscribers.get(instanceId);
|
|
61
|
+
if (subscribers) for (const onStoreChange of subscribers) onStoreChange();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
busUnsubscribers.set(instanceId, unsub);
|
|
28
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Cleans up the bus listener if no React subscribers remain.
|
|
68
|
+
*
|
|
69
|
+
* @param instanceId - The unique identifier for the viewport
|
|
70
|
+
*/
|
|
29
71
|
function cleanupBusListenerIfNeeded(instanceId) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
72
|
+
const subscribers = componentSubscribers.get(instanceId);
|
|
73
|
+
if (!subscribers || subscribers.size === 0) {
|
|
74
|
+
const unsub = busUnsubscribers.get(instanceId);
|
|
75
|
+
if (unsub) {
|
|
76
|
+
unsub();
|
|
77
|
+
busUnsubscribers.delete(instanceId);
|
|
78
|
+
}
|
|
79
|
+
viewportStore.delete(instanceId);
|
|
80
|
+
componentSubscribers.delete(instanceId);
|
|
81
|
+
subscriptionCache.delete(instanceId);
|
|
82
|
+
snapshotCache.delete(instanceId);
|
|
83
|
+
fallbackCache.delete(instanceId);
|
|
84
|
+
}
|
|
43
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates or retrieves a cached subscription function for a given instanceId.
|
|
88
|
+
* Uses a fan-out pattern: 1 bus listener -> N React subscribers.
|
|
89
|
+
* Automatically cleans up viewport state when the last subscriber unsubscribes.
|
|
90
|
+
*
|
|
91
|
+
* @param instanceId - The unique identifier for the viewport
|
|
92
|
+
* @returns A subscription function for useSyncExternalStore
|
|
93
|
+
*/
|
|
44
94
|
function getOrCreateSubscription(instanceId) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
subscriptionCache.set(instanceId, subscription);
|
|
62
|
-
return subscription;
|
|
95
|
+
const subscription = subscriptionCache.get(instanceId) ?? ((onStoreChange) => {
|
|
96
|
+
ensureBusListener(instanceId);
|
|
97
|
+
let subscriberSet = componentSubscribers.get(instanceId);
|
|
98
|
+
if (!subscriberSet) {
|
|
99
|
+
subscriberSet = /* @__PURE__ */ new Set();
|
|
100
|
+
componentSubscribers.set(instanceId, subscriberSet);
|
|
101
|
+
}
|
|
102
|
+
subscriberSet.add(onStoreChange);
|
|
103
|
+
return () => {
|
|
104
|
+
const currentSubscriberSet = componentSubscribers.get(instanceId);
|
|
105
|
+
if (currentSubscriberSet) currentSubscriberSet.delete(onStoreChange);
|
|
106
|
+
cleanupBusListenerIfNeeded(instanceId);
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
subscriptionCache.set(instanceId, subscription);
|
|
110
|
+
return subscription;
|
|
63
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Creates or retrieves a cached snapshot function for a given instanceId.
|
|
114
|
+
* The object returned gets equality checked, so it needs to be stable or React re-renders unnecessarily.
|
|
115
|
+
*
|
|
116
|
+
* @param instanceId - The unique identifier for the viewport
|
|
117
|
+
* @returns A snapshot function for useSyncExternalStore
|
|
118
|
+
*/
|
|
64
119
|
function getOrCreateSnapshot(instanceId) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
120
|
+
const fallback = fallbackCache.get(instanceId) ?? (() => {
|
|
121
|
+
const newFallback = {
|
|
122
|
+
id: instanceId,
|
|
123
|
+
bounds: void 0,
|
|
124
|
+
latitude: NaN,
|
|
125
|
+
longitude: NaN,
|
|
126
|
+
zoom: NaN,
|
|
127
|
+
width: 0,
|
|
128
|
+
height: 0
|
|
129
|
+
};
|
|
130
|
+
fallbackCache.set(instanceId, newFallback);
|
|
131
|
+
return newFallback;
|
|
132
|
+
})();
|
|
133
|
+
const snapshot = snapshotCache.get(instanceId) ?? (() => viewportStore.get(instanceId) ?? fallback);
|
|
134
|
+
snapshotCache.set(instanceId, snapshot);
|
|
135
|
+
return snapshot;
|
|
81
136
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Hook to subscribe to viewport state changes for a specific view.
|
|
139
|
+
*
|
|
140
|
+
* By default, subscribes to MapEvents.viewport events from the event bus and
|
|
141
|
+
* automatically cleans up when all subscribers unmount. For advanced use cases,
|
|
142
|
+
* custom subscribe/getSnapshot functions can be provided.
|
|
143
|
+
*
|
|
144
|
+
* A thin wrapper around [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).
|
|
145
|
+
*
|
|
146
|
+
* @param instanceId - Unique identifier for the viewport to track
|
|
147
|
+
* @param subscribe - Optional custom subscription function
|
|
148
|
+
* @param getSnapshot - Optional custom snapshot getter
|
|
149
|
+
* @param getServerSnapshot - Optional server-side snapshot getter
|
|
150
|
+
* @returns Current viewport state including bounds, latitude, longitude, zoom
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* function MapInfo({ instanceId }) {
|
|
155
|
+
* const { bounds, latitude, longitude, zoom } = useViewportState({
|
|
156
|
+
* instanceId
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* return (
|
|
160
|
+
* <div>
|
|
161
|
+
* Lat: {latitude?.toFixed(2)}, Lon: {longitude?.toFixed(2)}, Zoom: {zoom}
|
|
162
|
+
* </div>
|
|
163
|
+
* );
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```tsx
|
|
169
|
+
* // With custom subscribe/getSnapshot for advanced use cases
|
|
170
|
+
* function CustomMapInfo() {
|
|
171
|
+
* const customSubscribe = (onStoreChange) => {
|
|
172
|
+
* // Custom subscription logic
|
|
173
|
+
* return () => { // cleanup }
|
|
174
|
+
* }
|
|
175
|
+
*
|
|
176
|
+
* const customGetSnapshot = () => {
|
|
177
|
+
* // Custom snapshot logic
|
|
178
|
+
* return { latitude: 0, longitude: 0, zoom: 1 };
|
|
179
|
+
* };
|
|
180
|
+
*
|
|
181
|
+
* const viewState = useViewportState({
|
|
182
|
+
* instanceId: 'some-uuid',
|
|
183
|
+
* subscribe: customSubscribe,
|
|
184
|
+
* getSnapshot: customGetSnapshot,
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* return <div>Custom viewport state</div>;
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
function useViewportState({ instanceId, subscribe, getSnapshot, getServerSnapshot }) {
|
|
192
|
+
return useSyncExternalStore(subscribe ?? getOrCreateSubscription(instanceId), getSnapshot ?? getOrCreateSnapshot(instanceId), getServerSnapshot);
|
|
93
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Manually clear viewport state for a specific instanceId.
|
|
196
|
+
* This is typically not needed as cleanup happens automatically when all subscribers unmount.
|
|
197
|
+
* Use this only in advanced scenarios where manual cleanup is required.
|
|
198
|
+
*
|
|
199
|
+
* @param instanceId - The unique identifier for the viewport to clear
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```tsx
|
|
203
|
+
* // Manual cleanup (rarely needed)
|
|
204
|
+
* clearViewportState('my-map-instance');
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
94
207
|
function clearViewportState(instanceId) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
208
|
+
const unsub = busUnsubscribers.get(instanceId);
|
|
209
|
+
if (unsub) {
|
|
210
|
+
unsub();
|
|
211
|
+
busUnsubscribers.delete(instanceId);
|
|
212
|
+
}
|
|
213
|
+
viewportStore.delete(instanceId);
|
|
214
|
+
componentSubscribers.delete(instanceId);
|
|
215
|
+
subscriptionCache.delete(instanceId);
|
|
216
|
+
snapshotCache.delete(instanceId);
|
|
217
|
+
fallbackCache.delete(instanceId);
|
|
105
218
|
}
|
|
106
219
|
|
|
220
|
+
//#endregion
|
|
107
221
|
export { clearViewportState, useViewportState };
|
|
108
|
-
//# sourceMappingURL=use-viewport-state.js.map
|
|
109
222
|
//# sourceMappingURL=use-viewport-state.js.map
|