@geode/opengeodeweb-front 12.2.0-rc.1 → 12.2.0-rc.2
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/.build/server/utils/microservices_process.js +1 -1
- package/.build/tests/browser/helpers/crs.js +136 -0
- package/.build/tests/browser/helpers/crs_flows.js +60 -0
- package/.build/tests/browser/helpers/crs_shortlist.js +13 -0
- package/.build/tests/browser/helpers/crs_test_data.js +40 -0
- package/.build/tests/browser/suites/crs.js +142 -0
- package/.build/tests/browser/suites/crs_harmonize.js +63 -0
- package/.build/tests/browser/suites/crs_shortlist.js +31 -0
- package/.build/tests/browser/suites/index.js +6 -0
- package/app/app.config.ts +4 -0
- package/app/components/CrsAlign.vue +207 -0
- package/app/components/CrsDialog.vue +400 -0
- package/app/components/CrsDialogHost.vue +66 -0
- package/app/components/CrsSelector.vue +100 -3
- package/app/components/PickButton.vue +43 -0
- package/app/components/ProjectCrsDialog.vue +109 -0
- package/app/components/ToolPanel.vue +5 -2
- package/app/components/Viewer/CrsOverlays.vue +29 -0
- package/app/components/Viewer/Ui.vue +3 -2
- package/app/composables/crs.ts +197 -0
- package/app/composables/crs_align.ts +206 -0
- package/app/composables/crs_assign.ts +102 -0
- package/app/composables/crs_link.ts +22 -0
- package/app/composables/crs_shortlist.ts +63 -0
- package/app/composables/project_crs.ts +197 -0
- package/app/composables/user_setting.ts +140 -0
- package/app/stores/basemap.ts +19 -2
- package/app/stores/crs.ts +11 -106
- package/app/stores/crs_helpers/geographic_list.ts +44 -0
- package/app/stores/crs_helpers/project_crs.ts +60 -0
- package/app/stores/crs_helpers/requests.ts +60 -0
- package/app/utils/crs.ts +17 -1
- package/app/utils/import_item.ts +87 -0
- package/app/utils/import_workflow.ts +36 -94
- package/app/utils/reload_object.ts +26 -0
- package/package.json +1 -1
- package/server/utils/microservices_process.ts +4 -1
- package/tests/browser/data/test_lambert93_no_crs.og_pts3d +0 -0
- package/tests/browser/data/test_utm31n.og_pts3d +0 -0
- package/tests/browser/helpers/crs.ts +250 -0
- package/tests/browser/helpers/crs_flows.ts +115 -0
- package/tests/browser/helpers/crs_shortlist.ts +27 -0
- package/tests/browser/helpers/crs_test_data.ts +34 -0
- package/tests/browser/suites/crs.ts +228 -0
- package/tests/browser/suites/crs_harmonize.ts +96 -0
- package/tests/browser/suites/crs_shortlist.ts +37 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { Ref, ShallowRef } from "vue";
|
|
2
|
+
import { useLocalStorage } from "@vueuse/core";
|
|
3
|
+
import type { z } from "zod";
|
|
4
|
+
|
|
5
|
+
interface DesktopSettingsAPI {
|
|
6
|
+
app_settings: unknown;
|
|
7
|
+
app_settings_write: (settings: Record<string, unknown>) => Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// A setting of the user (theme, favorite CRS...), declared once next to the feature that uses it.
|
|
11
|
+
// Its value is replaced, never changed in place: `favorites.value = [...favorites.value, entry]`
|
|
12
|
+
interface UserSettingDefinition<Value> {
|
|
13
|
+
// Its key in the desktop settings.json
|
|
14
|
+
key: string;
|
|
15
|
+
// Checks the stored value on read, strictly: an invalid one gives the fallback. A setting whose type
|
|
16
|
+
// Changes takes a new key: the old value is left as is, never converted
|
|
17
|
+
schema: z.ZodType<Value>;
|
|
18
|
+
// A JSON value: copied for each use, compared when the setting is declared again
|
|
19
|
+
fallback: Value;
|
|
20
|
+
// Its key in the browser local storage
|
|
21
|
+
browserKey: string;
|
|
22
|
+
// The value shared by every caller on the desktop, with the settings API it is saved through
|
|
23
|
+
desktop?: { api: DesktopSettingsAPI; setting: ShallowRef<Value> };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The browser key and fallback of each declared setting, as JSON
|
|
27
|
+
const declared = new Map<string, string>();
|
|
28
|
+
|
|
29
|
+
// Declares a setting, at module level. Declaring it again the same way (hot reload, tests) is fine;
|
|
30
|
+
// Declaring it differently is an error: two features would overwrite each other's value.
|
|
31
|
+
function defineUserSetting<Value>(options: {
|
|
32
|
+
key: string;
|
|
33
|
+
schema: z.ZodType<Value>;
|
|
34
|
+
fallback: Value;
|
|
35
|
+
browserKey?: string;
|
|
36
|
+
}): UserSettingDefinition<Value> {
|
|
37
|
+
const definition: UserSettingDefinition<Value> = {
|
|
38
|
+
...options,
|
|
39
|
+
browserKey: options.browserKey ?? `ogw-${options.key}`,
|
|
40
|
+
};
|
|
41
|
+
const signature = JSON.stringify([definition.browserKey, definition.fallback]);
|
|
42
|
+
const existing = declared.get(definition.key);
|
|
43
|
+
if (existing !== undefined && existing !== signature) {
|
|
44
|
+
throw new Error(`User setting "${definition.key}" is already defined differently`);
|
|
45
|
+
}
|
|
46
|
+
declared.set(definition.key, signature);
|
|
47
|
+
return definition;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function hasDesktopSettingsAPI(
|
|
51
|
+
value: typeof globalThis,
|
|
52
|
+
): value is typeof globalThis & { electronAPI: DesktopSettingsAPI } {
|
|
53
|
+
return (
|
|
54
|
+
"electronAPI" in value &&
|
|
55
|
+
typeof value.electronAPI === "object" &&
|
|
56
|
+
value.electronAPI !== null &&
|
|
57
|
+
"app_settings" in value.electronAPI &&
|
|
58
|
+
"app_settings_write" in value.electronAPI
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The stored value when the setting's schema accepts it, a copy of the fallback otherwise
|
|
63
|
+
function validated<Value>(definition: UserSettingDefinition<Value>, value: unknown): Value {
|
|
64
|
+
const result = definition.schema.safeParse(value);
|
|
65
|
+
if (result.success) {
|
|
66
|
+
return result.data;
|
|
67
|
+
}
|
|
68
|
+
return structuredClone(definition.fallback);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Every value is stored as JSON. A value that is not JSON is a string stored raw by a previous version
|
|
72
|
+
// (the Vease color theme was stored as `dark`)
|
|
73
|
+
function parseStored(raw: string): unknown {
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(raw);
|
|
76
|
+
} catch {
|
|
77
|
+
return raw;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function browserSetting<Value>(definition: UserSettingDefinition<Value>): Ref<Value> {
|
|
82
|
+
return useLocalStorage<Value>(definition.browserKey, structuredClone(definition.fallback), {
|
|
83
|
+
shallow: true,
|
|
84
|
+
serializer: {
|
|
85
|
+
read: (raw: string): Value => validated(definition, parseStored(raw)),
|
|
86
|
+
write: (value: Value): string => JSON.stringify(value),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// A copy without Vue proxies: toRaw only unwraps the outer one, not the elements a filter or a spread returns
|
|
92
|
+
function toPlain(value: unknown): unknown {
|
|
93
|
+
const raw: unknown = toRaw(value);
|
|
94
|
+
if (Array.isArray(raw)) {
|
|
95
|
+
return raw.map((item: unknown) => toPlain(item));
|
|
96
|
+
}
|
|
97
|
+
if (typeof raw === "object" && raw !== null) {
|
|
98
|
+
return Object.fromEntries(
|
|
99
|
+
Object.entries(raw).map(([entryKey, entryValue]) => [entryKey, toPlain(entryValue)]),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return raw;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function desktopSetting<Value>(
|
|
106
|
+
api: DesktopSettingsAPI,
|
|
107
|
+
definition: UserSettingDefinition<Value>,
|
|
108
|
+
): Ref<Value> {
|
|
109
|
+
if (definition.desktop?.api === api) {
|
|
110
|
+
return definition.desktop.setting;
|
|
111
|
+
}
|
|
112
|
+
let saved: unknown = undefined;
|
|
113
|
+
if (typeof api.app_settings === "object" && api.app_settings !== null) {
|
|
114
|
+
saved = Reflect.get(api.app_settings, definition.key);
|
|
115
|
+
}
|
|
116
|
+
const setting = shallowRef(validated(definition, saved));
|
|
117
|
+
// Detached: the first caller's unmount must not stop the saving
|
|
118
|
+
effectScope(true).run(() => {
|
|
119
|
+
watch(setting, (value) => {
|
|
120
|
+
// Electron cannot send the Vue proxies a new value may hold, at any depth
|
|
121
|
+
void api.app_settings_write({ [definition.key]: toPlain(value) });
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
definition.desktop = { api, setting };
|
|
125
|
+
return setting;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// The value of a setting, shared by every caller. The desktop app clears its browser storage on every launch:
|
|
129
|
+
// There the settings live in its settings.json, read before the page renders and written on every change.
|
|
130
|
+
// The browser keeps them in its local storage.
|
|
131
|
+
function useUserSetting<Value>(definition: UserSettingDefinition<Value>): Ref<Value> {
|
|
132
|
+
const globalScope = globalThis;
|
|
133
|
+
if (!hasDesktopSettingsAPI(globalScope)) {
|
|
134
|
+
return browserSetting(definition);
|
|
135
|
+
}
|
|
136
|
+
return desktopSetting(globalScope.electronAPI, definition);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type { UserSettingDefinition };
|
|
140
|
+
export { defineUserSetting, useUserSetting };
|
package/app/stores/basemap.ts
CHANGED
|
@@ -6,11 +6,28 @@ import { useGeoreferenced } from "./basemap_helpers/georeferenced.js";
|
|
|
6
6
|
|
|
7
7
|
const REBUILD_DELAY_MILLISECONDS = 500;
|
|
8
8
|
|
|
9
|
+
// Apps opt in with `ogwFront.basemap` in their app.config.ts: without it, no map is built or offered
|
|
10
|
+
function readBasemapOption(appConfig: ReturnType<typeof useAppConfig>): boolean {
|
|
11
|
+
// The resolved type holds the layer's literal default (false): widen it to the config input type
|
|
12
|
+
const ogwFront: { basemap?: boolean } | undefined = appConfig.ogwFront;
|
|
13
|
+
return ogwFront?.basemap === true;
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
export const useBasemapStore = defineStore("basemap", () => {
|
|
10
|
-
const
|
|
17
|
+
const appConfig = useAppConfig();
|
|
18
|
+
const enabled = computed(() => readBasemapOption(appConfig));
|
|
19
|
+
const georeferenced = useGeoreferenced();
|
|
20
|
+
const { georeferencedIds, dataBounds, dataKey } = georeferenced;
|
|
21
|
+
const available = computed(() => enabled.value && georeferenced.available.value);
|
|
11
22
|
const layers = useBasemapLayers(georeferencedIds);
|
|
12
23
|
const { shown, maps, opacities, crop, layersParams, applyLayers, applyBasemap } = layers;
|
|
13
|
-
const
|
|
24
|
+
const builds = useBasemapBuilds(layers, dataBounds);
|
|
25
|
+
const { basemapId, grid, attribution, reset } = builds;
|
|
26
|
+
async function rebuild(): Promise<void> {
|
|
27
|
+
if (enabled.value) {
|
|
28
|
+
await builds.rebuild();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
14
31
|
const settings = useBasemapSettings(layers, basemapId, rebuild);
|
|
15
32
|
const { setMaps, setOpacity, setCrop, exportStores, importStores } = settings;
|
|
16
33
|
|
package/app/stores/crs.ts
CHANGED
|
@@ -1,110 +1,22 @@
|
|
|
1
|
-
import { oldestCrs, sameCrs } from "@ogw_front/utils/crs";
|
|
2
1
|
import type { CRS } from "@geode/opengeodeweb-back/schema_types";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
|
|
6
|
-
import { useBackStore } from "@ogw_front/stores/back";
|
|
2
|
+
import { oldestCrs } from "@ogw_front/utils/crs";
|
|
3
|
+
import { useCrsRequests } from "./crs_helpers/requests.js";
|
|
7
4
|
import { useDataStore } from "@ogw_front/stores/data";
|
|
5
|
+
import { useGeographicList } from "./crs_helpers/geographic_list.js";
|
|
6
|
+
import { useProjectCrsState } from "./crs_helpers/project_crs.js";
|
|
8
7
|
|
|
9
8
|
// Session cache of the available CRS, the project CRS, and the channel the shared components use to ask the host app for a CRS edit
|
|
10
|
-
// oxlint-disable-next-line max-lines-per-function, max-statements
|
|
11
9
|
export const useCrsStore = defineStore("crs", () => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const dataStore = useDataStore();
|
|
18
|
-
const crsItems = dataStore.refCrsItems();
|
|
19
|
-
const projectCrs = ref<CRS | undefined>(undefined);
|
|
20
|
-
const projectCrsEditRequest = ref(false);
|
|
21
|
-
|
|
22
|
-
// The project follows its data: once every georeferenced data is in one CRS, it is the project
|
|
23
|
-
// CRS. Data already mixed before any project CRS: the oldest one is the reference
|
|
24
|
-
watch(
|
|
25
|
-
() => {
|
|
26
|
-
const georeferenced = crsItems.value.filter((item) => item.crs !== undefined);
|
|
27
|
-
const [first] = georeferenced;
|
|
28
|
-
if (first === undefined) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
if (georeferenced.every((item) => sameCrs(item.crs, first.crs))) {
|
|
32
|
-
return first.crs;
|
|
33
|
-
}
|
|
34
|
-
return projectCrs.value ?? oldestCrs(georeferenced);
|
|
35
|
-
},
|
|
36
|
-
(reference) => {
|
|
37
|
-
if (reference !== undefined && !sameCrs(reference, projectCrs.value)) {
|
|
38
|
-
projectCrs.value = reference;
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
{ immediate: true },
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Data without CRS are listed too (value undefined): they could not follow the project
|
|
45
|
-
const mismatchedCrs = computed(() => {
|
|
46
|
-
const project = projectCrs.value;
|
|
47
|
-
const mismatched = new Map<string, CRS | undefined>();
|
|
48
|
-
for (const item of crsItems.value) {
|
|
49
|
-
if (project !== undefined && !sameCrs(item.crs, project)) {
|
|
50
|
-
mismatched.set(item.data_id, item.crs);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return mismatched;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
async function fetchGeographicList(geodeObjectType: GeodeObjectType): Promise<CRS[]> {
|
|
57
|
-
try {
|
|
58
|
-
const response = await backStore.request({
|
|
59
|
-
schema: back_schemas.opengeodeweb_back.crs.geographic_list,
|
|
60
|
-
params: { geode_object_type: geodeObjectType },
|
|
61
|
-
});
|
|
62
|
-
if (response?.crs_list !== undefined) {
|
|
63
|
-
return response.crs_list;
|
|
64
|
-
}
|
|
65
|
-
} catch {
|
|
66
|
-
// The back store already reports the error to the user
|
|
67
|
-
}
|
|
68
|
-
// A failed request is not cached: the next call retries
|
|
69
|
-
geographicListPromise = undefined;
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function geographicList(geodeObjectType: GeodeObjectType): Promise<CRS[]> {
|
|
74
|
-
// The promise is cached, so dialogs opened together share a single request.
|
|
75
|
-
// The back still checks each CRS against the list of the data dimension
|
|
76
|
-
geographicListPromise ??= fetchGeographicList(geodeObjectType);
|
|
77
|
-
const list = await geographicListPromise;
|
|
78
|
-
return list;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function enableCrsEdit(): void {
|
|
82
|
-
crsEditEnabled.value = true;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function requestCrsEdit(dataId: DataId): void {
|
|
86
|
-
crsEditRequest.value = dataId;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function clearCrsEditRequest(): void {
|
|
90
|
-
crsEditRequest.value = undefined;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function setProjectCrs(crs: CRS): void {
|
|
94
|
-
projectCrs.value = crs;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function requestProjectCrsEdit(): void {
|
|
98
|
-
projectCrsEditRequest.value = true;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function clearProjectCrsEditRequest(): void {
|
|
102
|
-
projectCrsEditRequest.value = false;
|
|
103
|
-
}
|
|
10
|
+
const crsItems = useDataStore().refCrsItems();
|
|
11
|
+
const { geographicList } = useGeographicList();
|
|
12
|
+
const { projectCrs, mismatchedCrs, setProjectCrs } = useProjectCrsState(crsItems);
|
|
13
|
+
// Edit and alignment requests, returned as they are
|
|
14
|
+
const requests = useCrsRequests();
|
|
104
15
|
|
|
105
16
|
// A new project: its data set the project CRS again
|
|
106
17
|
function reset(): void {
|
|
107
18
|
projectCrs.value = undefined;
|
|
19
|
+
requests.closeCrsAlign();
|
|
108
20
|
}
|
|
109
21
|
|
|
110
22
|
function exportStores(): { projectCrs?: CRS } {
|
|
@@ -119,17 +31,10 @@ export const useCrsStore = defineStore("crs", () => {
|
|
|
119
31
|
return {
|
|
120
32
|
crsItems,
|
|
121
33
|
geographicList,
|
|
122
|
-
crsEditEnabled,
|
|
123
|
-
enableCrsEdit,
|
|
124
|
-
crsEditRequest,
|
|
125
|
-
requestCrsEdit,
|
|
126
|
-
clearCrsEditRequest,
|
|
127
34
|
projectCrs,
|
|
128
35
|
mismatchedCrs,
|
|
129
36
|
setProjectCrs,
|
|
130
|
-
|
|
131
|
-
requestProjectCrsEdit,
|
|
132
|
-
clearProjectCrsEditRequest,
|
|
37
|
+
...requests,
|
|
133
38
|
reset,
|
|
134
39
|
exportStores,
|
|
135
40
|
importStores,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CRS } from "@geode/opengeodeweb-back/schema_types";
|
|
2
|
+
import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
|
|
3
|
+
import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
|
|
4
|
+
import { useBackStore } from "@ogw_front/stores/back";
|
|
5
|
+
|
|
6
|
+
interface GeographicList {
|
|
7
|
+
geographicList: (geodeObjectType: GeodeObjectType) => Promise<CRS[]>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Session cache of the available CRS
|
|
11
|
+
function useGeographicList(): GeographicList {
|
|
12
|
+
const backStore = useBackStore();
|
|
13
|
+
// OpenGeode geosciences lists the same geographic CRS for 2D and 3D data: one list for all types
|
|
14
|
+
let geographicListPromise: Promise<CRS[]> | undefined = undefined;
|
|
15
|
+
|
|
16
|
+
async function fetchGeographicList(geodeObjectType: GeodeObjectType): Promise<CRS[]> {
|
|
17
|
+
try {
|
|
18
|
+
const response = await backStore.request({
|
|
19
|
+
schema: back_schemas.opengeodeweb_back.crs.geographic_list,
|
|
20
|
+
params: { geode_object_type: geodeObjectType },
|
|
21
|
+
});
|
|
22
|
+
if (response?.crs_list !== undefined) {
|
|
23
|
+
return response.crs_list;
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
// The back store already reports the error to the user
|
|
27
|
+
}
|
|
28
|
+
// A failed request is not cached: the next call retries
|
|
29
|
+
geographicListPromise = undefined;
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function geographicList(geodeObjectType: GeodeObjectType): Promise<CRS[]> {
|
|
34
|
+
// The promise is cached, so dialogs opened together share a single request.
|
|
35
|
+
// The back still checks each CRS against the list of the data dimension
|
|
36
|
+
geographicListPromise ??= fetchGeographicList(geodeObjectType);
|
|
37
|
+
const list = await geographicListPromise;
|
|
38
|
+
return list;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { geographicList };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { useGeographicList };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from "vue";
|
|
2
|
+
import { oldestCrs, sameCrs } from "@ogw_front/utils/crs";
|
|
3
|
+
import type { CRS } from "@geode/opengeodeweb-back/schema_types";
|
|
4
|
+
import type { CrsItem } from "@ogw_front/stores/data";
|
|
5
|
+
|
|
6
|
+
interface ProjectCrsState {
|
|
7
|
+
projectCrs: Ref<CRS | undefined>;
|
|
8
|
+
mismatchedCrs: ComputedRef<Map<string, CRS | undefined>>;
|
|
9
|
+
setProjectCrs: (crs: CRS) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// The CRS every data of the project should be in, given the data CRS
|
|
13
|
+
function referenceCrs(crsItems: CrsItem[], projectCrs: CRS | undefined): CRS | undefined {
|
|
14
|
+
const georeferenced = crsItems.filter((item) => item.crs !== undefined);
|
|
15
|
+
const [first] = georeferenced;
|
|
16
|
+
if (first === undefined) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
if (georeferenced.every((item) => sameCrs(item.crs, first.crs))) {
|
|
20
|
+
return first.crs;
|
|
21
|
+
}
|
|
22
|
+
return projectCrs ?? oldestCrs(georeferenced);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The project CRS and the data out of it
|
|
26
|
+
function useProjectCrsState(crsItems: Ref<CrsItem[]>): ProjectCrsState {
|
|
27
|
+
const projectCrs = ref<CRS | undefined>(undefined);
|
|
28
|
+
|
|
29
|
+
// The project follows its data: once every georeferenced data is in one CRS, it is the project
|
|
30
|
+
// CRS. Data already mixed before any project CRS: the oldest one is the reference
|
|
31
|
+
watch(
|
|
32
|
+
() => referenceCrs(crsItems.value, projectCrs.value),
|
|
33
|
+
(reference) => {
|
|
34
|
+
if (reference !== undefined && !sameCrs(reference, projectCrs.value)) {
|
|
35
|
+
projectCrs.value = reference;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{ immediate: true },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Data without CRS are listed too (value undefined): they could not follow the project
|
|
42
|
+
const mismatchedCrs = computed(() => {
|
|
43
|
+
const project = projectCrs.value;
|
|
44
|
+
const mismatched = new Map<string, CRS | undefined>();
|
|
45
|
+
for (const item of crsItems.value) {
|
|
46
|
+
if (project !== undefined && !sameCrs(item.crs, project)) {
|
|
47
|
+
mismatched.set(item.data_id, item.crs);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return mismatched;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function setProjectCrs(crs: CRS): void {
|
|
54
|
+
projectCrs.value = crs;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return { projectCrs, mismatchedCrs, setProjectCrs };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { useProjectCrsState };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
|
|
2
|
+
import type { DataItem } from "@ogw_front/stores/data";
|
|
3
|
+
import type { Ref } from "vue";
|
|
4
|
+
|
|
5
|
+
interface CrsRequests {
|
|
6
|
+
crsEditEnabled: Ref<boolean>;
|
|
7
|
+
enableCrsEdit: () => void;
|
|
8
|
+
crsEditRequest: Ref<string | undefined>;
|
|
9
|
+
requestCrsEdit: (dataId: DataId) => void;
|
|
10
|
+
clearCrsEditRequest: () => void;
|
|
11
|
+
projectCrsEditRequest: Ref<boolean>;
|
|
12
|
+
requestProjectCrsEdit: () => void;
|
|
13
|
+
clearProjectCrsEditRequest: () => void;
|
|
14
|
+
showCrsAlign: Ref<boolean>;
|
|
15
|
+
crsAlignItem: Ref<DataItem | undefined>;
|
|
16
|
+
openCrsAlign: (item: DataItem) => void;
|
|
17
|
+
closeCrsAlign: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// The channel the shared components use to ask the host app for a CRS edit or an alignment
|
|
21
|
+
function useCrsRequests(): CrsRequests {
|
|
22
|
+
const crsEditEnabled = ref(false);
|
|
23
|
+
const crsEditRequest = ref<string | undefined>(undefined);
|
|
24
|
+
const projectCrsEditRequest = ref(false);
|
|
25
|
+
const showCrsAlign = ref(false);
|
|
26
|
+
const crsAlignItem = ref<DataItem | undefined>(undefined);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
crsEditEnabled,
|
|
30
|
+
enableCrsEdit: (): void => {
|
|
31
|
+
crsEditEnabled.value = true;
|
|
32
|
+
},
|
|
33
|
+
crsEditRequest,
|
|
34
|
+
requestCrsEdit: (dataId: DataId): void => {
|
|
35
|
+
crsEditRequest.value = dataId;
|
|
36
|
+
},
|
|
37
|
+
clearCrsEditRequest: (): void => {
|
|
38
|
+
crsEditRequest.value = undefined;
|
|
39
|
+
},
|
|
40
|
+
projectCrsEditRequest,
|
|
41
|
+
requestProjectCrsEdit: (): void => {
|
|
42
|
+
projectCrsEditRequest.value = true;
|
|
43
|
+
},
|
|
44
|
+
clearProjectCrsEditRequest: (): void => {
|
|
45
|
+
projectCrsEditRequest.value = false;
|
|
46
|
+
},
|
|
47
|
+
showCrsAlign,
|
|
48
|
+
crsAlignItem,
|
|
49
|
+
openCrsAlign: (item: DataItem): void => {
|
|
50
|
+
crsAlignItem.value = item;
|
|
51
|
+
showCrsAlign.value = true;
|
|
52
|
+
},
|
|
53
|
+
closeCrsAlign: (): void => {
|
|
54
|
+
showCrsAlign.value = false;
|
|
55
|
+
crsAlignItem.value = undefined;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { useCrsRequests };
|
package/app/utils/crs.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import type { CrsItem, NewDataItem } from "@ogw_front/stores/data";
|
|
2
2
|
import type { CRS } from "@geode/opengeodeweb-back/schema_types";
|
|
3
3
|
import type { LegacyDataId } from "@ogw_front/utils/legacy_data_id";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
// Only what a CRS selector shows: the back may add other fields
|
|
7
|
+
interface CrsEntry {
|
|
8
|
+
authority: string;
|
|
9
|
+
code: string;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// A stored CRS entry (favorites, history): unknown fields are dropped on read
|
|
14
|
+
const crsEntrySchema = z.object({
|
|
15
|
+
authority: z.string(),
|
|
16
|
+
code: z.string(),
|
|
17
|
+
name: z.string(),
|
|
18
|
+
});
|
|
4
19
|
|
|
5
20
|
function formatCrs(crs: CRS | undefined): string {
|
|
6
21
|
return crs ? `${crs.authority}:${crs.code} — ${crs.name}` : "None";
|
|
@@ -38,4 +53,5 @@ function oldestCrs(
|
|
|
38
53
|
?.crs;
|
|
39
54
|
}
|
|
40
55
|
|
|
41
|
-
export {
|
|
56
|
+
export type { CrsEntry };
|
|
57
|
+
export { crsEntrySchema, formatCrs, formatCrsCode, oldestCrs, sameCrs, sameCrsState };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Local imports
|
|
2
|
+
import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id";
|
|
3
|
+
import { type NewDataItem, useDataStore } from "@ogw_front/stores/data";
|
|
4
|
+
import { useDataStyleStore } from "@ogw_front/stores/data_style";
|
|
5
|
+
import { useFeedbackStore } from "@ogw_front/stores/feedback";
|
|
6
|
+
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
|
|
7
|
+
import { useTreeviewStore } from "@ogw_front/stores/treeview";
|
|
8
|
+
|
|
9
|
+
// Steps that need the data stored first, and run only for the data the viewer shows
|
|
10
|
+
async function registerWhenViewable(item: NewDataItem, added: Promise<unknown>): Promise<unknown> {
|
|
11
|
+
const dataStore = useDataStore();
|
|
12
|
+
await added;
|
|
13
|
+
if (!(await dataStore.isItemViewable(item))) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return dataStore.registerObject(item.data_id, item.name ?? item.data_id);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function addToViewerWhenViewable(
|
|
20
|
+
item: NewDataItem,
|
|
21
|
+
added: Promise<unknown>,
|
|
22
|
+
): Promise<unknown> {
|
|
23
|
+
const dataStore = useDataStore();
|
|
24
|
+
await added;
|
|
25
|
+
if (!(await dataStore.isItemViewable(item))) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return useHybridViewerStore().addItem(item.data_id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function applyStyleWhenReady(item: NewDataItem, ready: Promise<unknown>): Promise<unknown> {
|
|
32
|
+
await ready;
|
|
33
|
+
if (!(await useDataStore().isItemViewable(item))) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return useDataStyleStore().applyDefaultStyle(item.data_id);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
|
|
40
|
+
// Satisfy prefer-readonly-parameter-types deeply; left unfixed (same pattern as app/plugins/auto_store_register.ts).
|
|
41
|
+
async function importDataItem(item: NewDataItem): Promise<string> {
|
|
42
|
+
const dataStore = useDataStore();
|
|
43
|
+
const dataStyleStore = useDataStyleStore();
|
|
44
|
+
const treeviewStore = useTreeviewStore();
|
|
45
|
+
if (item.nb_vertices === 0) {
|
|
46
|
+
const feedbackStore = useFeedbackStore();
|
|
47
|
+
feedbackStore.add_warning(`"${item.geode_object_type}" with name "${item.name}" is empty`);
|
|
48
|
+
}
|
|
49
|
+
const addDataTask = dataStore.addItem(item);
|
|
50
|
+
const registerTask = registerWhenViewable(item, addDataTask);
|
|
51
|
+
let addDataComponentsTask: Promise<unknown> = Promise.resolve(undefined);
|
|
52
|
+
let addDataRelationsTask: Promise<unknown> = Promise.resolve(undefined);
|
|
53
|
+
if (item.viewer_object_type === "model") {
|
|
54
|
+
addDataComponentsTask = dataStore.addComponents(item);
|
|
55
|
+
addDataRelationsTask = dataStore.addComponentRelations(item);
|
|
56
|
+
}
|
|
57
|
+
treeviewStore.addItem(
|
|
58
|
+
item.geode_object_type,
|
|
59
|
+
item.name ?? item.data_id,
|
|
60
|
+
item.data_id,
|
|
61
|
+
item.geode_id,
|
|
62
|
+
item.viewer_object_type,
|
|
63
|
+
);
|
|
64
|
+
const addDataStyleTask = dataStyleStore.addDataStyle(item.data_id, item.geode_object_type);
|
|
65
|
+
const addViewerTask = addToViewerWhenViewable(item, addDataTask);
|
|
66
|
+
const applyStyleTask = applyStyleWhenReady(
|
|
67
|
+
item,
|
|
68
|
+
Promise.all([registerTask, addDataComponentsTask, addDataStyleTask]),
|
|
69
|
+
);
|
|
70
|
+
await Promise.all([
|
|
71
|
+
registerTask,
|
|
72
|
+
addDataTask,
|
|
73
|
+
addDataComponentsTask,
|
|
74
|
+
addDataRelationsTask,
|
|
75
|
+
addViewerTask,
|
|
76
|
+
applyStyleTask,
|
|
77
|
+
]);
|
|
78
|
+
return item.data_id;
|
|
79
|
+
}
|
|
80
|
+
// Every item comes through here: from the back-end, which still names its data id `id`, or from a project
|
|
81
|
+
async function importItem(imported: LegacyDataId<NewDataItem> | NewDataItem): Promise<string> {
|
|
82
|
+
const item = fromLegacyDataId(imported);
|
|
83
|
+
const dataId = await useTreeviewStore().untilLoaded(item.data_id, importDataItem(item));
|
|
84
|
+
return dataId;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { importItem };
|