@geode/opengeodeweb-front 10.44.0-rc.5 → 10.44.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/app/assets/geode_objects.ts +1 -0
  2. package/app/components/BasemapAttribution.vue +28 -0
  3. package/app/components/Viewer/Basemap/CropOptions.vue +50 -0
  4. package/app/components/Viewer/Basemap/OpacityOptions.vue +52 -0
  5. package/app/components/Viewer/ContextMenu/ContextMenu.vue +5 -1
  6. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +6 -2
  7. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +49 -10
  8. package/app/components/Viewer/Ui.vue +6 -1
  9. package/app/composables/project_manager.ts +6 -97
  10. package/app/composables/project_manager_helpers/reset.ts +34 -0
  11. package/app/composables/project_manager_helpers/restore.ts +58 -0
  12. package/app/composables/project_manager_helpers/types.ts +24 -0
  13. package/app/composables/project_manager_helpers/viewer_session.ts +25 -0
  14. package/app/composables/viewer_context_menu.ts +10 -0
  15. package/app/stores/basemap.ts +52 -0
  16. package/app/stores/basemap_detail.ts +51 -0
  17. package/app/stores/basemap_helpers/builds.ts +158 -0
  18. package/app/stores/basemap_helpers/detail_layers.ts +72 -0
  19. package/app/stores/basemap_helpers/detail_map.ts +62 -0
  20. package/app/stores/basemap_helpers/detail_refresh.ts +134 -0
  21. package/app/stores/basemap_helpers/detail_view.ts +94 -0
  22. package/app/stores/basemap_helpers/extent.ts +40 -0
  23. package/app/stores/basemap_helpers/georeferenced.ts +50 -0
  24. package/app/stores/basemap_helpers/layers.ts +66 -0
  25. package/app/stores/basemap_helpers/settings.ts +87 -0
  26. package/app/stores/basemap_helpers/viewer.ts +114 -0
  27. package/app/stores/menu_helpers/basemap.ts +10 -0
  28. package/app/stores/menu_helpers/menus_data.ts +18 -120
  29. package/app/stores/menu_helpers/mesh/edged_curve.ts +12 -0
  30. package/app/stores/menu_helpers/mesh/grid.ts +24 -0
  31. package/app/stores/menu_helpers/mesh/point_set.ts +11 -0
  32. package/app/stores/menu_helpers/mesh/solid.ts +29 -0
  33. package/app/stores/menu_helpers/mesh/surface.ts +22 -0
  34. package/app/stores/menu_helpers/model.ts +25 -0
  35. package/app/stores/menu_helpers/types.ts +5 -0
  36. package/app/stores/viewer.ts +0 -1
  37. package/app/utils/basemap_tree.ts +76 -0
  38. package/app/utils/treeview.ts +12 -1
  39. package/app/utils/visible_map_area.ts +129 -0
  40. package/internal/stores/hybrid_viewer/vtk_types.ts +2 -1
  41. package/package.json +1 -1
