Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distance constraint add on frontend #2084

Merged
merged 17 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
98471f9
feat(package): turf/distance package add for distance calculation bet…
NSUWAL123 Jan 13, 2025
ecb6779
fix(types): ProjectData type update
NSUWAL123 Jan 13, 2025
d2cfabd
fix(geolocation): reset userLocation coordinate if location disabled
NSUWAL123 Jan 13, 2025
c053890
feat(dialog-entities-actions): function add to check validity of dist…
NSUWAL123 Jan 13, 2025
3d81fa2
fix(dialog-entities): fix typo
NSUWAL123 Jan 13, 2025
4cdb795
feat(package): turf/distance package add for distance calculation bet…
NSUWAL123 Jan 13, 2025
5f63d14
fix(types): ProjectData type update
NSUWAL123 Jan 13, 2025
f66cef4
fix(geolocation): reset userLocation coordinate if location disabled
NSUWAL123 Jan 13, 2025
31e9caf
feat(dialog-entities-actions): function add to check validity of dist…
NSUWAL123 Jan 13, 2025
3c9f4c5
fix(dialog-entities): fix typo
NSUWAL123 Jan 13, 2025
b9f4c1a
refactor: update new feature draw warning/error logic
spwoodcock Jan 13, 2025
3b24cf6
docs: update comment describing the new feat dist constraint
spwoodcock Jan 13, 2025
7b44d00
fix(merge): merge conflict solve
NSUWAL123 Jan 15, 2025
9e7c5c3
Merge branch 'development' of github.com:hotosm/fmtm into feat/distan…
NSUWAL123 Jan 16, 2025
947725a
fix(dialog-entities-actions): update distance constraing logic
NSUWAL123 Jan 16, 2025
fe34e78
feat(dialog-entities-actions): show warning dialog on feature map if …
NSUWAL123 Jan 20, 2025
1fbcaba
Merge branch 'development' of github.com:hotosm/fmtm into feat/distan…
NSUWAL123 Jan 20, 2025
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
1 change: 1 addition & 0 deletions src/mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@turf/bbox": "^7.1.0",
"@turf/buffer": "^7.1.0",
"@turf/centroid": "^7.1.0",
"@turf/distance": "^7.2.0",
"@turf/helpers": "^7.1.0",
"@watergis/maplibre-gl-terradraw": "^0.5.1",
"drizzle-orm": "^0.35.3",
Expand Down
30 changes: 30 additions & 0 deletions src/mapper/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/mapper/src/lib/components/dialog-entities-actions.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { distance } from '@turf/distance';
import type { Coord } from '@turf/helpers';
import { TaskStatusEnum, type ProjectData } from '$lib/types';
import { getEntitiesStatusStore } from '$store/entities.svelte.ts';
import { getAlertStore } from '$store/common.svelte.ts';
Expand All @@ -25,7 +27,37 @@
const selectedEntityCoordinate = $derived(entitiesStore.selectedEntityCoordinate);
const entityToNavigate = $derived(entitiesStore.entityToNavigate);

// check if distance constraint is set to projectand is valid
const isDistanceConstaintValid = (): boolean => {
if (projectData?.geo_restrict_force_error) {
const to = entitiesStore.selectedEntityCoordinate?.coordinate;
const from = entitiesStore.userLocationCoord;
if (!from) {
alertStore.setAlert({
message:
'This project has a distance constraint set. Please enable device geolocation for optimal functionality',
variant: 'warning',
});
return false;
}

const entityDistance = distance(from as Coord, to as Coord, { units: 'kilometers' }) * 1000;
if (entityDistance && entityDistance > projectData?.geo_restrict_distance_meters) {
alertStore.setAlert({
message: `The feature must be within ${projectData?.geo_restrict_distance_meters} meters of your location`,
variant: 'warning',
});
return false;
}

return true;
}
return true;
};

const mapFeature = () => {
if (!isDistanceConstaintValid()) return;

const xformId = projectData?.odk_form_id;
const entityUuid = selectedEntity?.entity_id;

Expand Down
1 change: 1 addition & 0 deletions src/mapper/src/lib/components/map/geolocation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
on:click={() => {
entitiesStore.setToggleGeolocation(!entitiesStore.toggleGeolocation);
if (!entitiesStore.toggleGeolocation) {
entitiesStore.setUserLocationCoordinate(undefined);
exitNavigationMode();
}
}}
Expand Down
2 changes: 2 additions & 0 deletions src/mapper/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface ProjectData {
status: number;
hashtags: string[];
tasks: ProjectTask[];
geo_restrict_distance_meters: number;
geo_restrict_force_error: boolean;
}

export interface ZoomToTaskEventDetail {
Expand Down
Loading