From cd6a62ad34e0af54ab7aaef569ba3760c2b0468a Mon Sep 17 00:00:00 2001 From: Damian Cruz Date: Fri, 1 Sep 2023 13:13:07 +0200 Subject: [PATCH 1/5] nav to custom location --- src/wayfinding/components/MapView.tsx | 39 ++++++++++++++++++++++++++- src/wayfinding/hooks/index.ts | 39 +++++++++++++++++++-------- src/wayfinding/types/constants.ts | 2 ++ src/wayfinding/types/index.ts | 13 +++++++++ src/wayfinding/utils/mapper.ts | 10 ++++++- 5 files changed, 90 insertions(+), 13 deletions(-) diff --git a/src/wayfinding/components/MapView.tsx b/src/wayfinding/components/MapView.tsx index dcb0bf10..460590fe 100644 --- a/src/wayfinding/components/MapView.tsx +++ b/src/wayfinding/components/MapView.tsx @@ -18,6 +18,7 @@ import useSitum, { useCallbackRef } from "../hooks"; import { setWebViewRef } from "../store"; import { useDispatch } from "../store/utils"; import { + type NavigateToLocationType, type MapViewError, type MapViewRef, type NavigateToPoiType, @@ -169,6 +170,29 @@ const MapView = React.forwardRef( [pois] ); + const navigateToLocationRef = useCallbackRef( + ({ + lat, + lng, + floorIdentifier, + navigationName, + }: NavigateToLocationType) => { + if (!webViewRef.current || (!lat && !lng && !floorIdentifier)) return; + + sendMessageToViewer( + webViewRef.current, + Mapper.navigateToLocation({ + // @ts-ignore + lat: lat, + lng: lng, + floorIdentifier: floorIdentifier, + navigationName: navigationName, + } as NavigateToLocationType) + ); + }, + [pois] + ); + const selectPoiRef = useCallbackRef( (poiId: number) => { if (!webViewRef.current) { @@ -212,6 +236,19 @@ const MapView = React.forwardRef( navigateToPoi({ poi, poiId }: { poi?: Poi; poiId?: number }): void { navigateToPoiRef.current({ poi, poiId }); }, + navigateToLocation({ + lat, + lng, + floorIdentifier, + navigationName, + }: NavigateToLocationType): void { + navigateToLocationRef.current({ + lat, + lng, + floorIdentifier, + navigationName, + }); + }, cancelNavigation(): void { if (!webViewRef.current) return; stopNavigation(); @@ -219,7 +256,7 @@ const MapView = React.forwardRef( }, }; }, - [stopNavigation, navigateToPoiRef, selectPoiRef] + [stopNavigation, navigateToPoiRef, selectPoiRef, navigateToLocationRef] ); useEffect(() => { diff --git a/src/wayfinding/hooks/index.ts b/src/wayfinding/hooks/index.ts index aa776955..96b9e063 100644 --- a/src/wayfinding/hooks/index.ts +++ b/src/wayfinding/hooks/index.ts @@ -46,6 +46,10 @@ import { UseSitumContext, } from "../store/index"; import { useDispatch, useSelector } from "../store/utils"; +import { + CURRENT_USER_LOCATION_ID, + CUSTOM_DESTINATION_LOCATION_ID, +} from "../types/constants"; const defaultNavigationOptions = { distanceToGoalThreshold: 4, @@ -309,15 +313,18 @@ export const useSitumInternal = () => { (p: Poi) => p.identifier === destinationId?.toString() ); - if (!poiDestination || (!poiOrigin && originId !== -1) || lockDirections) { + if ( + (!poiDestination && destinationId !== CUSTOM_DESTINATION_LOCATION_ID) || + (!poiOrigin && originId !== CURRENT_USER_LOCATION_ID) || + lockDirections + ) { console.debug( `Situm > hook > Could not compute route for origin: ${originId} or destination: ${destinationId} (lockDirections: ${lockDirections})` ); return; } - const from = - originId === -1 && location + originId === CURRENT_USER_LOCATION_ID && location ? location.position : { buildingIdentifier: poiOrigin.buildingIdentifier, @@ -326,12 +333,20 @@ export const useSitumInternal = () => { coordinate: poiOrigin.coordinate, }; - const to = { - buildingIdentifier: poiDestination.buildingIdentifier, - floorIdentifier: poiDestination.floorIdentifier, - cartesianCoordinate: poiDestination.cartesianCoordinate, - coordinate: poiDestination.coordinate, - }; + const to = + destinationId === CUSTOM_DESTINATION_LOCATION_ID + ? { + buildingIdentifier: directionsOptions.to.buildingIdentifier, + floorIdentifier: directionsOptions.to.floorIdentifier, + cartesianCoordinate: directionsOptions.to.cartesianCoordinate, + coordinate: directionsOptions.to.coordinate, + } + : { + buildingIdentifier: poiDestination.buildingIdentifier, + floorIdentifier: poiDestination.floorIdentifier, + cartesianCoordinate: poiDestination.cartesianCoordinate, + coordinate: poiDestination.coordinate, + }; // iOS workaround -> does not allow for several direction petitions setLockDirections(true); @@ -344,7 +359,7 @@ export const useSitumInternal = () => { type: directionsOptions?.accessibilityMode, }; updateRoute && dispatch(setDirections(extendedRoute)); - return directions; + return extendedRoute; // directions }) .catch((e: string) => { dispatch(setDirections({ error: JSON.stringify(e) })); @@ -360,6 +375,7 @@ export const useSitumInternal = () => { directionsOptions, navigationOptions, originId, + to, }: { callback?: (status: string, navigation?: SDKNavigation) => void; destinationId: number; @@ -367,6 +383,7 @@ export const useSitumInternal = () => { navigationOptions?: any; originId: number; updateRoute?: boolean; + to: any; }) => { stopNavigation(); calculateRoute({ @@ -375,7 +392,7 @@ export const useSitumInternal = () => { directionsOptions, updateRoute: false, }).then((r) => { - if (originId !== -1 || !location || !r) { + if (originId !== CURRENT_USER_LOCATION_ID || !location || !r) { callback && callback("error"); return; } diff --git a/src/wayfinding/types/constants.ts b/src/wayfinding/types/constants.ts index ea095e43..abc935fd 100644 --- a/src/wayfinding/types/constants.ts +++ b/src/wayfinding/types/constants.ts @@ -3,3 +3,5 @@ export enum ErrorName { ERR_INTERNET_DISCONNECTED = "ERR_INTERNET_DISCONNECTED", ERR_INTERNAL_SERVER_ERROR = "ERR_INTERNAL_SERVER_ERROR", } +export const CURRENT_USER_LOCATION_ID = -1; +export const CUSTOM_DESTINATION_LOCATION_ID = -2; diff --git a/src/wayfinding/types/index.ts b/src/wayfinding/types/index.ts index 9b7723c5..2ee59531 100644 --- a/src/wayfinding/types/index.ts +++ b/src/wayfinding/types/index.ts @@ -9,6 +9,12 @@ export interface MapViewError { export interface MapViewRef { selectPoi: (poiId: number) => void; navigateToPoi: ({ poi, poiId }: { poi?: Poi; poiId?: number }) => void; + navigateToLocation: ({ + lat, + lng, + floorIdentifier, + navigationName, + }: NavigateToLocationType) => void; cancelNavigation: () => void; } @@ -61,3 +67,10 @@ export type NavigateToPoiType = { navigationTo: number; type?: string; }; + +export type NavigateToLocationType = { + lat: number; + lng: number; + floorIdentifier: string; + navigationName?: string; +}; diff --git a/src/wayfinding/utils/mapper.ts b/src/wayfinding/utils/mapper.ts index a00949a5..98af5835 100644 --- a/src/wayfinding/utils/mapper.ts +++ b/src/wayfinding/utils/mapper.ts @@ -5,7 +5,12 @@ import type { Location, SDKNavigation, } from "../../sdk/types"; -import type { Destination, NavigateToPoiType, Navigation } from "../types"; +import type { + Destination, + NavigateToLocationType, + NavigateToPoiType, + Navigation, +} from "../types"; const mapperWrapper = (type: string, payload: unknown) => JSON.stringify({ type, payload }); @@ -40,6 +45,9 @@ const Mapper = { navigateToPoi: (navigate: NavigateToPoiType) => mapperWrapper(`navigation.start`, { navigationTo: navigate?.navigationTo }), + navigateToLocation: (navigate: NavigateToLocationType) => + mapperWrapper(`navigation.to_location`, navigate), + cancelNavigation: () => mapperWrapper(`navigation.cancel`, {}), selectPoi: (poiId: number | null) => From be9aee4cab7ecdcbc43d48954897943d096b6bf0 Mon Sep 17 00:00:00 2001 From: Damian Cruz Date: Mon, 4 Sep 2023 09:18:31 +0200 Subject: [PATCH 2/5] overload navigation start and rename nav to location to nav to point --- src/wayfinding/components/MapView.tsx | 23 +++++++++-------------- src/wayfinding/hooks/index.ts | 2 -- src/wayfinding/types/index.ts | 6 +++--- src/wayfinding/utils/mapper.ts | 6 +++--- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/wayfinding/components/MapView.tsx b/src/wayfinding/components/MapView.tsx index 460590fe..b17b162b 100644 --- a/src/wayfinding/components/MapView.tsx +++ b/src/wayfinding/components/MapView.tsx @@ -18,7 +18,7 @@ import useSitum, { useCallbackRef } from "../hooks"; import { setWebViewRef } from "../store"; import { useDispatch } from "../store/utils"; import { - type NavigateToLocationType, + type NavigateToPointType, type MapViewError, type MapViewRef, type NavigateToPoiType, @@ -170,24 +170,19 @@ const MapView = React.forwardRef( [pois] ); - const navigateToLocationRef = useCallbackRef( - ({ - lat, - lng, - floorIdentifier, - navigationName, - }: NavigateToLocationType) => { + const navigateToPointRef = useCallbackRef( + ({ lat, lng, floorIdentifier, navigationName }: NavigateToPointType) => { if (!webViewRef.current || (!lat && !lng && !floorIdentifier)) return; sendMessageToViewer( webViewRef.current, - Mapper.navigateToLocation({ + Mapper.navigateToPoint({ // @ts-ignore lat: lat, lng: lng, floorIdentifier: floorIdentifier, navigationName: navigationName, - } as NavigateToLocationType) + } as NavigateToPointType) ); }, [pois] @@ -236,13 +231,13 @@ const MapView = React.forwardRef( navigateToPoi({ poi, poiId }: { poi?: Poi; poiId?: number }): void { navigateToPoiRef.current({ poi, poiId }); }, - navigateToLocation({ + navigateToPoint({ lat, lng, floorIdentifier, navigationName, - }: NavigateToLocationType): void { - navigateToLocationRef.current({ + }: NavigateToPointType): void { + navigateToPointRef.current({ lat, lng, floorIdentifier, @@ -256,7 +251,7 @@ const MapView = React.forwardRef( }, }; }, - [stopNavigation, navigateToPoiRef, selectPoiRef, navigateToLocationRef] + [stopNavigation, navigateToPoiRef, selectPoiRef, navigateToPointRef] ); useEffect(() => { diff --git a/src/wayfinding/hooks/index.ts b/src/wayfinding/hooks/index.ts index 96b9e063..29fa29e5 100644 --- a/src/wayfinding/hooks/index.ts +++ b/src/wayfinding/hooks/index.ts @@ -375,7 +375,6 @@ export const useSitumInternal = () => { directionsOptions, navigationOptions, originId, - to, }: { callback?: (status: string, navigation?: SDKNavigation) => void; destinationId: number; @@ -383,7 +382,6 @@ export const useSitumInternal = () => { navigationOptions?: any; originId: number; updateRoute?: boolean; - to: any; }) => { stopNavigation(); calculateRoute({ diff --git a/src/wayfinding/types/index.ts b/src/wayfinding/types/index.ts index 2ee59531..987ade2c 100644 --- a/src/wayfinding/types/index.ts +++ b/src/wayfinding/types/index.ts @@ -9,12 +9,12 @@ export interface MapViewError { export interface MapViewRef { selectPoi: (poiId: number) => void; navigateToPoi: ({ poi, poiId }: { poi?: Poi; poiId?: number }) => void; - navigateToLocation: ({ + navigateToPoint: ({ lat, lng, floorIdentifier, navigationName, - }: NavigateToLocationType) => void; + }: NavigateToPointType) => void; cancelNavigation: () => void; } @@ -68,7 +68,7 @@ export type NavigateToPoiType = { type?: string; }; -export type NavigateToLocationType = { +export type NavigateToPointType = { lat: number; lng: number; floorIdentifier: string; diff --git a/src/wayfinding/utils/mapper.ts b/src/wayfinding/utils/mapper.ts index 98af5835..461c934e 100644 --- a/src/wayfinding/utils/mapper.ts +++ b/src/wayfinding/utils/mapper.ts @@ -7,7 +7,7 @@ import type { } from "../../sdk/types"; import type { Destination, - NavigateToLocationType, + NavigateToPointType, NavigateToPoiType, Navigation, } from "../types"; @@ -45,8 +45,8 @@ const Mapper = { navigateToPoi: (navigate: NavigateToPoiType) => mapperWrapper(`navigation.start`, { navigationTo: navigate?.navigationTo }), - navigateToLocation: (navigate: NavigateToLocationType) => - mapperWrapper(`navigation.to_location`, navigate), + navigateToPoint: (navigate: NavigateToPointType) => + mapperWrapper(`navigation.start`, navigate), cancelNavigation: () => mapperWrapper(`navigation.cancel`, {}), From fadd6b919b00161797076e5645962d3410d7b70e Mon Sep 17 00:00:00 2001 From: Damian Cruz Date: Thu, 7 Sep 2023 12:37:28 +0200 Subject: [PATCH 3/5] adding type/acces mode to navigate to point --- src/wayfinding/components/MapView.tsx | 11 ++++++++++- src/wayfinding/types/index.ts | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wayfinding/components/MapView.tsx b/src/wayfinding/components/MapView.tsx index b17b162b..26d11295 100644 --- a/src/wayfinding/components/MapView.tsx +++ b/src/wayfinding/components/MapView.tsx @@ -171,7 +171,13 @@ const MapView = React.forwardRef( ); const navigateToPointRef = useCallbackRef( - ({ lat, lng, floorIdentifier, navigationName }: NavigateToPointType) => { + ({ + lat, + lng, + floorIdentifier, + navigationName, + type, + }: NavigateToPointType) => { if (!webViewRef.current || (!lat && !lng && !floorIdentifier)) return; sendMessageToViewer( @@ -182,6 +188,7 @@ const MapView = React.forwardRef( lng: lng, floorIdentifier: floorIdentifier, navigationName: navigationName, + type: type, } as NavigateToPointType) ); }, @@ -236,12 +243,14 @@ const MapView = React.forwardRef( lng, floorIdentifier, navigationName, + type, }: NavigateToPointType): void { navigateToPointRef.current({ lat, lng, floorIdentifier, navigationName, + type, }); }, cancelNavigation(): void { diff --git a/src/wayfinding/types/index.ts b/src/wayfinding/types/index.ts index 987ade2c..24c28133 100644 --- a/src/wayfinding/types/index.ts +++ b/src/wayfinding/types/index.ts @@ -73,4 +73,5 @@ export type NavigateToPointType = { lng: number; floorIdentifier: string; navigationName?: string; + type?: string; }; From 29253805692136e405f6b09e44eb8c3669da3e43 Mon Sep 17 00:00:00 2001 From: Damian Cruz Date: Thu, 7 Sep 2023 12:58:59 +0200 Subject: [PATCH 4/5] addint types for accesibility mode --- src/wayfinding/types/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wayfinding/types/index.ts b/src/wayfinding/types/index.ts index 24c28133..d224e9f9 100644 --- a/src/wayfinding/types/index.ts +++ b/src/wayfinding/types/index.ts @@ -68,10 +68,15 @@ export type NavigateToPoiType = { type?: string; }; +export type NavigationAccessibilityTypes = + | "CHOOSE_SHORTEST" + | "ONLY_NOT_ACCESSIBLE_FLOOR_CHANGES" + | "ONLY_ACCESSIBLE"; + export type NavigateToPointType = { lat: number; lng: number; floorIdentifier: string; navigationName?: string; - type?: string; + type?: NavigationAccessibilityTypes; }; From 90bfd212d6745667772656a9c0ec80eeb65b0dde Mon Sep 17 00:00:00 2001 From: Damian Cruz Date: Thu, 7 Sep 2023 13:35:34 +0200 Subject: [PATCH 5/5] addint types for accesibility mode --- src/wayfinding/types/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wayfinding/types/index.ts b/src/wayfinding/types/index.ts index d224e9f9..6145151e 100644 --- a/src/wayfinding/types/index.ts +++ b/src/wayfinding/types/index.ts @@ -14,6 +14,7 @@ export interface MapViewRef { lng, floorIdentifier, navigationName, + type, }: NavigateToPointType) => void; cancelNavigation: () => void; }