@@ -0,0 +1,52 @@
1
+ import { useBasemapBuilds } from "./basemap_helpers/builds.js";
2
+ import { useBasemapLayers } from "./basemap_helpers/layers.js";
3
+ import { useBasemapSettings } from "./basemap_helpers/settings.js";
4
+ import { useDebounceFn } from "@vueuse/core";
5
+ import { useGeoreferenced } from "./basemap_helpers/georeferenced.js";
6
+
7
+ const REBUILD_DELAY_MILLISECONDS = 500;
8
+
9
+ export const useBasemapStore = defineStore("basemap", () => {
10
+ const { available, georeferencedIds, dataBounds, dataKey } = useGeoreferenced();
11
+ const layers = useBasemapLayers(georeferencedIds);
12
+ const { shown, maps, opacities, crop, layersParams, applyLayers, applyBasemap } = layers;
13
+ const { basemapId, grid, attribution, rebuild, reset } = useBasemapBuilds(layers, dataBounds);
14
+ const settings = useBasemapSettings(layers, basemapId, rebuild);
15
+ const { setMaps, setOpacity, setCrop, exportStores, importStores } = settings;
16
+
17
+ const scheduleRebuild = useDebounceFn(() => {
18
+ void rebuild();
19
+ }, REBUILD_DELAY_MILLISECONDS);
20
+ // Rebuilt when the georeferenced data or their extent change: data added, removed, converted,
21
+ // Aligned, or displayed after a project import
22
+ watch(dataKey, () => {
23
+ // A hidden basemap would be out of date once shown again: the rebuild removes it
24
+ if (maps.value.length > 0 || basemapId.value !== undefined) {
25
+ void scheduleRebuild();
26
+ }
27
+ });
28
+
29
+ return {
30
+ maps,
31
+ shown,
32
+ opacities,
33
+ crop,
34
+ basemapId,
35
+ grid,
36
+ attribution,
37
+ available,
38
+ setMaps,
39
+ setOpacity,
40
+ setCrop,
41
+ rebuild,
42
+ reset,
43
+ layersParams,
44
+ applyLayers,
45
+ applyBasemap,
46
+ exportStores,
47
+ importStores,
48
+ };
49
+ });
50
+
51
+ export type { BasemapSnapshot } from "./basemap_helpers/settings.js";
52
+ export type { MapStyle } from "@ogw_front/utils/basemap_tree";
@@ -0,0 +1,51 @@
1
+ import { useBasemapStore } from "@ogw_front/stores/basemap";
2
+ import { useDetailLayers } from "./basemap_helpers/detail_layers.js";
3
+ import { useDetailMap } from "./basemap_helpers/detail_map.js";
4
+ import { useDetailRefresh } from "./basemap_helpers/detail_refresh.js";
5
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
6
+
7
+ // When the camera rests, the visible area of the basemap at the zoom of the screen
8
+ export const useBasemapDetailStore = defineStore("basemapDetail", () => {
9
+ const basemapStore = useBasemapStore();
10
+ const hybridViewerStore = useHybridViewerStore();
11
+ const detail = useDetailMap();
12
+ const { detailId, newRefresh, forget, clear } = detail;
13
+ const layers = useDetailLayers(detail);
14
+ const { scheduleRefresh, onCameraChange } = useDetailRefresh(detail, layers);
15
+
16
+ watch(() => hybridViewerStore.camera_options, onCameraChange, { deep: true });
17
+ watch(
18
+ () => hybridViewerStore.is_moving,
19
+ (moving) => {
20
+ if (moving) {
21
+ // The result of a refresh started before the move is obsolete
22
+ newRefresh();
23
+ } else {
24
+ scheduleRefresh();
25
+ }
26
+ },
27
+ );
28
+ // A new base (data changed, maps rebuilt) drops the detail, then a new one is built for it
29
+ // Once the camera rests
30
+ watch(
31
+ () => basemapStore.basemapId,
32
+ async (id) => {
33
+ await clear();
34
+ if (id !== undefined) {
35
+ scheduleRefresh();
36
+ }
37
+ },
38
+ );
39
+ watch(() => JSON.stringify(basemapStore.layersParams()), layers.syncLayers);
40
+ // A detail dropped for a missing map, or built while the maps changed, is built again
41
+ watch(() => basemapStore.maps.join(","), scheduleRefresh);
42
+
43
+ // A new project: the viewer and the back are already cleared, nothing is requested
44
+ basemapStore.$onAction(({ name }) => {
45
+ if (name === "reset") {
46
+ forget();
47
+ }
48
+ });
49
+
50
+ return { detailId };
51
+ });
@@ -0,0 +1,158 @@
1
+ import { type MapStyle, sortedMaps } from "@ogw_front/utils/basemap_tree";
2
+ import back_schemas, {
3
+ type BasemapBuildResponse,
4
+ type CRSList,
5
+ } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
6
+ import { ignoreError, useBasemapViewer } from "./viewer.js";
7
+ import type { BasemapLayers } from "./layers.js";
8
+ import type { Extent } from "./extent.js";
9
+ import type { Ref } from "vue";
10
+ import { useBackStore } from "@ogw_front/stores/back";
11
+ import { useCrsStore } from "@ogw_front/stores/crs";
12
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
13
+
14
+ // The grid of the basemap shown, and the height it lies at
15
+ interface BasemapGrid extends Pick<BasemapBuildResponse, "bounds" | "columns" | "zoom"> {
16
+ z: number;
17
+ }
18
+
19
+ interface BasemapBuilds {
20
+ basemapId: Ref<string | undefined>;
21
+ grid: Ref<BasemapGrid | undefined>;
22
+ attribution: Ref<string | undefined>;
23
+ rebuild: () => Promise<void>;
24
+ reset: () => void;
25
+ }
26
+
27
+ const BASEMAP_NAME = "basemap";
28
+
29
+ // The basemap downloaded for the visible maps around the data, one build replacing the other
30
+ // oxlint-disable max-lines-per-function, max-statements
31
+ function useBasemapBuilds(
32
+ layers: BasemapLayers,
33
+ dataBounds: () => Extent | undefined,
34
+ ): BasemapBuilds {
35
+ const { maps, hidden, built, layersParams, applyLayers, applyBasemap } = layers;
36
+ const backStore = useBackStore();
37
+ const crsStore = useCrsStore();
38
+ const hybridViewerStore = useHybridViewerStore();
39
+ const { discardMap } = useBasemapViewer();
40
+ const basemapId = ref<string | undefined>(undefined);
41
+ // The detail store compares its resolution with the screen
42
+ const grid = ref<BasemapGrid | undefined>(undefined);
43
+ const attribution = ref<string | undefined>(undefined);
44
+ // Each build gets a number: a build finishing after a newer one started is discarded
45
+ let lastBuild = 0;
46
+ // Builds up to this number belong to a project the viewer and the back already cleared
47
+ let lastBuildOfPreviousProject = 0;
48
+ // The maps of the basemap shown: a build that fails or is superseded gives them back
49
+ let shownMaps: MapStyle[] = [];
50
+
51
+ // A build of a previous project: the viewer and the back already cleared it
52
+ async function discardBuild(build: number, id: string, registered: boolean): Promise<void> {
53
+ if (build > lastBuildOfPreviousProject) {
54
+ await discardMap(id, registered);
55
+ }
56
+ }
57
+
58
+ function forget(): void {
59
+ basemapId.value = undefined;
60
+ grid.value = undefined;
61
+ built.value = [];
62
+ shownMaps = [];
63
+ attribution.value = undefined;
64
+ }
65
+
66
+ async function clear(): Promise<void> {
67
+ const id = basemapId.value;
68
+ forget();
69
+ if (id === undefined) {
70
+ return;
71
+ }
72
+ await discardMap(id, true);
73
+ await hybridViewerStore.remoteRender();
74
+ }
75
+
76
+ async function display(build: number, extent: Extent, crs: CRSList): Promise<void> {
77
+ const response = await backStore.request({
78
+ schema: back_schemas.opengeodeweb_back.basemap.build,
79
+ params: { maps: [...maps.value], crs, ...extent },
80
+ });
81
+ if (build !== lastBuild) {
82
+ // A newer build started: this result is obsolete
83
+ await discardBuild(build, response.id, false);
84
+ return;
85
+ }
86
+ const previousId = basemapId.value;
87
+ // The layers are computed from the maps just built
88
+ const builtMaps = sortedMaps(response.maps.map(({ map }) => map));
89
+ built.value = builtMaps;
90
+ // Only while this build still owns the built maps: a newer build may have set its own
91
+ function giveBackMaps(): void {
92
+ if (built.value === builtMaps) {
93
+ built.value = shownMaps;
94
+ }
95
+ }
96
+ let sentLayers = "";
97
+ try {
98
+ sentLayers = await applyBasemap(response, BASEMAP_NAME);
99
+ } catch (error) {
100
+ giveBackMaps();
101
+ // The new mesh must not stay registered without anyone tracking it
102
+ await discardBuild(build, response.id, true);
103
+ throw error;
104
+ }
105
+ if (build !== lastBuild) {
106
+ giveBackMaps();
107
+ // Superseded while applying: the new basemap must not stay displayed
108
+ await discardBuild(build, response.id, true);
109
+ return;
110
+ }
111
+ basemapId.value = response.id;
112
+ shownMaps = builtMaps;
113
+ const { bounds, zoom, columns } = response;
114
+ grid.value = { bounds, zoom, columns, z: extent.z };
115
+ attribution.value = response.attribution;
116
+ if (previousId !== undefined) {
117
+ await discardBuild(build, previousId, true);
118
+ }
119
+ // The states changed while the basemap was built: the viewer still has the old ones
120
+ if (JSON.stringify(layersParams()) !== sentLayers) {
121
+ await applyLayers(response.id);
122
+ }
123
+ // Always render: the first build has no previous basemap whose removal would render
124
+ await hybridViewerStore.remoteRender();
125
+ }
126
+
127
+ async function rebuild(): Promise<void> {
128
+ lastBuild += 1;
129
+ const build = lastBuild;
130
+ const extent = dataBounds();
131
+ const crs = crsStore.projectCrs;
132
+ if (maps.value.length === 0 || crs === undefined || extent === undefined) {
133
+ await clear();
134
+ return;
135
+ }
136
+ try {
137
+ await display(build, extent, crs);
138
+ } catch {
139
+ // The request feedback already shows the error: data changes must not repeat it forever
140
+ if (build === lastBuild) {
141
+ hidden.value = true;
142
+ await clear().catch(ignoreError);
143
+ }
144
+ }
145
+ }
146
+
147
+ // A new project: the viewer and the back were cleared, so nothing is requested
148
+ function reset(): void {
149
+ lastBuild += 1;
150
+ lastBuildOfPreviousProject = lastBuild;
151
+ forget();
152
+ }
153
+
154
+ return { basemapId, grid, attribution, rebuild, reset };
155
+ }
156
+
157
+ export type { BasemapGrid };
158
+ export { useBasemapBuilds };
@@ -0,0 +1,72 @@
1
+ import { coalesced, ignoreError, useBasemapViewer } from "./viewer.js";
2
+ import type { BasemapBuildResponse } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
3
+ import type { DetailMap } from "./detail_map.js";
4
+ import { useBasemapStore } from "@ogw_front/stores/basemap";
5
+ import { useDataStore } from "@ogw_front/stores/data";
6
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
7
+
8
+ interface DetailLayers {
9
+ syncLayers: () => Promise<void>;
10
+ replaceDetail: (response: BasemapBuildResponse, sentLayers: string) => Promise<void>;
11
+ rememberStep: (response: BasemapBuildResponse) => Promise<void>;
12
+ }
13
+
14
+ // What the viewer shows of the detail: its layers, and the detail replacing the previous one
15
+ function useDetailLayers(detail: DetailMap): DetailLayers {
16
+ const dataStore = useDataStore();
17
+ const basemapStore = useBasemapStore();
18
+ const hybridViewerStore = useHybridViewerStore();
19
+ const { discardMap } = useBasemapViewer();
20
+ const { detailId, shown, clear } = detail;
21
+
22
+ // Eye, opacity and crop reach the detail as they reach the base, one request at a time while a
23
+ // Slider is dragged. Nothing visible, or a visible map the detail was built without (missing
24
+ // From its sharp patch): the detail goes, the next one has the maps
25
+ const syncLayers = coalesced(async () => {
26
+ const id = detailId.value;
27
+ if (id === undefined) {
28
+ return;
29
+ }
30
+ const { maps } = basemapStore;
31
+ if (maps.length === 0 || maps.some((mapStyle) => !shown.maps.includes(mapStyle))) {
32
+ await clear();
33
+ return;
34
+ }
35
+ await basemapStore.applyLayers(id);
36
+ await hybridViewerStore.remoteRender();
37
+ });
38
+
39
+ async function replaceDetail(response: BasemapBuildResponse, sentLayers: string): Promise<void> {
40
+ const previous = detailId.value;
41
+ detailId.value = response.id;
42
+ shown.grid = response;
43
+ shown.maps = response.maps.map(({ map }) => map);
44
+ // Out of the viewer before the render, deleted on the back after it: shown sooner
45
+ if (previous !== undefined) {
46
+ await dataStore.deregisterObject(previous).catch(ignoreError);
47
+ }
48
+ // The states changed while the detail was built: the viewer still has the old ones
49
+ if (JSON.stringify(basemapStore.layersParams()) === sentLayers) {
50
+ await hybridViewerStore.remoteRender();
51
+ } else {
52
+ await syncLayers();
53
+ }
54
+ if (previous !== undefined) {
55
+ void discardMap(previous, false);
56
+ }
57
+ }
58
+
59
+ // No finer zoom exists here: the detail still shown goes, and this view is remembered as a step
60
+ async function rememberStep(response: BasemapBuildResponse): Promise<void> {
61
+ const clearing = clear();
62
+ // The synchronous part of clear() has run: the step is set before any newer refresh
63
+ shown.grid = response;
64
+ await clearing;
65
+ await discardMap(response.id, false);
66
+ }
67
+
68
+ return { syncLayers, replaceDetail, rememberStep };
69
+ }
70
+
71
+ export type { DetailLayers };
72
+ export { useDetailLayers };
@@ -0,0 +1,62 @@
1
+ import type { MapGrid } from "@ogw_front/utils/visible_map_area";
2
+ import type { Ref } from "vue";
3
+ import { useBasemapStore } from "@ogw_front/stores/basemap";
4
+ import { useBasemapViewer } from "./viewer.js";
5
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
6
+
7
+ interface ShownDetail {
8
+ // The grid of the detail shown: a new detail is built only when the view leaves its step
9
+ grid: MapGrid | undefined;
10
+ // The maps the detail shown was built with
11
+ maps: string[];
12
+ }
13
+
14
+ interface DetailMap {
15
+ detailId: Ref<string | undefined>;
16
+ shown: ShownDetail;
17
+ // Each refresh gets a number: a result arriving after a newer refresh is discarded
18
+ newRefresh: () => number;
19
+ isObsolete: (refreshNumber: number, basemapId: string) => boolean;
20
+ forget: () => void;
21
+ clear: () => Promise<void>;
22
+ }
23
+
24
+ // The detail shown over the basemap
25
+ function useDetailMap(): DetailMap {
26
+ const basemapStore = useBasemapStore();
27
+ const hybridViewerStore = useHybridViewerStore();
28
+ const { discardMap } = useBasemapViewer();
29
+ const detailId = ref<string | undefined>(undefined);
30
+ const shown: ShownDetail = { grid: undefined, maps: [] };
31
+ let lastRefresh = 0;
32
+
33
+ function newRefresh(): number {
34
+ lastRefresh += 1;
35
+ return lastRefresh;
36
+ }
37
+
38
+ function isObsolete(refreshNumber: number, basemapId: string): boolean {
39
+ return refreshNumber !== lastRefresh || basemapId !== basemapStore.basemapId;
40
+ }
41
+
42
+ function forget(): void {
43
+ newRefresh();
44
+ detailId.value = undefined;
45
+ shown.grid = undefined;
46
+ shown.maps = [];
47
+ }
48
+
49
+ async function clear(): Promise<void> {
50
+ const id = detailId.value;
51
+ forget();
52
+ if (id !== undefined) {
53
+ await discardMap(id, true);
54
+ await hybridViewerStore.remoteRender();
55
+ }
56
+ }
57
+
58
+ return { detailId, shown, newRefresh, isObsolete, forget, clear };
59
+ }
60
+
61
+ export type { DetailMap };
62
+ export { useDetailMap };
@@ -0,0 +1,134 @@
1
+ import { type MapBounds, covers, stillSharp } from "@ogw_front/utils/visible_map_area";
2
+ import type { BasemapBuildResponse } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
3
+ import type { BasemapGrid } from "./builds.js";
4
+ import type { DetailLayers } from "./detail_layers.js";
5
+ import type { DetailMap } from "./detail_map.js";
6
+ import { useBasemapStore } from "@ogw_front/stores/basemap";
7
+ import { useBasemapViewer } from "./viewer.js";
8
+ import { useDebounceFn } from "@vueuse/core";
9
+ import { useDetailView } from "./detail_view.js";
10
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
11
+
12
+ type BuildDetail = (grid: BasemapGrid, view: MapBounds, size: readonly number[]) => Promise<void>;
13
+
14
+ interface DetailRefresh {
15
+ // When the camera rests: a refresh waits for the last camera change
16
+ scheduleRefresh: () => void;
17
+ // A view leaving the detail would show it as a sharp patch in a blurred map: it goes at once,
18
+ // The base alone is shown until the next detail
19
+ onCameraChange: () => void;
20
+ }
21
+
22
+ const REST_DELAY_MILLISECONDS = 250;
23
+ const DETAIL_NAME = "basemap detail";
24
+
25
+ // Builds the detail of a view for the basemap shown, unless a newer refresh or base came meanwhile
26
+ function useBuildDetail(detail: DetailMap, layers: DetailLayers): BuildDetail {
27
+ const basemapStore = useBasemapStore();
28
+ const { discardMap } = useBasemapViewer();
29
+ const { detailRequest } = useDetailView();
30
+ const { newRefresh, isObsolete } = detail;
31
+
32
+ // Shown unless a newer refresh or base came while it was applied
33
+ async function show(
34
+ response: BasemapBuildResponse,
35
+ basemapId: string,
36
+ refreshNumber: number,
37
+ ): Promise<void> {
38
+ let sentLayers = "";
39
+ try {
40
+ sentLayers = await basemapStore.applyBasemap(response, DETAIL_NAME, basemapId);
41
+ } catch {
42
+ // The request feedback already shows the error: the detail must not stay registered
43
+ await discardMap(response.id, true);
44
+ return;
45
+ }
46
+ if (isObsolete(refreshNumber, basemapId)) {
47
+ await discardMap(response.id, true);
48
+ return;
49
+ }
50
+ await layers.replaceDetail(response, sentLayers);
51
+ }
52
+
53
+ return async (grid, view, size) => {
54
+ const { basemapId, maps } = basemapStore;
55
+ if (basemapId === undefined) {
56
+ return;
57
+ }
58
+ const refreshNumber = newRefresh();
59
+ const response = await detailRequest({ maps, visibleArea: view, z: grid.z }, size);
60
+ if (response === undefined) {
61
+ return;
62
+ }
63
+ if (isObsolete(refreshNumber, basemapId)) {
64
+ await discardMap(response.id, false);
65
+ } else if (response.zoom <= grid.zoom) {
66
+ await layers.rememberStep(response);
67
+ } else {
68
+ await show(response, basemapId, refreshNumber);
69
+ }
70
+ };
71
+ }
72
+
73
+ // The visible area of the basemap at the zoom of the screen, built when the camera rests
74
+ function useDetailRefresh(detail: DetailMap, layers: DetailLayers): DetailRefresh {
75
+ const basemapStore = useBasemapStore();
76
+ const hybridViewerStore = useHybridViewerStore();
77
+ const { viewportSize, currentView } = useDetailView();
78
+ const build = useBuildDetail(detail, layers);
79
+ const { shown, clear } = detail;
80
+
81
+ async function refresh(): Promise<void> {
82
+ const { grid, basemapId } = basemapStore;
83
+ const size = viewportSize();
84
+ const resting = !hybridViewerStore.is_moving && basemapStore.maps.length > 0;
85
+ if (!resting || grid === undefined || basemapId === undefined || size === undefined) {
86
+ return;
87
+ }
88
+ const { visibleArea, wanted, sharperNeeded } = currentView(grid, size);
89
+ if (visibleArea === undefined || !sharperNeeded) {
90
+ await clear();
91
+ return;
92
+ }
93
+ // Steps: the map shown is still right for this view, nothing to rebuild
94
+ if (shown.grid !== undefined && stillSharp(shown.grid, visibleArea, wanted)) {
95
+ return;
96
+ }
97
+ await build(grid, visibleArea, size);
98
+ }
99
+
100
+ async function refreshQuietly(): Promise<void> {
101
+ try {
102
+ await refresh();
103
+ } catch (error) {
104
+ // Request failures are shown by the request feedback; logged too, so a programming error
105
+ // Is never hidden
106
+ // oxlint-disable-next-line no-console -- no other channel for an error nobody awaits
107
+ console.error("Basemap detail refresh failed", error);
108
+ }
109
+ }
110
+
111
+ const debouncedRefresh = useDebounceFn(() => {
112
+ void refreshQuietly();
113
+ }, REST_DELAY_MILLISECONDS);
114
+
115
+ function scheduleRefresh(): void {
116
+ void debouncedRefresh();
117
+ }
118
+
119
+ function onCameraChange(): void {
120
+ const { grid } = basemapStore;
121
+ const size = viewportSize();
122
+ if (shown.grid !== undefined && grid !== undefined && size !== undefined) {
123
+ const { visibleArea } = currentView(grid, size);
124
+ if (visibleArea === undefined || !covers(shown.grid.bounds, visibleArea)) {
125
+ void clear();
126
+ }
127
+ }
128
+ scheduleRefresh();
129
+ }
130
+
131
+ return { scheduleRefresh, onCameraChange };
132
+ }
133
+
134
+ export { useDetailRefresh };
@@ -0,0 +1,94 @@
1
+ import {
2
+ type MapBounds,
3
+ type ViewCamera,
4
+ mapResolution,
5
+ needsSharperMap,
6
+ screenPixelGroundSize,
7
+ visibleMapArea,
8
+ } from "@ogw_front/utils/visible_map_area";
9
+ import back_schemas, {
10
+ type BasemapBuildResponse,
11
+ } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
12
+ import type { BasemapGrid } from "./builds.js";
13
+ import type { MapStyle } from "@ogw_front/utils/basemap_tree";
14
+ import { useBackStore } from "@ogw_front/stores/back";
15
+ import { useCrsStore } from "@ogw_front/stores/crs";
16
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
17
+
18
+ interface RenderWindowLike {
19
+ getApiSpecificRenderWindow: () => { getSize: () => [number, number] };
20
+ }
21
+ interface CurrentView {
22
+ visibleArea: MapBounds | undefined;
23
+ wanted: number;
24
+ sharperNeeded: boolean;
25
+ }
26
+
27
+ const MAX_DETAIL_PIXELS = 4096;
28
+
29
+ interface DetailView {
30
+ viewportSize: () => [number, number] | undefined;
31
+ currentView: (grid: BasemapGrid, size: readonly number[]) => CurrentView;
32
+ detailRequest: (
33
+ area: Readonly<{ maps: MapStyle[]; visibleArea: MapBounds; z: number }>,
34
+ size: readonly number[],
35
+ ) => Promise<BasemapBuildResponse | undefined>;
36
+ }
37
+
38
+ // The stores are taken once: a call still running after a project reset reaches its own stores
39
+ function useDetailView(): DetailView {
40
+ const backStore = useBackStore();
41
+ const crsStore = useCrsStore();
42
+ const hybridViewerStore = useHybridViewerStore();
43
+
44
+ function viewportSize(): [number, number] | undefined {
45
+ // The store holds the render window in a holder: the vtk.js typing of its API is partial
46
+ // oxlint-disable-next-line no-unsafe-type-assertion -- vtk.js render window API boundary
47
+ const renderWindow = hybridViewerStore.genericRenderWindow.value as unknown as
48
+ | RenderWindowLike
49
+ | undefined;
50
+ const size = renderWindow?.getApiSpecificRenderWindow().getSize();
51
+ if (size === undefined || size[0] === 0 || size[1] === 0) {
52
+ return undefined;
53
+ }
54
+ return size;
55
+ }
56
+
57
+ // What the screen shows of the base, and the ground size of one of its pixels
58
+ function currentView(grid: BasemapGrid, size: readonly number[]): CurrentView {
59
+ // oxlint-disable-next-line no-unsafe-type-assertion -- camera_options carries the vtk.js camera fields
60
+ const camera = hybridViewerStore.camera_options as unknown as ViewCamera;
61
+ const planeZ = grid.z * hybridViewerStore.zScale;
62
+ const aspect = (size[0] ?? 1) / (size[1] ?? 1);
63
+ const visibleArea = visibleMapArea(camera, aspect, planeZ, grid.bounds);
64
+ const wanted = screenPixelGroundSize(camera, size[1] ?? 1);
65
+ return { visibleArea, wanted, sharperNeeded: needsSharperMap(mapResolution(grid), wanted) };
66
+ }
67
+
68
+ // The visible area at about one map pixel per screen pixel, without margin
69
+ async function detailRequest(
70
+ { maps, visibleArea, z }: Readonly<{ maps: MapStyle[]; visibleArea: MapBounds; z: number }>,
71
+ size: readonly number[],
72
+ ): Promise<BasemapBuildResponse | undefined> {
73
+ const crs = crsStore.projectCrs;
74
+ if (crs === undefined) {
75
+ return undefined;
76
+ }
77
+ const response = await backStore.request({
78
+ schema: back_schemas.opengeodeweb_back.basemap.build,
79
+ params: {
80
+ maps: [...maps],
81
+ crs,
82
+ bounds: visibleArea,
83
+ z,
84
+ margin: false,
85
+ max_pixels: Math.min(MAX_DETAIL_PIXELS, Math.max(...size)),
86
+ },
87
+ });
88
+ return response;
89
+ }
90
+
91
+ return { viewportSize, currentView, detailRequest };
92
+ }
93
+
94
+ export { useDetailView };
@@ -0,0 +1,40 @@
1
+ import type { BasemapBuildResponse } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
2
+ import type { MapStyle } from "@ogw_front/utils/basemap_tree";
3
+
4
+ interface Extent {
5
+ bounds: BasemapBuildResponse["bounds"];
6
+ z: number;
7
+ }
8
+
9
+ const X_MIN = 0;
10
+ const X_MAX = 1;
11
+ const Y_MIN = 2;
12
+ const Y_MAX = 3;
13
+ const Z_MAX = 5;
14
+
15
+ function everyMap<Value>(value: Value): Record<MapStyle, Value> {
16
+ return { satellite: value, plan: value, routes: value };
17
+ }
18
+
19
+ // Unscaled polydata bounds: the actor bounds would include the z scale
20
+ function boxesExtent(boxes: readonly (readonly number[])[]): Extent | undefined {
21
+ if (boxes.length === 0) {
22
+ return undefined;
23
+ }
24
+ function side(index: number): number[] {
25
+ return boxes.map((box) => box[index] ?? 0);
26
+ }
27
+ return {
28
+ bounds: {
29
+ x_min: Math.min(...side(X_MIN)),
30
+ y_min: Math.min(...side(Y_MIN)),
31
+ x_max: Math.max(...side(X_MAX)),
32
+ y_max: Math.max(...side(Y_MAX)),
33
+ },
34
+ // At the top of the data, like the ground above subsurface data, ready to drape surfaces
35
+ z: Math.max(...side(Z_MAX)),
36
+ };
37
+ }
38
+
39
+ export type { Extent };
40
+ export { boxesExtent, everyMap };