Skip to content

Commit

Permalink
Merge pull request #2049 from hotosm/fix/limit-routing-api
Browse files Browse the repository at this point in the history
Mapper Navigation: Limit routing API call
  • Loading branch information
NSUWAL123 authored Jan 1, 2025
2 parents 94b7eb2 + da9d061 commit 4e20c3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/mapper/src/lib/components/dialog-entities-actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
const navigateToEntity = () => {
if (!entitiesStore.toggleGeolocation) {
entitiesStore.setToggleGeolocation(true);
alertStore.setAlert({ message: 'Please enable geolocation to navigate to the entity.', variant: 'warning' });
return;
}
entitiesStore.setEntityToNavigate(selectedEntityCoordinate);
};
Expand Down
17 changes: 14 additions & 3 deletions src/mapper/src/lib/components/map/geolocation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { getCommonStore } from '$store/common.svelte.ts';
import { layers } from '$assets/maplibre-directions.ts';
import locationUrl from '$assets/images/location.png';
import { untrack } from 'svelte';
interface Props {
map: maplibregl.Map | undefined;
Expand Down Expand Up @@ -68,10 +69,20 @@
}
}
// set waypoints for navigation on every 10 seconds if navigation mode is on i.e. entityToNavigate is not null
// don't track user geolocation
$effect(() => {
if (entitiesStore.userLocationCoord && entityToNavigate) {
setWaypoints(entitiesStore.userLocationCoord as [number, number], entityToNavigate?.coordinate);
}
if (!untrack(() => entitiesStore.userLocationCoord) && !entityToNavigate) return;
entityToNavigate?.coordinate &&
setWaypoints(untrack(() => entitiesStore.userLocationCoord) as [number, number], entityToNavigate?.coordinate);
const interval = setInterval(() => {
entityToNavigate?.coordinate &&
setWaypoints(untrack(() => entitiesStore.userLocationCoord) as [number, number], entityToNavigate?.coordinate);
}, 10000);
return () => {
clearInterval(interval);
};
});
// if navigation mode on, tilt map by 50 degrees
Expand Down

0 comments on commit 4e20c3c

Please sign in to comment.