Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions app/components/CrsSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,53 @@ function crs_key(crs: CRS): string {
return `${crs.authority}:${crs.code}`;
}

// The row picked in the table, and the optional heights that complete it
const horizontal_crs = ref<CRS | undefined>(undefined);
const heights_crs = ref<CRS | undefined>(undefined);

// Projected and geographic 2D CRS have no heights: only these take a vertical CRS
const heights_enabled = computed(
() =>
horizontal_crs.value !== undefined &&
crsStore.compoundable.includes(crs_key(horizontal_crs.value)),
);

function heights_title(crs: CRS): string {
return `${crs.name} (${crs_key(crs)})`;
}

// "A+B": EPSG has no single code for most projected + height pairs
function emit_selection(): void {
const horizontal = horizontal_crs.value;
const heights = heights_crs.value;
if (horizontal === undefined || heights === undefined) {
selectedCrs.value = horizontal;
return;
}
selectedCrs.value = {
authority: horizontal.authority,
code: `${horizontal.code}+${heights.code}`,
name: `${horizontal.name} + ${heights.name}`,
};
}

// A click on the row selects it: no checkbox column. Enter does the same once the row is focused
function select_crs(crs: CRS): void {
selectedCrs.value = crs;
horizontal_crs.value = crs;
if (!heights_enabled.value) {
heights_crs.value = undefined;
}
emit_selection();
}

function select_heights(crs: CRS | undefined | null): void {
heights_crs.value = crs ?? undefined;
emit_selection();
}

