From 6fdbf9680ab5dba23e45009fa3671e59dbfc3267 Mon Sep 17 00:00:00 2001 From: Sam <78538841+spwoodcock@users.noreply.github.com> Date: Mon, 9 Dec 2024 19:56:36 +0545 Subject: [PATCH] feat(mapper): add new point geom in maplibre terradraw, inject to ODK collect (#1966) --- src/mapper/package.json | 1 + src/mapper/pnpm-lock.yaml | 20 ++++ .../lib/components/dialog-task-actions.svelte | 27 +----- src/mapper/src/lib/components/map/main.svelte | 94 +++++++++++++++++-- src/mapper/src/lib/components/qrcode.svelte | 2 +- src/mapper/src/lib/odk/collect.ts | 26 +++++ src/mapper/src/lib/odk/javarosa.ts | 43 +++++++++ src/mapper/src/lib/{utils => odk}/qrcode.ts | 0 .../src/routes/[projectId]/+page.svelte | 21 ++++- 9 files changed, 195 insertions(+), 39 deletions(-) create mode 100644 src/mapper/src/lib/odk/collect.ts create mode 100644 src/mapper/src/lib/odk/javarosa.ts rename src/mapper/src/lib/{utils => odk}/qrcode.ts (100%) diff --git a/src/mapper/package.json b/src/mapper/package.json index 36196c6c46..e1e2839b9c 100644 --- a/src/mapper/package.json +++ b/src/mapper/package.json @@ -51,6 +51,7 @@ "@turf/bbox": "^7.1.0", "@turf/buffer": "^7.1.0", "@turf/helpers": "^7.1.0", + "@watergis/maplibre-gl-terradraw": "^0.5.1", "drizzle-orm": "^0.35.3", "flatgeobuf": "^3.36.0", "maplibre-gl": "^4.7.1", diff --git a/src/mapper/pnpm-lock.yaml b/src/mapper/pnpm-lock.yaml index 0ede86887b..48b13effbd 100644 --- a/src/mapper/pnpm-lock.yaml +++ b/src/mapper/pnpm-lock.yaml @@ -38,6 +38,9 @@ importers: '@turf/helpers': specifier: ^7.1.0 version: 7.1.0 + '@watergis/maplibre-gl-terradraw': + specifier: ^0.5.1 + version: 0.5.1(maplibre-gl@4.7.1)(terra-draw@1.0.0-beta.8) drizzle-orm: specifier: ^0.35.3 version: 0.35.3(@electric-sql/pglite@0.2.14)(@libsql/client-wasm@0.14.0)(@prisma/client@4.8.1)(@types/react@18.3.3) @@ -1703,6 +1706,13 @@ packages: '@vue/shared@3.5.13': resolution: {integrity: sha512-/hnE/qP5ZoGpol0a5mDi45bOd7t3tjYJBjsgCsivow7D48cJeV5l05RD82lPqi7gRiphZM37rnhW1l6ZoCNNnQ==} + '@watergis/maplibre-gl-terradraw@0.5.1': + resolution: {integrity: sha512-SIvCbrQYnYTJhTNqra3xKW6hUFzPRwvPiUlYoupjRqElmoEMjP7/t0+mDS+sDVofqArtzmcJ3OiaezgymnkDhw==} + engines: {pnpm: ^9.0.0} + peerDependencies: + maplibre-gl: ^2.0.0 || ^3.0.0 || ^4.0.0 + terra-draw: ^1.0.0-beta.1 + acorn-jsx@5.3.2: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: @@ -3353,6 +3363,9 @@ packages: resolution: {integrity: sha512-G13vtMYPT/J8A4X2SjdtBTphZlrp1gKv6hZiOjw14RCWg6GbHuQBGtjlx75xLbYV/wEc0D7G5K4rxKP/cXk8Bw==} engines: {node: '>=10'} + terra-draw@1.0.0-beta.8: + resolution: {integrity: sha512-40kOjgOQkDDmRIkz7QZ4urjwb9v/+Zm7tPf3RqeDY4UtKm3JodZ5iz3fFm93u3nzd+QVQlOZF0VF15ew0esQ7A==} + terser@5.36.0: resolution: {integrity: sha512-IYV9eNMuFAV4THUspIRXkLakHnV6XO7FEdtKjf/mDyrnqUg9LnlOn6/RwRvM9SZjR4GUq8Nk8zj67FzVARr74w==} engines: {node: '>=10'} @@ -5499,6 +5512,11 @@ snapshots: '@vue/shared@3.5.13': {} + '@watergis/maplibre-gl-terradraw@0.5.1(maplibre-gl@4.7.1)(terra-draw@1.0.0-beta.8)': + dependencies: + maplibre-gl: 4.7.1 + terra-draw: 1.0.0-beta.8 + acorn-jsx@5.3.2(acorn@8.14.0): dependencies: acorn: 8.14.0 @@ -7242,6 +7260,8 @@ snapshots: type-fest: 0.16.0 unique-string: 2.0.0 + terra-draw@1.0.0-beta.8: {} + terser@5.36.0: dependencies: '@jridgewell/source-map': 0.3.6 diff --git a/src/mapper/src/lib/components/dialog-task-actions.svelte b/src/mapper/src/lib/components/dialog-task-actions.svelte index cf5813cef3..1b4c2c5072 100644 --- a/src/mapper/src/lib/components/dialog-task-actions.svelte +++ b/src/mapper/src/lib/components/dialog-task-actions.svelte @@ -2,36 +2,17 @@ import { mapTask, finishTask, resetTask } from '$lib/db/events'; import type { ProjectData } from '$lib/types'; import { getTaskStore } from '$store/tasks.svelte.ts'; - import { getAlertStore } from '$store/common.svelte.ts'; type Props = { isTaskActionModalOpen: boolean; toggleTaskActionModal: (value: boolean) => void; selectedTab: string; projectData: ProjectData; + clickMapNewFeature: () => void; }; const taskStore = getTaskStore(); - const alertStore = getAlertStore(); - let { isTaskActionModalOpen, toggleTaskActionModal, selectedTab, projectData }: Props = $props(); - - function mapNewFeature() { - const xformId = projectData?.odk_form_id; - if (!xformId) { - return; - } - - const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); - - if (isMobile) { - document.location.href = `odkcollect://form/${xformId}`; - } else { - alertStore.setAlert({ - variant: 'warning', - message: 'Requires a mobile phone with ODK Collect.', - }); - } - } + let { isTaskActionModalOpen, toggleTaskActionModal, selectedTab, projectData, clickMapNewFeature }: Props = $props(); {#if taskStore.selectedTaskId && selectedTab === 'map' && isTaskActionModalOpen && (taskStore.selectedTaskState === 'UNLOCKED_TO_MAP' || taskStore.selectedTaskState === 'LOCKED_FOR_MAPPING')} @@ -57,11 +38,11 @@