-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): support for spatial id (#1331)
Co-authored-by: mkumbobeaty <[email protected]>
- Loading branch information
1 parent
9e409d9
commit 9441b7b
Showing
15 changed files
with
1,526 additions
and
868 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
web/src/beta/features/Visualizer/Crust/Plugins/hooks/useSpatialId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useCallback, useEffect, useMemo, useRef } from "react"; | ||
|
||
import { | ||
SpatialIdEventType, | ||
SpatialIdPickSpaceOptions | ||
} from "../pluginAPI/types"; | ||
import { Props } from "../types"; | ||
import { events } from "../utils/events"; | ||
|
||
export default ({ | ||
mapRef, | ||
mapAPIReady | ||
}: Pick<Props, "mapRef" | "mapAPIReady">) => { | ||
const spatialIdPickSpace = useCallback( | ||
(options?: SpatialIdPickSpaceOptions) => { | ||
mapRef?.current?.spatialId?.pickSpace(options); | ||
}, | ||
[mapRef] | ||
); | ||
|
||
const spatialIdExitPickSpace = useCallback(() => { | ||
mapRef?.current?.spatialId?.exitPickSpace(); | ||
}, [mapRef]); | ||
|
||
const [spatialIdEvents, emit] = useMemo( | ||
() => events<SpatialIdEventType>(), | ||
[] | ||
); | ||
|
||
const spacePickEventBinded = useRef(false); | ||
useEffect(() => { | ||
if ( | ||
mapAPIReady && | ||
!spacePickEventBinded.current && | ||
mapRef?.current?.spatialId?.onSpacePick | ||
) { | ||
mapRef.current.spatialId.onSpacePick((e) => { | ||
emit("spacePick", e); | ||
}); | ||
spacePickEventBinded.current = true; | ||
} | ||
}, [emit, mapRef, mapAPIReady]); | ||
|
||
const spatialIdEventsOn = useCallback( | ||
<T extends keyof SpatialIdEventType>( | ||
type: T, | ||
callback: (...args: SpatialIdEventType[T]) => void, | ||
options?: { once?: boolean } | ||
) => { | ||
return options?.once | ||
? spatialIdEvents.once(type, callback) | ||
: spatialIdEvents.on(type, callback); | ||
}, | ||
[spatialIdEvents] | ||
); | ||
|
||
const spatialIdEventsOff = useCallback( | ||
<T extends keyof SpatialIdEventType>( | ||
type: T, | ||
callback: (...args: SpatialIdEventType[T]) => void | ||
) => { | ||
return spatialIdEvents.off(type, callback); | ||
}, | ||
[spatialIdEvents] | ||
); | ||
|
||
return { | ||
spatialIdPickSpace, | ||
spatialIdExitPickSpace, | ||
spatialIdEventsOn, | ||
spatialIdEventsOff, | ||
spatialIdEvents | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
web/src/beta/features/Visualizer/Crust/Plugins/pluginAPI/constaint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const REEATH_PLUGIN_API_VERSION = "2.0.0"; | ||
export const REEATH_PLUGIN_API_VERSION = "2.1.0"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
web/src/beta/features/Visualizer/Crust/Plugins/pluginAPI/types/spatialId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export declare type SpatialId = { | ||
pickSpace: (options?: SpatialIdPickSpaceOptions) => void; | ||
exitPickSpace: () => void; | ||
on: SpatialIdEvents["on"]; | ||
off: SpatialIdEvents["off"]; | ||
}; | ||
|
||
export declare type SpatialIdPickSpaceOptions = { | ||
zoom?: number; | ||
maxHeight?: number; | ||
color?: string; | ||
dataOnly?: boolean; | ||
rightClickToExit?: boolean; | ||
}; | ||
|
||
export declare type SpatialIdSpacePickProps = SpatialIdSpaceData; | ||
|
||
export declare type SpatialIdSpaceData = { | ||
id: string; | ||
center: { lat: number; lng: number; alt?: number }; | ||
alt: number; | ||
zoom: number; | ||
zfxy: { | ||
z: number; | ||
f: number; | ||
x: number; | ||
y: number; | ||
}; | ||
zfxyStr: string; | ||
tilehash: string; | ||
hilbertTilehash: string; | ||
hilbertIndex: string; | ||
vertices: [number, number, number][]; | ||
}; | ||
|
||
export declare type SpatialIdEventType = { | ||
spacePick: [props: SpatialIdSpacePickProps]; | ||
}; | ||
|
||
export declare type SpatialIdEvents = { | ||
readonly on: <T extends keyof SpatialIdEventType>( | ||
type: T, | ||
callback: (...args: SpatialIdEventType[T]) => void, | ||
options?: { once?: boolean } | ||
) => void; | ||
readonly off: <T extends keyof SpatialIdEventType>( | ||
type: T, | ||
callback: (...args: SpatialIdEventType[T]) => void | ||
) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.