@geode/opengeodeweb-front 10.44.0-rc.6 → 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 (30) hide show
  1. package/app/components/BasemapAttribution.vue +28 -0
  2. package/app/components/Viewer/Basemap/CropOptions.vue +50 -0
  3. package/app/components/Viewer/Basemap/OpacityOptions.vue +52 -0
  4. package/app/components/Viewer/ContextMenu/ContextMenu.vue +5 -1
  5. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +6 -2
  6. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +49 -10
  7. package/app/components/Viewer/Ui.vue +6 -0
  8. package/app/composables/project_manager_helpers/reset.ts +3 -0
  9. package/app/composables/project_manager_helpers/restore.ts +3 -0
  10. package/app/composables/project_manager_helpers/types.ts +2 -0
  11. package/app/composables/viewer_context_menu.ts +10 -0
  12. package/app/stores/basemap.ts +52 -0
  13. package/app/stores/basemap_detail.ts +51 -0
  14. package/app/stores/basemap_helpers/builds.ts +158 -0
  15. package/app/stores/basemap_helpers/detail_layers.ts +72 -0
  16. package/app/stores/basemap_helpers/detail_map.ts +62 -0
  17. package/app/stores/basemap_helpers/detail_refresh.ts +134 -0
  18. package/app/stores/basemap_helpers/detail_view.ts +94 -0
  19. package/app/stores/basemap_helpers/extent.ts +40 -0
  20. package/app/stores/basemap_helpers/georeferenced.ts +50 -0
  21. package/app/stores/basemap_helpers/layers.ts +66 -0
  22. package/app/stores/basemap_helpers/settings.ts +87 -0
  23. package/app/stores/basemap_helpers/viewer.ts +114 -0
  24. package/app/stores/menu_helpers/basemap.ts +10 -0
  25. package/app/stores/menu_helpers/menus_data.ts +2 -0
  26. package/app/utils/basemap_tree.ts +76 -0
  27. package/app/utils/treeview.ts +12 -1
  28. package/app/utils/visible_map_area.ts +129 -0
  29. package/internal/stores/hybrid_viewer/vtk_types.ts +2 -1
  30. package/package.json +1 -1
@@ -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 };
@@ -0,0 +1,87 @@
1
+ import { type MapStyle, sortedMaps } from "@ogw_front/utils/basemap_tree";
2
+ import type { BasemapLayers } from "./layers.js";
3
+ import type { Ref } from "vue";
4
+ import { coalesced } from "./viewer.js";
5
+ import { everyMap } from "./extent.js";
6
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
7
+
8
+ interface BasemapSnapshot {
9
+ maps?: MapStyle[];
10
+ opacities?: Partial<Record<MapStyle, number>>;
11
+ crop?: Partial<Record<MapStyle, boolean>>;
12
+ }
13
+
14
+ interface BasemapSettings {
15
+ setMaps: (newMaps: readonly MapStyle[]) => Promise<void>;
16
+ setOpacity: (mapStyle: MapStyle, value: number) => Promise<void>;
17
+ setCrop: (value: boolean, mapStyles: readonly MapStyle[]) => Promise<void>;
18
+ exportStores: () => Required<BasemapSnapshot>;
19
+ importStores: (snapshot: BasemapSnapshot | undefined) => Promise<void>;
20
+ }
21
+
22
+ // The choices of the user: a change already built only recomposes, the others rebuild
23
+ function useBasemapSettings(
24
+ layers: BasemapLayers,
25
+ basemapId: Ref<string | undefined>,
26
+ rebuild: () => Promise<void>,
27
+ ): BasemapSettings {
28
+ const hybridViewerStore = useHybridViewerStore();
29
+ const { shown, hidden, maps, opacities, crop, built, applyLayers } = layers;
30
+
31
+ const recompose = coalesced(async () => {
32
+ const id = basemapId.value;
33
+ if (id !== undefined) {
34
+ await applyLayers(id);
35
+ await hybridViewerStore.remoteRender();
36
+ }
37
+ });
38
+
39
+ // No map hides the basemap and keeps the last maps, to show them again. Hidden, the built
40
+ // Basemap stays with every layer invisible: shown again, it only recomposes
41
+ async function setMaps(newMaps: readonly MapStyle[]): Promise<void> {
42
+ if (newMaps.length === 0) {
43
+ hidden.value = true;
44
+ } else {
45
+ shown.value = sortedMaps(newMaps);
46
+ hidden.value = false;
47
+ }
48
+ const allBuilt = maps.value.every((mapStyle) => built.value.includes(mapStyle));
49
+ if (basemapId.value !== undefined && allBuilt) {
50
+ await recompose();
51
+ return;
52
+ }
53
+ await rebuild();
54
+ }
55
+
56
+ // No rebuild: each map keeps its opacity
57
+ async function setOpacity(mapStyle: MapStyle, value: number): Promise<void> {
58
+ opacities.value = { ...opacities.value, [mapStyle]: value };
59
+ await recompose();
60
+ }
61
+
62
+ // No rebuild
63
+ async function setCrop(value: boolean, mapStyles: readonly MapStyle[]): Promise<void> {
64
+ crop.value = {
65
+ ...crop.value,
66
+ ...Object.fromEntries(mapStyles.map((mapStyle) => [mapStyle, value])),
67
+ };
68
+ await recompose();
69
+ }
70
+
71
+ function exportStores(): Required<BasemapSnapshot> {
72
+ return { maps: maps.value, opacities: opacities.value, crop: crop.value };
73
+ }
74
+
75
+ // Called once the project data is imported. When the data is not displayed yet,
76
+ // The rebuild finds no bounds and the store rebuilds once it is displayed.
77
+ async function importStores(snapshot: BasemapSnapshot | undefined): Promise<void> {
78
+ opacities.value = { ...everyMap(1), ...snapshot?.opacities };
79
+ crop.value = { ...everyMap(false), ...snapshot?.crop };
80
+ await setMaps(sortedMaps(snapshot?.maps ?? ["satellite"]));
81
+ }
82
+
83
+ return { setMaps, setOpacity, setCrop, exportStores, importStores };
84
+ }
85
+
86
+ export type { BasemapSnapshot };
87
+ export { useBasemapSettings };