react-three-map 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +18 -3
- package/dist/cjs/main.js +35 -18
- package/dist/es/main.mjs +5 -3
- package/dist/es/main.mjs.map +1 -1
- package/dist/es/main10.mjs +8 -33
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +33 -11
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main12.mjs +11 -22
- package/dist/es/main12.mjs.map +1 -1
- package/dist/es/main13.mjs +17 -24
- package/dist/es/main13.mjs.map +1 -1
- package/dist/es/main14.mjs +2 -23
- package/dist/es/main14.mjs.map +1 -1
- package/dist/es/main15.mjs +28 -93
- package/dist/es/main15.mjs.map +1 -1
- package/dist/es/main16.mjs +21 -61
- package/dist/es/main16.mjs.map +1 -1
- package/dist/es/main17.mjs +94 -19
- package/dist/es/main17.mjs.map +1 -1
- package/dist/es/main18.mjs +62 -23
- package/dist/es/main18.mjs.map +1 -1
- package/dist/es/main19.mjs +17 -13
- package/dist/es/main19.mjs.map +1 -1
- package/dist/es/main20.mjs +23 -68
- package/dist/es/main20.mjs.map +1 -1
- package/dist/es/main21.mjs +19 -0
- package/dist/es/main21.mjs.map +1 -0
- package/dist/es/main22.mjs +83 -0
- package/dist/es/main22.mjs.map +1 -0
- package/dist/es/main3.mjs +3 -3
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main4.mjs +3 -3
- package/dist/es/main5.mjs +12 -19
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +19 -15
- package/dist/es/main6.mjs.map +1 -1
- package/dist/es/main7.mjs +10 -22
- package/dist/es/main7.mjs.map +1 -1
- package/dist/es/main8.mjs +22 -26
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +26 -8
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +35 -18
- package/dist/maplibre/es/main.mjs +5 -3
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main10.mjs +8 -33
- package/dist/maplibre/es/main10.mjs.map +1 -1
- package/dist/maplibre/es/main11.mjs +33 -11
- package/dist/maplibre/es/main11.mjs.map +1 -1
- package/dist/maplibre/es/main12.mjs +11 -22
- package/dist/maplibre/es/main12.mjs.map +1 -1
- package/dist/maplibre/es/main13.mjs +17 -24
- package/dist/maplibre/es/main13.mjs.map +1 -1
- package/dist/maplibre/es/main14.mjs +2 -23
- package/dist/maplibre/es/main14.mjs.map +1 -1
- package/dist/maplibre/es/main15.mjs +28 -93
- package/dist/maplibre/es/main15.mjs.map +1 -1
- package/dist/maplibre/es/main16.mjs +21 -61
- package/dist/maplibre/es/main16.mjs.map +1 -1
- package/dist/maplibre/es/main17.mjs +94 -19
- package/dist/maplibre/es/main17.mjs.map +1 -1
- package/dist/maplibre/es/main18.mjs +62 -23
- package/dist/maplibre/es/main18.mjs.map +1 -1
- package/dist/maplibre/es/main19.mjs +17 -13
- package/dist/maplibre/es/main19.mjs.map +1 -1
- package/dist/maplibre/es/main20.mjs +23 -68
- package/dist/maplibre/es/main20.mjs.map +1 -1
- package/dist/maplibre/es/main21.mjs +19 -0
- package/dist/maplibre/es/main21.mjs.map +1 -0
- package/dist/maplibre/es/main22.mjs +83 -0
- package/dist/maplibre/es/main22.mjs.map +1 -0
- package/dist/maplibre/es/main3.mjs +3 -3
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +3 -3
- package/dist/maplibre/es/main5.mjs +12 -19
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/es/main6.mjs +19 -15
- package/dist/maplibre/es/main6.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +10 -22
- package/dist/maplibre/es/main7.mjs.map +1 -1
- package/dist/maplibre/es/main8.mjs +22 -26
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/es/main9.mjs +26 -8
- package/dist/maplibre/es/main9.mjs.map +1 -1
- package/dist/maplibre/types/api/coords-to-vector-3.d.ts +2 -3
- package/dist/maplibre/types/api/index.d.ts +2 -1
- package/dist/maplibre/types/api/vector-3-to-coords.d.ts +3 -0
- package/dist/maplibre/types/core/canvas-overlay/sync-camera-fc.d.ts +2 -1
- package/dist/maplibre/types/core/earth-radius.d.ts +1 -0
- package/dist/types/api/coords-to-vector-3.d.ts +2 -3
- package/dist/types/api/index.d.ts +2 -1
- package/dist/types/api/vector-3-to-coords.d.ts +3 -0
- package/dist/types/core/canvas-overlay/sync-camera-fc.d.ts +2 -1
- package/dist/types/core/earth-radius.d.ts +1 -0
- package/package.json +6 -9
- package/stories/package.json +4 -4
- package/stories/yarn.lock +1931 -1085
- package/vitest.config.ts +1 -5
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const store = _roots.get(canvas).store;
|
|
12
|
-
initR3M({ ...props, store });
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
function initR3M({ store, ...props }) {
|
|
16
|
-
const viewProjMx = new Matrix4().identity().toArray();
|
|
17
|
-
const r3m = { ...props, viewProjMx };
|
|
18
|
-
store.setState({ r3m });
|
|
19
|
-
return r3m;
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { coordsToMatrix } from "./main19.mjs";
|
|
3
|
+
function useCoordsToMatrix({ latitude, longitude, altitude, fromLngLat }) {
|
|
4
|
+
const m4 = useMemo(() => coordsToMatrix({
|
|
5
|
+
latitude,
|
|
6
|
+
longitude,
|
|
7
|
+
altitude,
|
|
8
|
+
fromLngLat
|
|
9
|
+
}), [latitude, longitude, altitude, fromLngLat]);
|
|
10
|
+
return m4;
|
|
20
11
|
}
|
|
21
12
|
export {
|
|
22
|
-
|
|
23
|
-
useInitR3M,
|
|
24
|
-
useR3M
|
|
13
|
+
useCoordsToMatrix
|
|
25
14
|
};
|
|
26
15
|
//# sourceMappingURL=main12.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main12.mjs","sources":["../../../src/core/use-
|
|
1
|
+
{"version":3,"file":"main12.mjs","sources":["../../../src/core/use-coords-to-matrix.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { coordsToMatrix } from \"./coords-to-matrix\";\n\ntype Props = Parameters<typeof coordsToMatrix>[0];\n\n/** calculate matrix from coordinates */\nexport function useCoordsToMatrix({latitude, longitude, altitude, fromLngLat}: Props) {\n const m4 = useMemo(() => coordsToMatrix({\n latitude, longitude, altitude, fromLngLat,\n }), [latitude, longitude, altitude, fromLngLat]);\n\n return m4;\n}"],"names":[],"mappings":";;AAMO,SAAS,kBAAkB,EAAC,UAAU,WAAW,UAAU,cAAoB;AAC9E,QAAA,KAAK,QAAQ,MAAM,eAAe;AAAA,IACtC;AAAA,IAAU;AAAA,IAAW;AAAA,IAAU;AAAA,EAAA,CAChC,GAAG,CAAC,UAAU,WAAW,UAAU,UAAU,CAAC;AAExC,SAAA;AACT;"}
|
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
import { useThree, _roots } from "@react-three/fiber";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Matrix4 } from "three";
|
|
4
|
+
function useR3M() {
|
|
5
|
+
const r3m = useThree((s) => s.r3m);
|
|
6
|
+
return r3m;
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
+
function useInitR3M(props) {
|
|
8
9
|
const canvas = useThree((s) => s.gl.domElement);
|
|
9
|
-
|
|
10
|
+
useState(() => {
|
|
10
11
|
const store = _roots.get(canvas).store;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}, [longitude, latitude, altitude]);
|
|
12
|
+
initR3M({ ...props, store });
|
|
13
|
+
});
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
useMemo(() => {
|
|
21
|
-
setCoords(store, { longitude, latitude, altitude });
|
|
22
|
-
}, [longitude, latitude, altitude]);
|
|
23
|
-
}
|
|
24
|
-
function setCoords(store, coords) {
|
|
25
|
-
store.setState({ coords });
|
|
15
|
+
function initR3M({ store, ...props }) {
|
|
16
|
+
const viewProjMx = new Matrix4().identity().toArray();
|
|
17
|
+
const r3m = { ...props, viewProjMx };
|
|
18
|
+
store.setState({ r3m });
|
|
19
|
+
return r3m;
|
|
26
20
|
}
|
|
27
21
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
useSetRootCoords
|
|
22
|
+
initR3M,
|
|
23
|
+
useInitR3M,
|
|
24
|
+
useR3M
|
|
32
25
|
};
|
|
33
26
|
//# sourceMappingURL=main13.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main13.mjs","sources":["../../../src/core/use-
|
|
1
|
+
{"version":3,"file":"main13.mjs","sources":["../../../src/core/use-r3m.ts"],"sourcesContent":["import { RootState, _roots, useThree } from \"@react-three/fiber\";\nimport { useState } from \"react\";\nimport { Matrix4, Matrix4Tuple } from \"three\";\nimport { UseBoundStore } from 'zustand';\nimport { FromLngLat, MapInstance } from \"./generic-map\";\n\nexport interface R3M<T extends MapInstance = MapInstance> {\n /** Map provider */\n map: T,\n /** view projection matrix coming from the map provider */\n viewProjMx: Matrix4Tuple,\n fromLngLat: FromLngLat,\n}\n\nexport function useR3M<T extends MapInstance> () {\n const r3m = useThree(s=>(s as any).r3m) as R3M<T>; // eslint-disable-line @typescript-eslint/no-explicit-any\n return r3m;\n}\n\n/** init `useR3M` hook */\nexport function useInitR3M<T extends MapInstance>(props: {\n map: T; fromLngLat: FromLngLat;\n}) {\n const canvas = useThree(s => s.gl.domElement);\n // to run only once\n useState(()=>{\n const store = _roots.get(canvas)!.store; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n initR3M({...props, store})\n })\n}\n\nexport function initR3M<T extends MapInstance>({store, ...props}: {\n map: T;\n fromLngLat: FromLngLat;\n store: UseBoundStore<RootState>;\n}) {\n const viewProjMx = new Matrix4().identity().toArray();\n const r3m : R3M<T> = { ...props, viewProjMx };\n store.setState({r3m} as any); // eslint-disable-line @typescript-eslint/no-explicit-any\n return r3m;\n}"],"names":[],"mappings":";;;AAcO,SAAS,SAAiC;AAC/C,QAAM,MAAM,SAAS,CAAI,MAAA,EAAU,GAAG;AAC/B,SAAA;AACT;AAGO,SAAS,WAAkC,OAE/C;AACD,QAAM,SAAS,SAAS,CAAK,MAAA,EAAE,GAAG,UAAU;AAE5C,WAAS,MAAI;AACX,UAAM,QAAQ,OAAO,IAAI,MAAM,EAAG;AAClC,YAAQ,EAAC,GAAG,OAAO,MAAM,CAAA;AAAA,EAAA,CAC1B;AACH;AAEO,SAAS,QAA+B,EAAC,OAAO,GAAG,SAIvD;AACD,QAAM,aAAa,IAAI,QAAA,EAAU,WAAW,QAAQ;AACpD,QAAM,MAAe,EAAE,GAAG,OAAO,WAAW;AACtC,QAAA,SAAS,EAAC,IAAA,CAAW;AACpB,SAAA;AACT;"}
|
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { useFunction } from "./main9.mjs";
|
|
3
|
-
function useRender({
|
|
4
|
-
map,
|
|
5
|
-
origin,
|
|
6
|
-
useThree,
|
|
7
|
-
frameloop,
|
|
8
|
-
r3m
|
|
9
|
-
}) {
|
|
10
|
-
const render = useFunction((_gl, projViewMx) => {
|
|
11
|
-
r3m.viewProjMx.splice(0, 16, ...projViewMx);
|
|
12
|
-
const state = useThree.getState();
|
|
13
|
-
const camera = state.camera;
|
|
14
|
-
const { gl, advance } = state;
|
|
15
|
-
syncCamera(camera, origin, projViewMx);
|
|
16
|
-
gl.resetState();
|
|
17
|
-
advance(Date.now() * 1e-3, true);
|
|
18
|
-
if (!frameloop || frameloop === "always")
|
|
19
|
-
map.triggerRepaint();
|
|
20
|
-
});
|
|
21
|
-
return render;
|
|
22
|
-
}
|
|
1
|
+
const earthRadius = 6378137;
|
|
23
2
|
export {
|
|
24
|
-
|
|
3
|
+
earthRadius
|
|
25
4
|
};
|
|
26
5
|
//# sourceMappingURL=main14.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main14.mjs","sources":["../../../src/core/
|
|
1
|
+
{"version":3,"file":"main14.mjs","sources":["../../../src/core/earth-radius.ts"],"sourcesContent":["export const earthRadius = 6378137;\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}
|
|
@@ -1,98 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
antialias: true,
|
|
22
|
-
...props == null ? void 0 : props.gl
|
|
23
|
-
},
|
|
24
|
-
onCreated: (state) => {
|
|
25
|
-
state.gl.forceContextLoss = () => {
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
camera: {
|
|
29
|
-
matrixAutoUpdate: false,
|
|
30
|
-
near: 0
|
|
31
|
-
},
|
|
32
|
-
size: {
|
|
33
|
-
width: canvas2.clientWidth,
|
|
34
|
-
height: canvas2.clientHeight,
|
|
35
|
-
top: canvas2.offsetTop,
|
|
36
|
-
left: canvas2.offsetLeft,
|
|
37
|
-
updateStyle: false,
|
|
38
|
-
...props == null ? void 0 : props.size
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const store = _roots.get(canvas2).store;
|
|
42
|
-
const r3m2 = initR3M({ map, fromLngLat, store });
|
|
1
|
+
import { useThree, _roots } from "@react-three/fiber";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
function useCoords() {
|
|
4
|
+
const coords = useThree((s) => s.coords);
|
|
5
|
+
return coords;
|
|
6
|
+
}
|
|
7
|
+
function useSetCoords({ longitude, latitude, altitude }) {
|
|
8
|
+
const canvas = useThree((s) => s.gl.domElement);
|
|
9
|
+
useMemo(() => {
|
|
10
|
+
const store = _roots.get(canvas).store;
|
|
11
|
+
const coords = { longitude, latitude, altitude };
|
|
12
|
+
setCoords(store, coords);
|
|
13
|
+
}, [longitude, latitude, altitude]);
|
|
14
|
+
}
|
|
15
|
+
function useSetRootCoords(store, {
|
|
16
|
+
longitude,
|
|
17
|
+
latitude,
|
|
18
|
+
altitude
|
|
19
|
+
}) {
|
|
20
|
+
useMemo(() => {
|
|
43
21
|
setCoords(store, { longitude, latitude, altitude });
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
map.triggerRepaint();
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return { root: root2, useThree: store, map, canvas: canvas2, r3m: r3m2 };
|
|
53
|
-
});
|
|
54
|
-
const onResize = useFunction(() => {
|
|
55
|
-
const { setDpr, setSize } = useThree.getState();
|
|
56
|
-
setDpr(window.devicePixelRatio);
|
|
57
|
-
setSize(
|
|
58
|
-
canvas.clientWidth,
|
|
59
|
-
canvas.clientHeight,
|
|
60
|
-
false,
|
|
61
|
-
canvas.offsetTop,
|
|
62
|
-
canvas.offsetLeft
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
const onRemove = useFunction(() => {
|
|
66
|
-
root.unmount();
|
|
67
|
-
});
|
|
68
|
-
useSetRootCoords(useThree, { longitude, latitude, altitude });
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (frameloop !== "demand")
|
|
71
|
-
return;
|
|
72
|
-
const setState = useThree.setState;
|
|
73
|
-
const { invalidate } = useThree.getState();
|
|
74
|
-
setState({
|
|
75
|
-
frameloop,
|
|
76
|
-
invalidate: () => {
|
|
77
|
-
map.triggerRepaint();
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return () => {
|
|
81
|
-
setState({ frameloop: "never", invalidate });
|
|
82
|
-
};
|
|
83
|
-
}, [frameloop]);
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
map.on("resize", onResize);
|
|
86
|
-
return () => {
|
|
87
|
-
map.off("resize", onResize);
|
|
88
|
-
};
|
|
89
|
-
}, []);
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
root.render(/* @__PURE__ */ jsx(Fragment, { children: props.children }));
|
|
92
|
-
}, [props.children]);
|
|
93
|
-
return { onRemove, useThree, r3m };
|
|
22
|
+
}, [longitude, latitude, altitude]);
|
|
23
|
+
}
|
|
24
|
+
function setCoords(store, coords) {
|
|
25
|
+
store.setState({ coords });
|
|
94
26
|
}
|
|
95
27
|
export {
|
|
96
|
-
|
|
28
|
+
setCoords,
|
|
29
|
+
useCoords,
|
|
30
|
+
useSetCoords,
|
|
31
|
+
useSetRootCoords
|
|
97
32
|
};
|
|
98
33
|
//# sourceMappingURL=main15.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main15.mjs","sources":["../../../src/core/
|
|
1
|
+
{"version":3,"file":"main15.mjs","sources":["../../../src/core/use-coords.tsx"],"sourcesContent":["import { RootState, _roots, useThree } from \"@react-three/fiber\";\nimport { useMemo } from \"react\";\nimport { UseBoundStore } from 'zustand';\nimport { Coords } from \"../api/coords\";\n\nexport function useCoords() {\n const coords = useThree(s=>(s as any).coords) as Coords; // eslint-disable-line @typescript-eslint/no-explicit-any\n return coords;\n}\n\nexport function useSetCoords({longitude, latitude, altitude}: Coords) {\n \n const canvas = useThree(s => s.gl.domElement);\n useMemo(()=>{\n const store = _roots.get(canvas)!.store; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n const coords : Coords = { longitude, latitude, altitude };\n setCoords(store, coords);\n }, [longitude, latitude, altitude]) // eslint-disable-line react-hooks/exhaustive-deps\n}\n\nexport function useSetRootCoords(store:UseBoundStore<RootState>, {\n longitude, latitude, altitude\n}: Coords) {\n useMemo(()=>{\n setCoords(store, {longitude, latitude, altitude});\n }, [longitude, latitude, altitude]) // eslint-disable-line react-hooks/exhaustive-deps\n}\n\nexport function setCoords(store:UseBoundStore<RootState>, coords: Coords) {\n store.setState({coords} as any) // eslint-disable-line @typescript-eslint/no-explicit-any\n}"],"names":[],"mappings":";;AAKO,SAAS,YAAY;AAC1B,QAAM,SAAS,SAAS,CAAI,MAAA,EAAU,MAAM;AACrC,SAAA;AACT;AAEO,SAAS,aAAa,EAAC,WAAW,UAAU,YAAmB;AAEpE,QAAM,SAAS,SAAS,CAAK,MAAA,EAAE,GAAG,UAAU;AAC5C,UAAQ,MAAI;AACV,UAAM,QAAQ,OAAO,IAAI,MAAM,EAAG;AAClC,UAAM,SAAkB,EAAE,WAAW,UAAU,SAAS;AACxD,cAAU,OAAO,MAAM;AAAA,EACtB,GAAA,CAAC,WAAW,UAAU,QAAQ,CAAC;AACpC;AAEO,SAAS,iBAAiB,OAAgC;AAAA,EAC/D;AAAA,EAAW;AAAA,EAAU;AACvB,GAAW;AACT,UAAQ,MAAI;AACV,cAAU,OAAO,EAAC,WAAW,UAAU,SAAS,CAAA;AAAA,EAC/C,GAAA,CAAC,WAAW,UAAU,QAAQ,CAAC;AACpC;AAEgB,SAAA,UAAU,OAAgC,QAAgB;AAClE,QAAA,SAAS,EAAC,OAAA,CAAc;AAChC;"}
|
|
@@ -1,66 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { events } from "./main18.mjs";
|
|
5
|
-
import { useFunction } from "./main9.mjs";
|
|
6
|
-
import { InitR3M } from "./main19.mjs";
|
|
7
|
-
import { SyncCameraFC } from "./main20.mjs";
|
|
8
|
-
const CanvasPortal = memo(({
|
|
9
|
-
children,
|
|
10
|
-
latitude,
|
|
11
|
-
longitude,
|
|
12
|
-
altitude,
|
|
13
|
-
setOnRender,
|
|
1
|
+
import { syncCamera } from "./main11.mjs";
|
|
2
|
+
import { useFunction } from "./main10.mjs";
|
|
3
|
+
function useRender({
|
|
14
4
|
map,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
origin,
|
|
6
|
+
useThree,
|
|
7
|
+
frameloop,
|
|
8
|
+
r3m
|
|
9
|
+
}) {
|
|
10
|
+
const render = useFunction((_gl, projViewMx) => {
|
|
11
|
+
r3m.viewProjMx.splice(0, 16, ...projViewMx);
|
|
12
|
+
const state = useThree.getState();
|
|
13
|
+
const camera = state.camera;
|
|
14
|
+
const { gl, advance } = state;
|
|
15
|
+
syncCamera(camera, origin, projViewMx);
|
|
16
|
+
gl.resetState();
|
|
17
|
+
advance(Date.now() * 1e-3, true);
|
|
18
|
+
if (!frameloop || frameloop === "always")
|
|
19
|
+
map.triggerRepaint();
|
|
23
20
|
});
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
camera: {
|
|
28
|
-
matrixAutoUpdate: false,
|
|
29
|
-
matrixWorldAutoUpdate: false
|
|
30
|
-
},
|
|
31
|
-
events,
|
|
32
|
-
eventSource,
|
|
33
|
-
...props,
|
|
34
|
-
gl: { autoClear: false, ...props.gl },
|
|
35
|
-
children: [
|
|
36
|
-
/* @__PURE__ */ jsx(
|
|
37
|
-
InitR3M,
|
|
38
|
-
{
|
|
39
|
-
map,
|
|
40
|
-
fromLngLat,
|
|
41
|
-
latitude,
|
|
42
|
-
longitude,
|
|
43
|
-
altitude
|
|
44
|
-
}
|
|
45
|
-
),
|
|
46
|
-
/* @__PURE__ */ jsx(
|
|
47
|
-
SyncCameraFC,
|
|
48
|
-
{
|
|
49
|
-
latitude,
|
|
50
|
-
longitude,
|
|
51
|
-
altitude,
|
|
52
|
-
setOnRender,
|
|
53
|
-
onReady,
|
|
54
|
-
mapCanvas
|
|
55
|
-
}
|
|
56
|
-
),
|
|
57
|
-
ready && children
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
CanvasPortal.displayName = "CanvasPortal";
|
|
21
|
+
return render;
|
|
22
|
+
}
|
|
63
23
|
export {
|
|
64
|
-
|
|
24
|
+
useRender
|
|
65
25
|
};
|
|
66
26
|
//# sourceMappingURL=main16.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main16.mjs","sources":["../../../src/core/canvas-
|
|
1
|
+
{"version":3,"file":"main16.mjs","sources":["../../../src/core/canvas-in-layer/use-render.ts"],"sourcesContent":["import { RootState } from \"@react-three/fiber\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { UseBoundStore } from \"zustand\";\nimport { MapInstance } from \"../generic-map\";\nimport { syncCamera } from \"../sync-camera\";\nimport { useFunction } from \"../use-function\";\nimport { R3M } from \"../use-r3m\";\n\nexport function useRender({\n map, origin, useThree, frameloop, r3m,\n} :{\n map: MapInstance,\n origin: Matrix4Tuple,\n useThree: UseBoundStore<RootState>,\n frameloop?: 'always' | 'demand',\n r3m: R3M\n}) {\n const render = useFunction((_gl: WebGL2RenderingContext, projViewMx: number[]) => {\n r3m.viewProjMx.splice(0, 16, ...projViewMx)\n const state = useThree.getState();\n const camera = state.camera as PerspectiveCamera;\n const {gl, advance} = state;\n syncCamera(camera as PerspectiveCamera, origin, projViewMx as Matrix4Tuple);\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (!frameloop || frameloop === 'always') map.triggerRepaint();\n })\n return render;\n}"],"names":[],"mappings":";;AAQO,SAAS,UAAU;AAAA,EACxB;AAAA,EAAK;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAW;AACpC,GAMG;AACD,QAAM,SAAS,YAAY,CAAC,KAA6B,eAAyB;AAChF,QAAI,WAAW,OAAO,GAAG,IAAI,GAAG,UAAU;AACpC,UAAA,QAAQ,SAAS;AACvB,UAAM,SAAS,MAAM;AACf,UAAA,EAAC,IAAI,QAAW,IAAA;AACX,eAAA,QAA6B,QAAQ,UAA0B;AAC1E,OAAG,WAAW;AACd,YAAQ,KAAK,IAAQ,IAAA,MAAO,IAAI;AAC5B,QAAA,CAAC,aAAa,cAAc;AAAU,UAAI,eAAe;AAAA,EAAA,CAC9D;AACM,SAAA;AACT;"}
|
|
@@ -1,23 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createRoot, _roots } from "@react-three/fiber";
|
|
3
|
+
import { useState, useEffect } from "react";
|
|
4
|
+
import { events } from "./main20.mjs";
|
|
5
|
+
import { setCoords, useSetRootCoords } from "./main15.mjs";
|
|
6
|
+
import { useFunction } from "./main10.mjs";
|
|
7
|
+
import { initR3M } from "./main13.mjs";
|
|
8
|
+
function useRoot(fromLngLat, map, { frameloop, longitude, latitude, altitude, ...props }) {
|
|
9
|
+
const [{ root, useThree, canvas, r3m }] = useState(() => {
|
|
10
|
+
const canvas2 = map.getCanvas();
|
|
11
|
+
const gl = canvas2.getContext("webgl2") || canvas2.getContext("webgl");
|
|
12
|
+
const root2 = createRoot(canvas2);
|
|
13
|
+
root2.configure({
|
|
14
|
+
dpr: window.devicePixelRatio,
|
|
15
|
+
events,
|
|
16
|
+
...props,
|
|
17
|
+
frameloop: "never",
|
|
18
|
+
gl: {
|
|
19
|
+
context: gl,
|
|
20
|
+
autoClear: false,
|
|
21
|
+
antialias: true,
|
|
22
|
+
...props == null ? void 0 : props.gl
|
|
23
|
+
},
|
|
24
|
+
onCreated: (state) => {
|
|
25
|
+
state.gl.forceContextLoss = () => {
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
camera: {
|
|
29
|
+
matrixAutoUpdate: false,
|
|
30
|
+
near: 0
|
|
31
|
+
},
|
|
32
|
+
size: {
|
|
33
|
+
width: canvas2.clientWidth,
|
|
34
|
+
height: canvas2.clientHeight,
|
|
35
|
+
top: canvas2.offsetTop,
|
|
36
|
+
left: canvas2.offsetLeft,
|
|
37
|
+
updateStyle: false,
|
|
38
|
+
...props == null ? void 0 : props.size
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const store = _roots.get(canvas2).store;
|
|
42
|
+
const r3m2 = initR3M({ map, fromLngLat, store });
|
|
43
|
+
setCoords(store, { longitude, latitude, altitude });
|
|
44
|
+
if (frameloop === "demand") {
|
|
45
|
+
store.setState({
|
|
46
|
+
frameloop,
|
|
47
|
+
invalidate: () => {
|
|
48
|
+
map.triggerRepaint();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return { root: root2, useThree: store, map, canvas: canvas2, r3m: r3m2 };
|
|
53
|
+
});
|
|
54
|
+
const onResize = useFunction(() => {
|
|
55
|
+
const { setDpr, setSize } = useThree.getState();
|
|
56
|
+
setDpr(window.devicePixelRatio);
|
|
57
|
+
setSize(
|
|
58
|
+
canvas.clientWidth,
|
|
59
|
+
canvas.clientHeight,
|
|
60
|
+
false,
|
|
61
|
+
canvas.offsetTop,
|
|
62
|
+
canvas.offsetLeft
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
const onRemove = useFunction(() => {
|
|
66
|
+
root.unmount();
|
|
67
|
+
});
|
|
68
|
+
useSetRootCoords(useThree, { longitude, latitude, altitude });
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (frameloop !== "demand")
|
|
71
|
+
return;
|
|
72
|
+
const setState = useThree.setState;
|
|
73
|
+
const { invalidate } = useThree.getState();
|
|
74
|
+
setState({
|
|
75
|
+
frameloop,
|
|
76
|
+
invalidate: () => {
|
|
77
|
+
map.triggerRepaint();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return () => {
|
|
81
|
+
setState({ frameloop: "never", invalidate });
|
|
82
|
+
};
|
|
83
|
+
}, [frameloop]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
map.on("resize", onResize);
|
|
86
|
+
return () => {
|
|
87
|
+
map.off("resize", onResize);
|
|
88
|
+
};
|
|
89
|
+
}, []);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
root.render(/* @__PURE__ */ jsx(Fragment, { children: props.children }));
|
|
92
|
+
}, [props.children]);
|
|
93
|
+
return { onRemove, useThree, r3m };
|
|
19
94
|
}
|
|
20
95
|
export {
|
|
21
|
-
|
|
96
|
+
useRoot
|
|
22
97
|
};
|
|
23
98
|
//# sourceMappingURL=main17.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main17.mjs","sources":["../../../src/core/
|
|
1
|
+
{"version":3,"file":"main17.mjs","sources":["../../../src/core/canvas-in-layer/use-root.tsx"],"sourcesContent":["import { _roots, createRoot } from \"@react-three/fiber\";\nimport { useEffect, useState } from \"react\";\nimport { CanvasProps } from \"../../api/canvas-props\";\nimport { events } from \"../events\";\nimport { FromLngLat, MapInstance } from \"../generic-map\";\nimport { setCoords, useSetRootCoords } from \"../use-coords\";\nimport { useFunction } from \"../use-function\";\nimport { initR3M } from \"../use-r3m\";\n\nexport function useRoot(\n fromLngLat: FromLngLat,\n map: MapInstance,\n { frameloop, longitude, latitude, altitude, ...props }: CanvasProps\n) {\n\n const [{ root, useThree, canvas, r3m }] = useState(() => {\n const canvas = map.getCanvas();\n const gl = (canvas.getContext('webgl2') || canvas.getContext('webgl')) as WebGLRenderingContext;\n\n const root = createRoot(canvas);\n root.configure({\n dpr: window.devicePixelRatio,\n events,\n ...props,\n frameloop: 'never',\n gl: {\n context: gl,\n autoClear: false,\n antialias: true,\n ...props?.gl,\n },\n onCreated: (state) => {\n state.gl.forceContextLoss = () => { }; // eslint-disable-line @typescript-eslint/no-empty-function\n },\n camera: {\n matrixAutoUpdate: false,\n near: 0,\n },\n size: {\n width: canvas.clientWidth,\n height: canvas.clientHeight,\n top: canvas.offsetTop,\n left: canvas.offsetLeft,\n updateStyle: false,\n ...props?.size,\n },\n });\n\n const store = _roots.get(canvas)!.store; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n\n const r3m = initR3M({ map, fromLngLat, store });\n setCoords(store, {longitude, latitude, altitude});\n\n if (frameloop === 'demand') {\n store.setState({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n },\n })\n }\n\n return { root, useThree: store, map, canvas, r3m }\n\n })\n\n const onResize = useFunction(() => {\n\n const { setDpr, setSize } = useThree.getState();\n\n setDpr(window.devicePixelRatio);\n\n setSize(\n canvas.clientWidth,\n canvas.clientHeight,\n false,\n canvas.offsetTop,\n canvas.offsetLeft,\n );\n\n })\n\n const onRemove = useFunction(() => {\n root.unmount();\n })\n\n useSetRootCoords(useThree, {longitude, latitude, altitude});\n\n // on `frameloop` change\n useEffect(() => {\n if (frameloop !== 'demand') return;\n const setState = useThree.setState;\n const { invalidate } = useThree.getState();\n setState({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n }\n });\n return () => {\n setState({ frameloop: 'never', invalidate })\n }\n }, [frameloop]) // eslint-disable-line react-hooks/exhaustive-deps\n\n // on mount / unmount\n useEffect(() => {\n map.on('resize', onResize);\n return () => {\n map.off('resize', onResize)\n }\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n // root.render\n useEffect(() => {\n root.render(<>\n {props.children}\n </>);\n }, [props.children]) // eslint-disable-line react-hooks/exhaustive-deps\n\n return { onRemove, useThree, r3m };\n}"],"names":["canvas","root","r3m"],"mappings":";;;;;;;AASgB,SAAA,QACd,YACA,KACA,EAAE,WAAW,WAAW,UAAU,UAAU,GAAG,SAC/C;AAEM,QAAA,CAAC,EAAE,MAAM,UAAU,QAAQ,IAAK,CAAA,IAAI,SAAS,MAAM;AACjDA,UAAAA,UAAS,IAAI;AACnB,UAAM,KAAMA,QAAO,WAAW,QAAQ,KAAKA,QAAO,WAAW,OAAO;AAE9DC,UAAAA,QAAO,WAAWD,OAAM;AAC9BC,UAAK,UAAU;AAAA,MACb,KAAK,OAAO;AAAA,MACZ;AAAA,MACA,GAAG;AAAA,MACH,WAAW;AAAA,MACX,IAAI;AAAA,QACF,SAAS;AAAA,QACT,WAAW;AAAA,QACX,WAAW;AAAA,QACX,GAAG,+BAAO;AAAA,MACZ;AAAA,MACA,WAAW,CAAC,UAAU;AACd,cAAA,GAAG,mBAAmB,MAAM;AAAA,QAAA;AAAA,MACpC;AAAA,MACA,QAAQ;AAAA,QACN,kBAAkB;AAAA,QAClB,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,QACJ,OAAOD,QAAO;AAAA,QACd,QAAQA,QAAO;AAAA,QACf,KAAKA,QAAO;AAAA,QACZ,MAAMA,QAAO;AAAA,QACb,aAAa;AAAA,QACb,GAAG,+BAAO;AAAA,MACZ;AAAA,IAAA,CACD;AAED,UAAM,QAAQ,OAAO,IAAIA,OAAM,EAAG;AAElC,UAAME,OAAM,QAAQ,EAAE,KAAK,YAAY,OAAO;AAC9C,cAAU,OAAO,EAAC,WAAW,UAAU,SAAS,CAAA;AAEhD,QAAI,cAAc,UAAU;AAC1B,YAAM,SAAS;AAAA,QACb;AAAA,QACA,YAAY,MAAM;AAChB,cAAI,eAAe;AAAA,QACrB;AAAA,MAAA,CACD;AAAA,IACH;AAEO,WAAA,EAAE,MAAAD,OAAM,UAAU,OAAO,KAAK,QAAAD,SAAQ,KAAAE;EAAI,CAElD;AAEK,QAAA,WAAW,YAAY,MAAM;AAEjC,UAAM,EAAE,QAAQ,QAAQ,IAAI,SAAS,SAAS;AAE9C,WAAO,OAAO,gBAAgB;AAE9B;AAAA,MACE,OAAO;AAAA,MACP,OAAO;AAAA,MACP;AAAA,MACA,OAAO;AAAA,MACP,OAAO;AAAA,IAAA;AAAA,EACT,CAED;AAEK,QAAA,WAAW,YAAY,MAAM;AACjC,SAAK,QAAQ;AAAA,EAAA,CACd;AAED,mBAAiB,UAAU,EAAC,WAAW,UAAU,SAAS,CAAA;AAG1D,YAAU,MAAM;AACd,QAAI,cAAc;AAAU;AAC5B,UAAM,WAAW,SAAS;AAC1B,UAAM,EAAE,WAAA,IAAe,SAAS,SAAS;AAChC,aAAA;AAAA,MACP;AAAA,MACA,YAAY,MAAM;AAChB,YAAI,eAAe;AAAA,MACrB;AAAA,IAAA,CACD;AACD,WAAO,MAAM;AACX,eAAS,EAAE,WAAW,SAAS,WAAY,CAAA;AAAA,IAAA;AAAA,EAC7C,GACC,CAAC,SAAS,CAAC;AAGd,YAAU,MAAM;AACV,QAAA,GAAG,UAAU,QAAQ;AACzB,WAAO,MAAM;AACP,UAAA,IAAI,UAAU,QAAQ;AAAA,IAAA;AAAA,EAE9B,GAAG,CAAE,CAAA;AAGL,YAAU,MAAM;AACd,SAAK,OAAO,oBAAA,UAAA,EACT,UAAM,MAAA,SACT,CAAA,CAAG;AAAA,EAAA,GACF,CAAC,MAAM,QAAQ,CAAC;AAEZ,SAAA,EAAE,UAAU,UAAU;AAC/B;"}
|