-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathcanvas-portal.tsx
More file actions
55 lines (49 loc) · 1.48 KB
/
canvas-portal.tsx
File metadata and controls
55 lines (49 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Canvas } from "@react-three/fiber";
import { memo, useState } from "react";
import { Matrix4Tuple } from "three";
import { CanvasProps } from "../../api/canvas-props";
import { events } from "../events";
import { FromLngLat, MapInstance } from "../generic-map";
import { useFunction } from "../use-function";
import { InitR3M } from "./init-r3m";
import { SyncCameraFC } from "./sync-camera-fc";
interface CanvasPortalProps extends CanvasProps {
setOnRender: (callback: () => (mx: Matrix4Tuple) => void) => void,
map: MapInstance,
fromLngLat: FromLngLat,
}
export const CanvasPortal = memo<CanvasPortalProps>(({
children, latitude, longitude, altitude,
setOnRender, map, fromLngLat, ...props
}) => {
const mapCanvas = map.getCanvas();
const eventSource = mapCanvas.parentElement!; // eslint-disable-line @typescript-eslint/no-non-null-assertion
const [ready, setReady] = useState(false);
const onReady = useFunction(() => {
setReady(true);
})
return <Canvas
events={events}
eventSource={eventSource}
{...props}
gl={{ autoClear: false, ...props.gl }}
>
<InitR3M
map={map}
fromLngLat={fromLngLat}
latitude={latitude}
longitude={longitude}
altitude={altitude}
/>
<SyncCameraFC
latitude={latitude}
longitude={longitude}
altitude={altitude}
setOnRender={setOnRender}
onReady={onReady}
map={map}
/>
{ready && children}
</Canvas>
})
CanvasPortal.displayName = 'CanvasPortal';