From fe07bb50737854f005ebe72c91669d336f978ffd Mon Sep 17 00:00:00 2001 From: Mumbi Francis Date: Mon, 20 Mar 2023 17:17:33 +0300 Subject: [PATCH] Add geolocation capture feature on record geometry field --- .../ModuleFields/Configurator/Geometry.vue | 42 +++++- .../ModuleFields/Editor/Geometry.vue | 132 ++++++++++++++++-- .../ModuleFields/Viewer/Geometry.vue | 32 ++++- .../components/PageBlocks/GeometryBase.vue | 32 ++++- .../GeometryConfigurator/Configurator.vue | 36 ++++- client/web/compose/src/components/faIcons.js | 2 + .../compose/types/module-field/geometry.ts | 6 + locale/en/corteza-webapp-compose/field.yaml | 8 +- .../corteza-webapp-compose/notification.yaml | 8 ++ 9 files changed, 272 insertions(+), 26 deletions(-) diff --git a/client/web/compose/src/components/ModuleFields/Configurator/Geometry.vue b/client/web/compose/src/components/ModuleFields/Configurator/Geometry.vue index 3e1a389d5..660fdc677 100644 --- a/client/web/compose/src/components/ModuleFields/Configurator/Geometry.vue +++ b/client/web/compose/src/components/ModuleFields/Configurator/Geometry.vue @@ -1,21 +1,44 @@ @@ -51,16 +65,17 @@ diff --git a/client/web/compose/src/components/PageBlocks/GeometryConfigurator/Configurator.vue b/client/web/compose/src/components/PageBlocks/GeometryConfigurator/Configurator.vue index 4a6cca02d..e5534f8ab 100644 --- a/client/web/compose/src/components/PageBlocks/GeometryConfigurator/Configurator.vue +++ b/client/web/compose/src/components/PageBlocks/GeometryConfigurator/Configurator.vue @@ -14,11 +14,25 @@ @update:zoom="zoomUpdated" @update:center="updateCenter" @update:bounds="boundsUpdated" + @locationfound="onLocationFound" > + + + + + {{ $t('geometry.mapHelpText') }} @@ -130,16 +144,19 @@ diff --git a/client/web/compose/src/components/faIcons.js b/client/web/compose/src/components/faIcons.js index 6721331e5..78dd4fee0 100644 --- a/client/web/compose/src/components/faIcons.js +++ b/client/web/compose/src/components/faIcons.js @@ -62,6 +62,7 @@ import { faSync, faExclamationTriangle, faEllipsisV, + faLocationArrow, } from '@fortawesome/free-solid-svg-icons' import { @@ -172,4 +173,5 @@ library.add( faExclamationTriangle, faSync, faEllipsisV, + faLocationArrow, ) diff --git a/lib/js/src/compose/types/module-field/geometry.ts b/lib/js/src/compose/types/module-field/geometry.ts index 1a661b03c..653b0f226 100644 --- a/lib/js/src/compose/types/module-field/geometry.ts +++ b/lib/js/src/compose/types/module-field/geometry.ts @@ -7,6 +7,8 @@ interface GeometryOptions extends Options { center: number[]; zoom: number; multiDelimiter: string; + prefillWithCurrentLocation: boolean; + hideCurrentLocationButton: boolean; } const defaults = (): Readonly => Object.freeze({ @@ -14,6 +16,8 @@ const defaults = (): Readonly => Object.freeze({ center: [30, 30], zoom: 3, multiDelimiter: '\n', + prefillWithCurrentLocation: false, + hideCurrentLocationButton: false, }) export class ModuleFieldGeometry extends ModuleField { @@ -32,6 +36,8 @@ export class ModuleFieldGeometry extends ModuleField { Apply(this.options, o, String, 'multiDelimiter') Apply(this.options, o, Number, 'zoom') + Apply(this.options, o, Boolean, 'prefillWithCurrentLocation') + Apply(this.options, o, Boolean, 'hideCurrentLocationButton') if (o.center) { this.options.center = o.center diff --git a/locale/en/corteza-webapp-compose/field.yaml b/locale/en/corteza-webapp-compose/field.yaml index c2119bfb6..eb24b7dc0 100644 --- a/locale/en/corteza-webapp-compose/field.yaml +++ b/locale/en/corteza-webapp-compose/field.yaml @@ -143,8 +143,14 @@ kind: label: Geometry latitude: Latitude longitude: Longitude - clickToPlaceMarker: Click to place a marker or click on a marker to remove it + clickToPlaceMarker: Click to place/remove a marker initialZoomAndPosition: Set initial map zoom and position + prefillWithCurrentLocation: Prefill with current location + hideCurrentLocationButton: Hide current location button + tooltip: + goToCurrentLocation: Go to current location + useCurrentLocation: Use current location + openMap: Open map noPermission: No permission to read field value no-items-found: No items found options: diff --git a/locale/en/corteza-webapp-compose/notification.yaml b/locale/en/corteza-webapp-compose/notification.yaml index 914349ae2..98065bb72 100644 --- a/locale/en/corteza-webapp-compose/notification.yaml +++ b/locale/en/corteza-webapp-compose/notification.yaml @@ -28,6 +28,14 @@ field: field-datetime: valueNotFuture: Past value on future only field valueNotPast: Future value on past only field +field-geometry: + geolocationErrors: + permissionDenied: User denied the request for geolocation + positionUnavailable: Location information is unavailable + timeout: The request to get user location timed out + unknownError: An unknown error occurred + notSupported: Geolocation is not supported by this browser + errorOccurred: An error occurred while getting user location general: composeAccessNotAllowed: Not allowed to access Compose error: Error