function row_props({ item }: { item: CRS }): Record<string, unknown> {
const selected = selectedCrs.value !== undefined && crs_key(item) === crs_key(selectedCrs.value);
const selected =
horizontal_crs.value !== undefined && crs_key(item) === crs_key(horizontal_crs.value);
return {
class: ["crs-row", { "bg-primary": selected }],
tabindex: 0,
Expand Down Expand Up @@ -111,6 +151,25 @@ onMounted(async () => {
</v-tooltip>
</template>
</v-data-table>
<v-autocomplete
data-testid="crsHeightsInput"
:model-value="heights_crs"
:items="crsStore.verticalList"
:item-title="heights_title"
:item-value="crs_key"
return-object
clearable
:disabled="!heights_enabled"
label="Heights (optional)"
:hint="
horizontal_crs !== undefined && !heights_enabled ? 'This CRS already includes heights' : ''
"
persistent-hint
:prepend-inner-icon="compact ? undefined : 'ph-arrows-vertical'"
density="compact"
class="mt-2"
@update:model-value="select_heights"
></v-autocomplete>
</template>

<style scoped>
Expand Down
3 changes: 1 addition & 2 deletions app/stores/basemap_helpers/georeferenced.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type Extent, boxesExtent } from "./extent.js";
import type { ComputedRef } from "vue";
import { sameCrs } from "@ogw_front/utils/crs";
import { useCrsStore } from "@ogw_front/stores/crs";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";

Expand All @@ -21,7 +20,7 @@ function useGeoreferenced(): Georeferenced {

function georeferencedIds(): string[] {
return crsStore.crsItems
.filter((item) => sameCrs(item.crs, crsStore.projectCrs))
.filter((item) => crsStore.sameProjectCrs(item.crs, crsStore.projectCrs))
.map((item) => item.data_id);
}

Expand Down
24 changes: 20 additions & 4 deletions app/stores/crs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { oldestCrs, sameCrs } from "@ogw_front/utils/crs";
import { oldestCrs, sameHorizontalCrs } from "@ogw_front/utils/crs";
import type { CRS } from "@geode/opengeodeweb-back/schema_types";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
Expand All @@ -18,6 +18,15 @@ export const useCrsStore = defineStore("crs", () => {
const crsItems = dataStore.refCrsItems();
const projectCrs = ref<CRS | undefined>(undefined);
const projectCrsEditRequest = ref(false);
// From the geographic list: the heights a CRS can take, and the X/Y part of compound CRS
const verticalList = shallowRef<CRS[]>([]);
const compoundable = shallowRef<string[]>([]);
const horizontalParts = shallowRef<Record<string, string>>({});

// Heights are a label of each data: the project compares the X/Y part only
function sameProjectCrs(left: CRS | undefined, right: CRS | undefined): boolean {
return sameHorizontalCrs(left, right, horizontalParts.value);
}

// The project follows its data: once every georeferenced data is in one CRS, it is the project
// CRS. Data already mixed before any project CRS: the oldest one is the reference
Expand All @@ -28,13 +37,13 @@ export const useCrsStore = defineStore("crs", () => {
if (first === undefined) {
return undefined;
}
if (georeferenced.every((item) => sameCrs(item.crs, first.crs))) {
if (georeferenced.every((item) => sameProjectCrs(item.crs, first.crs))) {
return first.crs;
}
return projectCrs.value ?? oldestCrs(georeferenced);
},
(reference) => {
if (reference !== undefined && !sameCrs(reference, projectCrs.value)) {
if (reference !== undefined && !sameProjectCrs(reference, projectCrs.value)) {
projectCrs.value = reference;
}
},
Expand All @@ -46,7 +55,7 @@ export const useCrsStore = defineStore("crs", () => {
const project = projectCrs.value;
const mismatched = new Map<string, CRS | undefined>();
for (const item of crsItems.value) {
if (project !== undefined && !sameCrs(item.crs, project)) {
if (project !== undefined && !sameProjectCrs(item.crs, project)) {
mismatched.set(item.data_id, item.crs);
}
}
Expand All @@ -60,6 +69,9 @@ export const useCrsStore = defineStore("crs", () => {
params: { geode_object_type: geodeObjectType },
});
if (response?.crs_list !== undefined) {
verticalList.value = response.vertical_list;
compoundable.value = response.compoundable;
horizontalParts.value = response.horizontal_parts;
return response.crs_list;
}
} catch {
Expand Down Expand Up @@ -119,6 +131,10 @@ export const useCrsStore = defineStore("crs", () => {
return {
crsItems,
geographicList,
verticalList,
compoundable,
horizontalParts,
sameProjectCrs,
crsEditEnabled,
enableCrsEdit,
crsEditRequest,
Expand Down
31 changes: 30 additions & 1 deletion app/utils/crs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ function sameCrs(left: CRS | undefined, right: CRS | undefined): boolean {
);
}

// The X/Y part of a CRS: "A" for a compound "A+B" code, the horizontal part of a registered
// Compound CRS given by the back (e.g. "EPSG:5698" -> "EPSG:2154"), the CRS itself otherwise
function horizontalCode(crs: CRS, horizontalParts: Record<string, string> = {}): string {
const key = `${crs.authority}:${crs.code}`;
const [horizontal = crs.code] = crs.code.split("+");
return horizontalParts[key] ?? `${crs.authority}:${horizontal}`;
}

// Heights are a label of each data: two CRS place X and Y the same when their horizontal parts do
function sameHorizontalCrs(
left: CRS | undefined,
right: CRS | undefined,
horizontalParts: Record<string, string> = {},
): boolean {
return (
left !== undefined &&
right !== undefined &&
horizontalCode(left, horizontalParts) === horizontalCode(right, horizontalParts)
);
}

// Same CRS, or both still in local coordinates
function sameCrsState(left: CRS | undefined, right: CRS | undefined): boolean {
return (left === undefined && right === undefined) || sameCrs(left, right);
Expand All @@ -38,4 +59,12 @@ function oldestCrs(
?.crs;
}

export { formatCrs, formatCrsCode, oldestCrs, sameCrs, sameCrsState };
export {
formatCrs,
formatCrsCode,
horizontalCode,
oldestCrs,
sameCrs,
sameCrsState,
sameHorizontalCrs,
};
39 changes: 39 additions & 0 deletions tests/unit/components/CrsSelector.nuxt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,45 @@
expect(wrapper.find("tbody tr").classes()).toContain("bg-primary");
});

test("composes the selected crs with optional heights", async () => {
const nztm = { authority: "EPSG", code: "2193", name: "NZGD2000 / NZTM 2000" };
const nzgdNzvd = { authority: "EPSG", code: "9528", name: "NZGD2000 + NZVD2016 height" };
const nzvd = { authority: "EPSG", code: "7839", name: "NZVD2016 height" };
const crsStore = useCrsStore();
crsStore.geographicList = mockAs<typeof crsStore.geographicList>(
vi.fn().mockResolvedValue([nztm, nzgdNzvd]),
);
crsStore.verticalList = [nzvd];
crsStore.compoundable = ["EPSG:2193"];

const wrapper = await mountSuspended(CrsSelector, {
global: { plugins: [vuetify, pinia] },
props: { geodeObjectType: "BRep" },
});
await wrapper.vm.$nextTick();
const heights = wrapper.findComponent('[data-testid="crsHeightsInput"]');
// Nothing to complete before a crs without heights is selected
expect(heights.props("disabled")).toBe(true);

Check failure on line 150 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

typescript(no-unsafe-call)

tests/unit/components/CrsSelector.nuxt.test.ts:150:12: Unsafe call of a(n) `error` type typed value.

Check failure on line 150 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

typescript(TS2339)

tests/unit/components/CrsSelector.nuxt.test.ts:150:20: Property 'props' does not exist on type 'WrapperLike'.

await wrapper.findAll("tbody tr")[FIRST_INDEX]?.trigger("click");
expect(heights.props("disabled")).toBe(false);

Check failure on line 153 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

typescript(no-unsafe-call)

tests/unit/components/CrsSelector.nuxt.test.ts:153:12: Unsafe call of a(n) `error` type typed value.

Check failure on line 153 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

typescript(TS2339)

tests/unit/components/CrsSelector.nuxt.test.ts:153:20: Property 'props' does not exist on type 'WrapperLike'.
heights.vm.$emit("update:modelValue", nzvd);

Check failure on line 154 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

typescript(no-unsafe-call)

tests/unit/components/CrsSelector.nuxt.test.ts:154:5: Unsafe call of a(n) `error` type typed value.

Check failure on line 154 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

typescript(TS2339)

tests/unit/components/CrsSelector.nuxt.test.ts:154:13: Property 'vm' does not exist on type 'WrapperLike'.
await wrapper.vm.$nextTick();
const emitted = wrapper.emitted<unknown[]>()["update:modelValue"] ?? [];

Check failure on line 156 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

vitest(no-conditional-in-test)

tests/unit/components/CrsSelector.nuxt.test.ts:156:21: Avoid having conditionals in tests.
expect(emitted.at(-1)?.[FIRST_INDEX]).toStrictEqual({
authority: "EPSG",
code: "2193+7839",
name: "NZGD2000 / NZTM 2000 + NZVD2016 height",
});

// A crs that already has heights: the heights are cleared
await wrapper.findAll("tbody tr")[ESRI_INDEX]?.trigger("click");
expect(emitted.at(-1)?.[FIRST_INDEX]).toStrictEqual(nzgdNzvd);
// Vuetify shows an empty value as null
expect(heights.props("modelValue")).toBeNull();

Check failure on line 167 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

typescript(TS2339)

tests/unit/components/CrsSelector.nuxt.test.ts:167:20: Property 'props' does not exist on type 'WrapperLike'.
expect(heights.props("disabled")).toBe(true);

Check failure on line 168 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

typescript(TS2339)

tests/unit/components/CrsSelector.nuxt.test.ts:168:20: Property 'props' does not exist on type 'WrapperLike'.

Check failure on line 168 in tests/unit/components/CrsSelector.nuxt.test.ts

View workflow job for this annotation

GitHub Actions / test / oxlint

vitest(max-expects)

tests/unit/components/CrsSelector.nuxt.test.ts:168:5: Enforces a maximum number assertion calls in a test body.
});

test("does not offer to show all the crs at once", async () => {
const crsStore = useCrsStore();
crsStore.geographicList = mockAs<typeof crsStore.geographicList>(vi.fn().mockResolvedValue([]));
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/stores/crs.nuxt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ describe("project crs", () => {
]);
});

test("data in the horizontal part of a compound project crs are in the project crs", () => {
const nztm = { authority: "EPSG", code: "2193", name: "NZGD2000 / NZTM 2000" };
const nztmNzvd = { authority: "EPSG", code: "2193+7839", name: "NZTM 2000 + NZVD2016 height" };
mockItems(
mockAs<DataItem[]>([
{ data_id: "model", created_at: "1", crs: nztmNzvd },
{ data_id: "map", created_at: "2", crs: nztm },
]),
);
const crsStore = useCrsStore();
crsStore.setProjectCrs(nztmNzvd);
// Heights are a label of each data: they do not set them apart from the project
expect(crsStore.mismatchedCrs.size).toBe(0);
expect(crsStore.projectCrs).toStrictEqual(nztmNzvd);
});

test("is exported and imported with the project", () => {
mockItems(mockAs<DataItem[]>([{ data_id: "a", created_at: "1", crs: LAMBERT }]));
const crsStore = useCrsStore();
Expand Down
30 changes: 29 additions & 1 deletion tests/unit/utils/crs.nuxt.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { describe, expect, test, vi } from "vitest";
import { formatCrs, formatCrsCode, oldestCrs, sameCrs, sameCrsState } from "@ogw_front/utils/crs";
import {
formatCrs,
formatCrsCode,
oldestCrs,
sameCrs,
sameCrsState,
sameHorizontalCrs,
} from "@ogw_front/utils/crs";
import type { DataItem } from "@ogw_front/stores/data";
import { mockAs } from "@ogw_tests/utils";

Expand Down Expand Up @@ -36,6 +43,27 @@ describe("same crs", () => {
});
});

const NZTM = { authority: "EPSG", code: "2193", name: "NZGD2000 / NZTM 2000" };
const NZTM_NZVD = { authority: "EPSG", code: "2193+7839", name: "NZTM 2000 + NZVD2016 height" };
const LAMBERT_NGF = {
authority: "EPSG",
code: "5698",
name: "RGF93 v1 / Lambert-93 + NGF-IGN69 height",
};

describe("same horizontal crs", () => {
test("a compound code is in the crs of its horizontal part, even before the list loads", () => {
expect(sameHorizontalCrs(NZTM, NZTM_NZVD)).toBe(true);
expect(sameHorizontalCrs(LAMBERT, NZTM_NZVD)).toBe(false);
expect(sameHorizontalCrs(undefined, NZTM)).toBe(false);
});

test("a registered compound crs is in the crs of its horizontal part", () => {
expect(sameHorizontalCrs(LAMBERT, LAMBERT_NGF, { "EPSG:5698": "EPSG:2154" })).toBe(true);
expect(sameHorizontalCrs(LAMBERT, LAMBERT_NGF)).toBe(false);
});
});

describe("oldest crs", () => {
test("is the crs of the oldest georeferenced data", () => {
const items = mockAs<DataItem[]>([
Expand Down
Loading