Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 42 additions & 1 deletion src/wayfinding/components/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import useSitum, { useCallbackRef } from "../hooks";
import { setWebViewRef } from "../store";
import { useDispatch } from "../store/utils";
import {
type NavigateToPointType,
type MapViewError,
type MapViewRef,
type NavigateToPoiType,
Expand Down Expand Up @@ -169,6 +170,31 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
[pois]
);

const navigateToPointRef = useCallbackRef(
({
lat,
lng,
floorIdentifier,
navigationName,
type,
}: NavigateToPointType) => {
if (!webViewRef.current || (!lat && !lng && !floorIdentifier)) return;

sendMessageToViewer(
webViewRef.current,
Mapper.navigateToPoint({
// @ts-ignore
lat: lat,
lng: lng,
floorIdentifier: floorIdentifier,
navigationName: navigationName,
type: type,
} as NavigateToPointType)
);
},
[pois]
);

const selectPoiRef = useCallbackRef(
(poiId: number) => {
if (!webViewRef.current) {
Expand Down Expand Up @@ -212,14 +238,29 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
navigateToPoi({ poi, poiId }: { poi?: Poi; poiId?: number }): void {
navigateToPoiRef.current({ poi, poiId });
},
navigateToPoint({
lat,
lng,
floorIdentifier,
navigationName,
type,
}: NavigateToPointType): void {
navigateToPointRef.current({
lat,
lng,
floorIdentifier,
navigationName,
type,
});
},
cancelNavigation(): void {
if (!webViewRef.current) return;
stopNavigation();
sendMessageToViewer(webViewRef.current, Mapper.cancelNavigation());
},
};
},
[stopNavigation, navigateToPoiRef, selectPoiRef]
[stopNavigation, navigateToPoiRef, selectPoiRef, navigateToPointRef]
);

useEffect(() => {
Expand Down
37 changes: 26 additions & 11 deletions src/wayfinding/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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) }));
Expand Down Expand Up @@ -375,7 +390,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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/wayfinding/types/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
20 changes: 20 additions & 0 deletions src/wayfinding/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export interface MapViewError {
export interface MapViewRef {
selectPoi: (poiId: number) => void;
navigateToPoi: ({ poi, poiId }: { poi?: Poi; poiId?: number }) => void;
navigateToPoint: ({
lat,
lng,
floorIdentifier,
navigationName,
type,
}: NavigateToPointType) => void;
cancelNavigation: () => void;
}

Expand Down Expand Up @@ -61,3 +68,16 @@ export type NavigateToPoiType = {
navigationTo: number;
type?: string;
};

export type NavigationAccessibilityTypes =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to enum

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export enum RouteType {
CHOOSE_SHORTEST = "CHOOSE_SHORTEST",
ONLY_ACCESSIBLE = "ONLY_ACCESSIBLE",
ONLY_NOT_ACCESSIBLE_FLOOR_CHANGES = "ONLY_NOT_ACCESSIBLE_FLOOR_CHANGES",
}

| "CHOOSE_SHORTEST"
| "ONLY_NOT_ACCESSIBLE_FLOOR_CHANGES"
| "ONLY_ACCESSIBLE";

export type NavigateToPointType = {
lat: number;
lng: number;
floorIdentifier: string;
navigationName?: string;
type?: NavigationAccessibilityTypes;
};
10 changes: 9 additions & 1 deletion src/wayfinding/utils/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import type {
Location,
SDKNavigation,
} from "../../sdk/types";
import type { Destination, NavigateToPoiType, Navigation } from "../types";
import type {
Destination,
NavigateToPointType,
NavigateToPoiType,
Navigation,
} from "../types";

const mapperWrapper = (type: string, payload: unknown) =>
JSON.stringify({ type, payload });
Expand Down Expand Up @@ -40,6 +45,9 @@ const Mapper = {
navigateToPoi: (navigate: NavigateToPoiType) =>
mapperWrapper(`navigation.start`, { navigationTo: navigate?.navigationTo }),

navigateToPoint: (navigate: NavigateToPointType) =>
mapperWrapper(`navigation.start`, navigate),

cancelNavigation: () => mapperWrapper(`navigation.cancel`, {}),

selectPoi: (poiId: number | null) =>
Expand Down