@geode/opengeodeweb-front 10.44.0-rc.6 → 10.44.0-rc.8

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 (59) hide show
  1. package/.build/server/utils/scripts.js +34 -23
  2. package/app/components/BasemapAttribution.vue +28 -0
  3. package/app/components/MissingFilesSelector.vue +30 -17
  4. package/app/components/ObjectSelector.vue +34 -23
  5. package/app/components/Viewer/Basemap/CropOptions.vue +50 -0
  6. package/app/components/Viewer/Basemap/OpacityOptions.vue +52 -0
  7. package/app/components/Viewer/ContextMenu/ContextMenu.vue +5 -1
  8. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +6 -2
  9. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +49 -10
  10. package/app/components/Viewer/Ui.vue +6 -0
  11. package/app/composables/overlapping_picker_menu.ts +43 -0
  12. package/app/composables/project_manager_helpers/reset.ts +3 -0
  13. package/app/composables/project_manager_helpers/restore.ts +22 -10
  14. package/app/composables/project_manager_helpers/types.ts +2 -0
  15. package/app/composables/use_overlapping_picker.ts +23 -37
  16. package/app/composables/viewer_context_menu.ts +10 -0
  17. package/app/composables/virtual_tree_flatten.ts +66 -43
  18. package/app/stores/app_helpers/extension.ts +90 -51
  19. package/app/stores/basemap.ts +52 -0
  20. package/app/stores/basemap_detail.ts +51 -0
  21. package/app/stores/basemap_helpers/builds.ts +158 -0
  22. package/app/stores/basemap_helpers/detail_layers.ts +72 -0
  23. package/app/stores/basemap_helpers/detail_map.ts +62 -0
  24. package/app/stores/basemap_helpers/detail_refresh.ts +134 -0
  25. package/app/stores/basemap_helpers/detail_view.ts +94 -0
  26. package/app/stores/basemap_helpers/extent.ts +40 -0
  27. package/app/stores/basemap_helpers/georeferenced.ts +50 -0
  28. package/app/stores/basemap_helpers/layers.ts +66 -0
  29. package/app/stores/basemap_helpers/settings.ts +87 -0
  30. package/app/stores/basemap_helpers/viewer.ts +114 -0
  31. package/app/stores/infra.ts +26 -21
  32. package/app/stores/menu_helpers/basemap.ts +10 -0
  33. package/app/stores/menu_helpers/menus_data.ts +2 -0
  34. package/app/utils/basemap_tree.ts +76 -0
  35. package/app/utils/color_picker.ts +18 -15
  36. package/app/utils/treeview.ts +12 -1
  37. package/app/utils/visible_map_area.ts +129 -0
  38. package/internal/database/database.ts +47 -32
  39. package/internal/stores/data_style/mesh/base_style.ts +74 -0
  40. package/internal/stores/data_style/mesh/index.ts +2 -57
  41. package/internal/stores/data_style/model/blocks/color.ts +58 -57
  42. package/internal/stores/data_style/model/blocks/polyhedron.ts +88 -44
  43. package/internal/stores/data_style/model/blocks/vertex.ts +88 -44
  44. package/internal/stores/data_style/model/color.ts +25 -26
  45. package/internal/stores/data_style/model/corners/index.ts +85 -78
  46. package/internal/stores/data_style/model/corners/vertex.ts +83 -39
  47. package/internal/stores/data_style/model/lines/color.ts +53 -40
  48. package/internal/stores/data_style/model/lines/edge.ts +88 -44
  49. package/internal/stores/data_style/model/lines/vertex.ts +88 -44
  50. package/internal/stores/data_style/model/surfaces/color.ts +68 -56
  51. package/internal/stores/data_style/model/surfaces/polygon.ts +80 -36
  52. package/internal/stores/data_style/model/surfaces/vertex.ts +80 -36
  53. package/internal/stores/data_style/model/visibility_dispatch.ts +49 -99
  54. package/internal/stores/hybrid_viewer/highlight.ts +70 -54
  55. package/internal/stores/hybrid_viewer/scene.ts +31 -25
  56. package/internal/stores/hybrid_viewer/vtk_types.ts +2 -1
  57. package/package.json +1 -1
  58. package/server/api/local/extensions/upload.put.ts +47 -20
  59. package/server/utils/scripts.ts +35 -30
@@ -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 };
@@ -0,0 +1,50 @@
1
+ import { type Extent, boxesExtent } from "./extent.js";
2
+ import type { ComputedRef } from "vue";
3
+ import { sameCrs } from "@ogw_front/utils/crs";
4
+ import { useCrsStore } from "@ogw_front/stores/crs";
5
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
6
+
7
+ interface Georeferenced {
8
+ // A map needs at least one data in the project CRS to lie under
9
+ available: ComputedRef<boolean>;
10
+ georeferencedIds: () => string[];
11
+ dataBounds: () => Extent | undefined;
12
+ // Changes with the project CRS, the georeferenced data or their extent
13
+ dataKey: () => string;
14
+ }
15
+
16
+ // Data without a CRS is still in local coordinates, and data in another CRS than the
17
+ // Project would be misplaced: only the data in the project CRS are under the basemap
18
+ function useGeoreferenced(): Georeferenced {
19
+ const crsStore = useCrsStore();
20
+ const hybridViewerStore = useHybridViewerStore();
21
+
22
+ function georeferencedIds(): string[] {
23
+ return crsStore.crsItems
24
+ .filter((item) => sameCrs(item.crs, crsStore.projectCrs))
25
+ .map((item) => item.id);
26
+ }
27
+
28
+ const available = computed(
29
+ () => crsStore.projectCrs !== undefined && georeferencedIds().length > 0,
30
+ );
31
+
32
+ function dataBounds(): Extent | undefined {
33
+ const georeferenced = new Set(georeferencedIds());
34
+ return boxesExtent(
35
+ Object.entries(hybridViewerStore.hybridDb)
36
+ .filter(([id]) => georeferenced.has(id))
37
+ .map(([, entry]) => entry.polydata.getBounds()),
38
+ );
39
+ }
40
+
41
+ function dataKey(): string {
42
+ const crs = crsStore.projectCrs;
43
+ const extentKey = JSON.stringify(dataBounds() ?? "none");
44
+ return `${crs?.authority}:${crs?.code}|${georeferencedIds().join(",")}|${extentKey}`;
45
+ }
46
+
47
+ return { available, georeferencedIds, dataBounds, dataKey };
48
+ }
49
+
50
+ export { useGeoreferenced };
@@ -0,0 +1,66 @@
1
+ import type { ComputedRef, Ref } from "vue";
2
+ import { type Layer, useBasemapViewer } from "./viewer.js";
3
+ import type { BasemapBuildResponse } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
4
+ import type { MapStyle } from "@ogw_front/utils/basemap_tree";
5
+ import { everyMap } from "./extent.js";
6
+
7
+ interface BasemapLayers {
8
+ // The last chosen maps: shown again when the basemap is shown again
9
+ shown: Ref<MapStyle[]>;
10
+ // Shown as soon as the project has a CRS, until the user hides it
11
+ hidden: Ref<boolean>;
12
+ // The visible maps, from the bottom one to the top one
13
+ maps: ComputedRef<MapStyle[]>;
14
+ opacities: Ref<Record<MapStyle, number>>;
15
+ // Cropped: only draped on the top surfaces, out of the flat map around
16
+ crop: Ref<Record<MapStyle, boolean>>;
17
+ // The maps downloaded in the current basemap: the others need a build
18
+ built: Ref<MapStyle[]>;
19
+ layersParams: () => Layer[];
20
+ applyLayers: (id: string) => Promise<void>;
21
+ // Returns the layers sent: the states changed meanwhile are sent again
22
+ applyBasemap: (
23
+ response: BasemapBuildResponse,
24
+ name: string,
25
+ detailOf?: string,
26
+ ) => Promise<string>;
27
+ }
28
+
29
+ // The state of each map, and how it reaches the viewer
30
+ function useBasemapLayers(georeferencedIds: () => string[]): BasemapLayers {
31
+ const { sendLayers, showMap } = useBasemapViewer();
32
+ const shown = ref<MapStyle[]>(["satellite"]);
33
+ const hidden = ref(false);
34
+ const maps = computed<MapStyle[]>(() => (hidden.value ? [] : shown.value));
35
+ const opacities = ref<Record<MapStyle, number>>(everyMap(1));
36
+ const crop = ref<Record<MapStyle, boolean>>(everyMap(false));
37
+ const built = ref<MapStyle[]>([]);
38
+
39
+ function layersParams(): Layer[] {
40
+ return built.value.map((map) => ({
41
+ map,
42
+ visible: maps.value.includes(map),
43
+ opacity: opacities.value[map],
44
+ crop: crop.value[map],
45
+ }));
46
+ }
47
+
48
+ async function applyLayers(id: string): Promise<void> {
49
+ await sendLayers(id, layersParams());
50
+ }
51
+
52
+ async function applyBasemap(
53
+ response: BasemapBuildResponse,
54
+ name: string,
55
+ detailOf?: string,
56
+ ): Promise<string> {
57
+ const layers = layersParams();
58
+ await showMap({ response, name, layers, dataIds: georeferencedIds() }, detailOf);
59
+ return JSON.stringify(layers);
60
+ }
61
+
62
+ return { shown, hidden, maps, opacities, crop, built, layersParams, applyLayers, applyBasemap };
63
+ }
64
+
65
+ export type { BasemapLayers };
66
+ export { useBasemapLayers };