react-three-map 0.4.0 → 0.4.2
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 +12 -0
- package/README.md +2 -2
- package/dist/cjs/main.js +327 -1
- package/dist/es/main.mjs +4 -4
- package/dist/es/main10.mjs +14 -6
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +48 -34
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main12.mjs +8 -5
- package/dist/es/main12.mjs.map +1 -1
- package/dist/es/main13.mjs +54 -37
- package/dist/es/main13.mjs.map +1 -1
- package/dist/es/main2.mjs +18 -17
- package/dist/es/main2.mjs.map +1 -1
- package/dist/es/main3.mjs +46 -32
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main4.mjs +20 -18
- package/dist/es/main4.mjs.map +1 -1
- package/dist/es/main5.mjs +3 -3
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +33 -5
- package/dist/es/main6.mjs.map +1 -1
- package/dist/es/main7.mjs +11 -10
- package/dist/es/main7.mjs.map +1 -1
- package/dist/es/main8.mjs +19 -13
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +17 -9
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +327 -1
- package/dist/maplibre/es/main.mjs +4 -4
- package/dist/maplibre/es/main10.mjs +19 -6
- package/dist/maplibre/es/main10.mjs.map +1 -1
- package/dist/maplibre/es/main11.mjs +48 -34
- package/dist/maplibre/es/main11.mjs.map +1 -1
- package/dist/maplibre/es/main12.mjs +8 -5
- package/dist/maplibre/es/main12.mjs.map +1 -1
- package/dist/maplibre/es/main13.mjs +54 -37
- package/dist/maplibre/es/main13.mjs.map +1 -1
- package/dist/maplibre/es/main2.mjs +18 -17
- package/dist/maplibre/es/main2.mjs.map +1 -1
- package/dist/maplibre/es/main3.mjs +46 -32
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +20 -18
- package/dist/maplibre/es/main4.mjs.map +1 -1
- package/dist/maplibre/es/main5.mjs +3 -3
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/es/main6.mjs +33 -5
- package/dist/maplibre/es/main6.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +11 -10
- package/dist/maplibre/es/main7.mjs.map +1 -1
- package/dist/maplibre/es/main8.mjs +15 -15
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/es/main9.mjs +20 -11
- package/dist/maplibre/es/main9.mjs.map +1 -1
- package/package.json +1 -1
- package/stories/package.json +1 -1
- package/stories/yarn.lock +4 -4
package/dist/es/main13.mjs
CHANGED
|
@@ -1,56 +1,73 @@
|
|
|
1
|
-
import { createEvents as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { createEvents as createEvents$1 } from "@react-three/fiber";
|
|
2
|
+
import { Matrix4 } from "three";
|
|
3
|
+
const DOM_EVENTS = {
|
|
4
|
+
onClick: ["click", false],
|
|
5
|
+
onContextMenu: ["contextmenu", false],
|
|
6
|
+
onDoubleClick: ["dblclick", false],
|
|
7
|
+
onWheel: ["wheel", true],
|
|
8
|
+
onPointerDown: ["pointerdown", true],
|
|
9
|
+
onPointerUp: ["pointerup", true],
|
|
10
|
+
onPointerLeave: ["pointerleave", true],
|
|
11
|
+
onPointerMove: ["pointermove", true],
|
|
12
|
+
onPointerCancel: ["pointercancel", true],
|
|
13
|
+
onLostPointerCapture: ["lostpointercapture", true]
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const projByViewInv = new Matrix4();
|
|
16
|
+
function createEvents() {
|
|
17
|
+
return (store) => {
|
|
18
|
+
const { handlePointer } = createEvents$1(store);
|
|
17
19
|
return {
|
|
18
20
|
priority: 1,
|
|
19
|
-
enabled:
|
|
20
|
-
compute(
|
|
21
|
-
|
|
21
|
+
enabled: true,
|
|
22
|
+
compute(event, state) {
|
|
23
|
+
state.size.width = state.gl.domElement.width / window.devicePixelRatio;
|
|
24
|
+
state.size.height = state.gl.domElement.height / window.devicePixelRatio;
|
|
25
|
+
state.pointer.x = event.offsetX / state.size.width * 2 - 1;
|
|
26
|
+
state.pointer.y = 1 - event.offsetY / state.size.height * 2;
|
|
27
|
+
if (state.camera.userData.projByViewInv)
|
|
28
|
+
projByViewInv.fromArray(state.camera.userData.projByViewInv);
|
|
29
|
+
state.raycaster.camera = state.camera;
|
|
30
|
+
state.raycaster.ray.origin.setScalar(0).applyMatrix4(projByViewInv);
|
|
31
|
+
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(projByViewInv).sub(state.raycaster.ray.origin).normalize();
|
|
22
32
|
},
|
|
23
33
|
connected: void 0,
|
|
24
|
-
handlers: Object.keys(
|
|
25
|
-
(
|
|
34
|
+
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
35
|
+
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
26
36
|
{}
|
|
27
37
|
),
|
|
28
38
|
update: () => {
|
|
29
|
-
var
|
|
30
|
-
const { events
|
|
31
|
-
(
|
|
39
|
+
var _a;
|
|
40
|
+
const { events, internal } = store.getState();
|
|
41
|
+
if (((_a = internal.lastEvent) == null ? void 0 : _a.current) && events.handlers) {
|
|
42
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
43
|
+
}
|
|
32
44
|
},
|
|
33
|
-
connect: (
|
|
34
|
-
var
|
|
35
|
-
const { set
|
|
36
|
-
(
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
connect: (target) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const { set, events } = store.getState();
|
|
48
|
+
(_a = events.disconnect) == null ? void 0 : _a.call(events);
|
|
49
|
+
set((state) => ({ events: { ...state.events, connected: target.parentNode } }));
|
|
50
|
+
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
51
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
52
|
+
target.addEventListener(eventName, event, { passive });
|
|
39
53
|
});
|
|
40
54
|
},
|
|
41
55
|
disconnect: () => {
|
|
42
|
-
const { set
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
const { set, events } = store.getState();
|
|
57
|
+
if (events.connected) {
|
|
58
|
+
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
59
|
+
if (events && events.connected instanceof HTMLElement) {
|
|
60
|
+
const [eventName] = DOM_EVENTS[name];
|
|
61
|
+
events.connected.removeEventListener(eventName, event);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
65
|
+
}
|
|
49
66
|
}
|
|
50
67
|
};
|
|
51
68
|
};
|
|
52
69
|
}
|
|
53
70
|
export {
|
|
54
|
-
|
|
71
|
+
createEvents
|
|
55
72
|
};
|
|
56
73
|
//# sourceMappingURL=main13.mjs.map
|
package/dist/es/main13.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main13.mjs","sources":["../../src/core/create-events.ts"],"sourcesContent":["import { Events, RenderProps, RootState, createEvents as createFiberEvents } from \"@react-three/fiber\";\nimport { UseBoundStore } from \"zustand\";\n\ntype DomEvent = PointerEvent | MouseEvent | WheelEvent;\n\nconst DOM_EVENTS = {\n onClick: [\"click\", false],\n onContextMenu: [\"contextmenu\", false],\n onDoubleClick: [\"dblclick\", false],\n onWheel: [\"wheel\", true],\n onPointerDown: [\"pointerdown\", true],\n onPointerUp: [\"pointerup\", true],\n onPointerLeave: [\"pointerleave\", true],\n onPointerMove: [\"pointermove\", true],\n onPointerCancel: [\"pointercancel\", true],\n onLostPointerCapture: [\"lostpointercapture\", true],\n} as const;\n\n/** ThreeLayer event manager for MapLibre and Mapbox */\nexport function createEvents(): RenderProps<HTMLCanvasElement>[\"events\"] {\n return (store: UseBoundStore<RootState>) => {\n const { handlePointer } = createFiberEvents(store);\n return {\n priority: 1,\n enabled: true,\n compute(event: DomEvent, state: RootState) {\n state.size.width = state.gl.domElement.width / window.devicePixelRatio;\n state.size.height = state.gl.domElement.height / window.devicePixelRatio;\n state.pointer.x = (event.offsetX / state.size.width) * 2 - 1;\n state.pointer.y = 1 - (event.offsetY / state.size.height) * 2;\n state.raycaster.camera = state.camera;\n state.raycaster.ray.origin.setScalar(0).applyMatrix4(
|
|
1
|
+
{"version":3,"file":"main13.mjs","sources":["../../src/core/create-events.ts"],"sourcesContent":["import { Events, RenderProps, RootState, createEvents as createFiberEvents } from \"@react-three/fiber\";\nimport { Matrix4 } from \"three\";\nimport { UseBoundStore } from \"zustand\";\n\ntype DomEvent = PointerEvent | MouseEvent | WheelEvent;\n\nconst DOM_EVENTS = {\n onClick: [\"click\", false],\n onContextMenu: [\"contextmenu\", false],\n onDoubleClick: [\"dblclick\", false],\n onWheel: [\"wheel\", true],\n onPointerDown: [\"pointerdown\", true],\n onPointerUp: [\"pointerup\", true],\n onPointerLeave: [\"pointerleave\", true],\n onPointerMove: [\"pointermove\", true],\n onPointerCancel: [\"pointercancel\", true],\n onLostPointerCapture: [\"lostpointercapture\", true],\n} as const;\n\nconst projByViewInv = new Matrix4()\n\n/** ThreeLayer event manager for MapLibre and Mapbox */\nexport function createEvents(): RenderProps<HTMLCanvasElement>[\"events\"] {\n return (store: UseBoundStore<RootState>) => {\n const { handlePointer } = createFiberEvents(store);\n\n return {\n priority: 1,\n enabled: true,\n compute(event: DomEvent, state: RootState) {\n state.size.width = state.gl.domElement.width / window.devicePixelRatio;\n state.size.height = state.gl.domElement.height / window.devicePixelRatio;\n state.pointer.x = (event.offsetX / state.size.width) * 2 - 1;\n state.pointer.y = 1 - (event.offsetY / state.size.height) * 2;\n\n if(state.camera.userData.projByViewInv) projByViewInv.fromArray(state.camera.userData.projByViewInv);\n\n state.raycaster.camera = state.camera;\n state.raycaster.ray.origin.setScalar(0).applyMatrix4(projByViewInv);\n state.raycaster.ray.direction\n .set(state.pointer.x, state.pointer.y, 1)\n .applyMatrix4(projByViewInv)\n .sub(state.raycaster.ray.origin)\n .normalize();\n },\n connected: undefined,\n handlers: Object.keys(DOM_EVENTS).reduce(\n (acc, key) => ({ ...acc, [key]: handlePointer(key) }),\n {}\n ) as unknown as Events,\n update: () => {\n const { events, internal } = store.getState();\n if (internal.lastEvent?.current && events.handlers) {\n events.handlers.onPointerMove(internal.lastEvent.current);\n }\n },\n connect: (target: HTMLElement) => {\n const { set, events } = store.getState();\n events.disconnect?.();\n set((state) => ({ events: { ...state.events, connected: target.parentNode } }));\n Object.entries(events.handlers ?? []).forEach(([name, event]) => {\n const [eventName, passive] = DOM_EVENTS[name as keyof typeof DOM_EVENTS];\n target.addEventListener(eventName, event, { passive });\n });\n },\n disconnect: () => {\n const { set, events } = store.getState();\n if (events.connected) {\n Object.entries(events.handlers ?? []).forEach(([name, event]) => {\n if (events && events.connected instanceof HTMLElement) {\n const [eventName] = DOM_EVENTS[name as keyof typeof DOM_EVENTS];\n events.connected.removeEventListener(eventName, event);\n }\n });\n set((state) => ({ events: { ...state.events, connected: undefined } }));\n }\n },\n };\n };\n}\n"],"names":["createFiberEvents"],"mappings":"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"}
|
package/dist/es/main2.mjs
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import { extend
|
|
3
|
-
import { MercatorCoordinate
|
|
4
|
-
import { memo
|
|
5
|
-
import { Layer
|
|
6
|
-
import * as
|
|
7
|
-
import { useCanvas
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { extend } from "@react-three/fiber";
|
|
3
|
+
import { MercatorCoordinate } from "mapbox-gl";
|
|
4
|
+
import { memo } from "react";
|
|
5
|
+
import { Layer } from "react-map-gl";
|
|
6
|
+
import * as THREE from "three";
|
|
7
|
+
import { useCanvas } from "./main4.mjs";
|
|
8
|
+
extend(THREE);
|
|
9
|
+
const fromLngLat = MercatorCoordinate.fromLngLat;
|
|
10
|
+
const Canvas = memo((props) => {
|
|
11
|
+
const { id, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });
|
|
12
|
+
return /* @__PURE__ */ jsx(
|
|
13
|
+
Layer,
|
|
13
14
|
{
|
|
14
|
-
id
|
|
15
|
+
id,
|
|
15
16
|
type: "custom",
|
|
16
17
|
renderingMode: "3d",
|
|
17
|
-
onAdd
|
|
18
|
-
onRemove
|
|
19
|
-
render
|
|
18
|
+
onAdd,
|
|
19
|
+
onRemove,
|
|
20
|
+
render
|
|
20
21
|
}
|
|
21
22
|
);
|
|
22
23
|
});
|
|
23
24
|
export {
|
|
24
|
-
|
|
25
|
+
Canvas
|
|
25
26
|
};
|
|
26
27
|
//# sourceMappingURL=main2.mjs.map
|
package/dist/es/main2.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main2.mjs","sources":["../../src/mapbox/canvas.tsx"],"sourcesContent":["import { extend } from \"@react-three/fiber\";\nimport { MercatorCoordinate } from \"mapbox-gl\";\nimport { memo } from \"react\";\nimport { Layer } from \"react-map-gl\";\nimport * as THREE from \"three\";\nimport { CanvasProps } from \"../api/canvas-props\";\nimport { useCanvas } from \"../core/use-canvas\";\n\nextend(THREE);\n\nconst fromLngLat = MercatorCoordinate.fromLngLat\n\n/** react`-three-fiber` canvas inside `Mapbox` */\nexport const Canvas = memo<CanvasProps>((props) => {\n\n const { id, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });\n\n return <Layer\n id={id}\n type=\"custom\"\n renderingMode=\"3d\"\n onAdd={onAdd}\n onRemove={onRemove}\n render={render}\n />\n})"],"names":[
|
|
1
|
+
{"version":3,"file":"main2.mjs","sources":["../../src/mapbox/canvas.tsx"],"sourcesContent":["import { extend } from \"@react-three/fiber\";\nimport { MercatorCoordinate } from \"mapbox-gl\";\nimport { memo } from \"react\";\nimport { Layer } from \"react-map-gl\";\nimport * as THREE from \"three\";\nimport { CanvasProps } from \"../api/canvas-props\";\nimport { useCanvas } from \"../core/use-canvas\";\n\nextend(THREE);\n\nconst fromLngLat = MercatorCoordinate.fromLngLat\n\n/** react`-three-fiber` canvas inside `Mapbox` */\nexport const Canvas = memo<CanvasProps>((props) => {\n\n const { id, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });\n\n return <Layer\n id={id}\n type=\"custom\"\n renderingMode=\"3d\"\n onAdd={onAdd}\n onRemove={onRemove}\n render={render}\n />\n})"],"names":[],"mappings":";;;;;;;AAQA,OAAO,KAAK;AAEZ,MAAM,aAAa,mBAAmB;AAGzB,MAAA,SAAS,KAAkB,CAAC,UAAU;AAE3C,QAAA,EAAE,IAAI,OAAO,UAAU,OAAA,IAAW,UAAU,EAAE,GAAG,OAAO,WAAA,CAAY;AAEnE,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACN;AAAA,MACA,MAAK;AAAA,MACL,eAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAAA;AAEJ,CAAC;"}
|
package/dist/es/main3.mjs
CHANGED
|
@@ -1,42 +1,56 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import { createPortal
|
|
3
|
-
import { memo
|
|
4
|
-
import { Scene
|
|
5
|
-
import { useR3M
|
|
6
|
-
import { syncCamera
|
|
7
|
-
import { useCoords
|
|
8
|
-
const
|
|
9
|
-
latitude
|
|
10
|
-
longitude
|
|
11
|
-
altitude
|
|
12
|
-
children
|
|
1
|
+
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createPortal, useThree, useFrame } from "@react-three/fiber";
|
|
3
|
+
import { memo, useState, useRef, useLayoutEffect } from "react";
|
|
4
|
+
import { Scene } from "three";
|
|
5
|
+
import { useR3M } from "./main5.mjs";
|
|
6
|
+
import { syncCamera } from "./main6.mjs";
|
|
7
|
+
import { useCoords } from "./main7.mjs";
|
|
8
|
+
const Coordinates = memo(({
|
|
9
|
+
latitude,
|
|
10
|
+
longitude,
|
|
11
|
+
altitude = 0,
|
|
12
|
+
children
|
|
13
13
|
}) => {
|
|
14
|
-
const [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const [scene] = useState(() => new Scene());
|
|
15
|
+
const r3m = useR3M();
|
|
16
|
+
const origin = useCoords({
|
|
17
|
+
latitude,
|
|
18
|
+
longitude,
|
|
19
|
+
altitude,
|
|
20
|
+
fromLngLat: r3m.fromLngLat
|
|
19
21
|
});
|
|
20
|
-
return /* @__PURE__ */
|
|
21
|
-
/* @__PURE__ */
|
|
22
|
-
|
|
23
|
-
] }),
|
|
22
|
+
return /* @__PURE__ */ jsx(Fragment, { children: createPortal(/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
23
|
+
/* @__PURE__ */ jsx(RenderAtCoords, { r3m, origin }),
|
|
24
|
+
children
|
|
25
|
+
] }), scene, { events: { priority: 2 } }) });
|
|
24
26
|
});
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
const { gl
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
Coordinates.displayName = "Coordinates";
|
|
28
|
+
function RenderAtCoords({ r3m, origin }) {
|
|
29
|
+
const { gl, scene, set } = useThree();
|
|
30
|
+
const cameraRef = useRef(null);
|
|
31
|
+
useFrame(() => {
|
|
32
|
+
if (!r3m.mapCamMx)
|
|
33
|
+
return;
|
|
34
|
+
if (!cameraRef.current)
|
|
35
|
+
return;
|
|
36
|
+
syncCamera(cameraRef.current, origin, r3m.mapCamMx);
|
|
37
|
+
gl.render(scene, cameraRef.current);
|
|
38
|
+
});
|
|
39
|
+
useLayoutEffect(() => {
|
|
40
|
+
if (!cameraRef.current)
|
|
41
|
+
return;
|
|
42
|
+
set({
|
|
32
43
|
invalidate: () => {
|
|
33
|
-
|
|
44
|
+
if (!r3m.map)
|
|
45
|
+
return;
|
|
46
|
+
r3m.map.triggerRepaint();
|
|
34
47
|
},
|
|
35
|
-
camera:
|
|
48
|
+
camera: cameraRef.current
|
|
36
49
|
});
|
|
37
|
-
}, [
|
|
50
|
+
}, [set, r3m]);
|
|
51
|
+
return /* @__PURE__ */ jsx("perspectiveCamera", { ref: cameraRef });
|
|
38
52
|
}
|
|
39
53
|
export {
|
|
40
|
-
|
|
54
|
+
Coordinates
|
|
41
55
|
};
|
|
42
56
|
//# sourceMappingURL=main3.mjs.map
|
package/dist/es/main3.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main3.mjs","sources":["../../src/api/coordinates.tsx"],"sourcesContent":["import { createPortal, useFrame, useThree } from \"@react-three/fiber\";\nimport { PropsWithChildren, memo, useLayoutEffect, useRef, useState } from \"react\";\nimport { Matrix4Tuple, PerspectiveCamera, Scene } from \"three\";\nimport { R3mStore, useR3M } from \"../core/store\";\nimport { syncCamera } from \"../core/sync-camera\";\nimport { useCoords } from \"../core/use-coords\";\n\nexport interface CoordinatesProps extends PropsWithChildren {\n longitude: number,\n latitude: number,\n altitude?: number,\n}\n\nexport const Coordinates = memo<CoordinatesProps>(({\n latitude, longitude, altitude = 0, children\n}) => {\n\n const [scene] = useState(() => new Scene())\n\n const r3m = useR3M();\n\n const origin = useCoords({\n latitude, longitude, altitude, fromLngLat: r3m.fromLngLat,\n });\n\n\n return <>{createPortal(<>\n <RenderAtCoords r3m={r3m} origin={origin} />\n {children}\n </>, scene, { events: { priority: 2 } })}</>\n})\n\nCoordinates.displayName = 'Coordinates';\n\ninterface RenderAtCoordsProps {\n r3m: R3mStore,\n origin: Matrix4Tuple\n}\n\nfunction RenderAtCoords({ r3m, origin }: RenderAtCoordsProps) {\n\n const { gl, scene, set } = useThree()\n\n const cameraRef = useRef<PerspectiveCamera>(null)\n\n useFrame(() => {\n if (!r3m.mapCamMx) return;\n if (!cameraRef.current) return;\n syncCamera(cameraRef.current, origin, r3m.mapCamMx);\n gl.render(scene, cameraRef.current);\n })\n\n useLayoutEffect(() => {\n if (!cameraRef.current) return;\n set({\n invalidate: () => {\n if (!r3m.map) return;\n r3m.map.triggerRepaint();\n },\n camera: cameraRef.current,\n });\n }, [set, r3m])\n\n return <perspectiveCamera ref={cameraRef} />\n}"],"names":[
|
|
1
|
+
{"version":3,"file":"main3.mjs","sources":["../../src/api/coordinates.tsx"],"sourcesContent":["import { createPortal, useFrame, useThree } from \"@react-three/fiber\";\nimport { PropsWithChildren, memo, useLayoutEffect, useRef, useState } from \"react\";\nimport { Matrix4Tuple, PerspectiveCamera, Scene } from \"three\";\nimport { R3mStore, useR3M } from \"../core/store\";\nimport { syncCamera } from \"../core/sync-camera\";\nimport { useCoords } from \"../core/use-coords\";\n\nexport interface CoordinatesProps extends PropsWithChildren {\n longitude: number,\n latitude: number,\n altitude?: number,\n}\n\nexport const Coordinates = memo<CoordinatesProps>(({\n latitude, longitude, altitude = 0, children\n}) => {\n\n const [scene] = useState(() => new Scene())\n\n const r3m = useR3M();\n\n const origin = useCoords({\n latitude, longitude, altitude, fromLngLat: r3m.fromLngLat,\n });\n\n\n return <>{createPortal(<>\n <RenderAtCoords r3m={r3m} origin={origin} />\n {children}\n </>, scene, { events: { priority: 2 } })}</>\n})\n\nCoordinates.displayName = 'Coordinates';\n\ninterface RenderAtCoordsProps {\n r3m: R3mStore,\n origin: Matrix4Tuple\n}\n\nfunction RenderAtCoords({ r3m, origin }: RenderAtCoordsProps) {\n\n const { gl, scene, set } = useThree()\n\n const cameraRef = useRef<PerspectiveCamera>(null)\n\n useFrame(() => {\n if (!r3m.mapCamMx) return;\n if (!cameraRef.current) return;\n syncCamera(cameraRef.current, origin, r3m.mapCamMx);\n gl.render(scene, cameraRef.current);\n })\n\n useLayoutEffect(() => {\n if (!cameraRef.current) return;\n set({\n invalidate: () => {\n if (!r3m.map) return;\n r3m.map.triggerRepaint();\n },\n camera: cameraRef.current,\n });\n }, [set, r3m])\n\n return <perspectiveCamera ref={cameraRef} />\n}"],"names":[],"mappings":";;;;;;;AAaa,MAAA,cAAc,KAAuB,CAAC;AAAA,EACjD;AAAA,EAAU;AAAA,EAAW,WAAW;AAAA,EAAG;AACrC,MAAM;AAEJ,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,IAAI,MAAO,CAAA;AAE1C,QAAM,MAAM;AAEZ,QAAM,SAAS,UAAU;AAAA,IACvB;AAAA,IAAU;AAAA,IAAW;AAAA,IAAU,YAAY,IAAI;AAAA,EAAA,CAChD;AAGM,SAAA,oBAAA,UAAA,EAAG,uBACR,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAC,oBAAA,gBAAA,EAAe,KAAU,OAAgB,CAAA;AAAA,IACzC;AAAA,EAAA,GACH,GAAK,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAA,GAAK,EAAE,CAAA;AAC3C,CAAC;AAED,YAAY,cAAc;AAO1B,SAAS,eAAe,EAAE,KAAK,UAA+B;AAE5D,QAAM,EAAE,IAAI,OAAO,QAAQ,SAAS;AAE9B,QAAA,YAAY,OAA0B,IAAI;AAEhD,WAAS,MAAM;AACb,QAAI,CAAC,IAAI;AAAU;AACnB,QAAI,CAAC,UAAU;AAAS;AACxB,eAAW,UAAU,SAAS,QAAQ,IAAI,QAAQ;AAC/C,OAAA,OAAO,OAAO,UAAU,OAAO;AAAA,EAAA,CACnC;AAED,kBAAgB,MAAM;AACpB,QAAI,CAAC,UAAU;AAAS;AACpB,QAAA;AAAA,MACF,YAAY,MAAM;AAChB,YAAI,CAAC,IAAI;AAAK;AACd,YAAI,IAAI;MACV;AAAA,MACA,QAAQ,UAAU;AAAA,IAAA,CACnB;AAAA,EAAA,GACA,CAAC,KAAK,GAAG,CAAC;AAEN,SAAA,oBAAC,qBAAkB,EAAA,KAAK,UAAW,CAAA;AAC5C;"}
|
package/dist/es/main4.mjs
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { useCoords
|
|
2
|
-
import { useCreateRoot
|
|
3
|
-
import { useRender
|
|
4
|
-
function
|
|
5
|
-
longitude
|
|
6
|
-
latitude
|
|
7
|
-
altitude
|
|
8
|
-
frameloop
|
|
9
|
-
fromLngLat
|
|
10
|
-
...
|
|
1
|
+
import { useCoords } from "./main7.mjs";
|
|
2
|
+
import { useCreateRoot } from "./main8.mjs";
|
|
3
|
+
import { useRender } from "./main9.mjs";
|
|
4
|
+
function useCanvas({
|
|
5
|
+
longitude,
|
|
6
|
+
latitude,
|
|
7
|
+
altitude = 0,
|
|
8
|
+
frameloop = "always",
|
|
9
|
+
fromLngLat,
|
|
10
|
+
...renderProps
|
|
11
11
|
}) {
|
|
12
|
-
const
|
|
13
|
-
latitude
|
|
14
|
-
longitude
|
|
15
|
-
altitude
|
|
16
|
-
fromLngLat
|
|
17
|
-
})
|
|
18
|
-
|
|
12
|
+
const m4 = useCoords({
|
|
13
|
+
latitude,
|
|
14
|
+
longitude,
|
|
15
|
+
altitude,
|
|
16
|
+
fromLngLat
|
|
17
|
+
});
|
|
18
|
+
const { id, onAdd, onRemove, r3mRef } = useCreateRoot({ frameloop, fromLngLat, ...renderProps });
|
|
19
|
+
const render = useRender(m4, r3mRef, frameloop);
|
|
20
|
+
return { id, onAdd, onRemove, render };
|
|
19
21
|
}
|
|
20
22
|
export {
|
|
21
|
-
|
|
23
|
+
useCanvas
|
|
22
24
|
};
|
|
23
25
|
//# sourceMappingURL=main4.mjs.map
|
package/dist/es/main4.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main4.mjs","sources":["../../src/core/use-canvas.ts"],"sourcesContent":["import { CanvasProps } from \"../api/canvas-props\";\nimport { FromLngLat } from \"./generic-map\";\nimport { useCoords } from \"./use-coords\";\nimport { useCreateRoot } from \"./use-create-root\";\nimport { useRender } from \"./use-render\";\n\nexport interface useCanvasProps extends CanvasProps {\n fromLngLat: FromLngLat,\n}\n\nexport function useCanvas({\n longitude, latitude, altitude = 0,\n frameloop = 'always',\n fromLngLat,\n ...renderProps\n}: useCanvasProps) {\n\n const m4 = useCoords({\n latitude, longitude, altitude, fromLngLat,\n });\n\n const { id, onAdd, onRemove, r3mRef } = useCreateRoot({ frameloop, fromLngLat, ...renderProps });\n\n const render = useRender(m4, r3mRef, frameloop);\n\n return { id, onAdd, onRemove, render }\n}"],"names":[
|
|
1
|
+
{"version":3,"file":"main4.mjs","sources":["../../src/core/use-canvas.ts"],"sourcesContent":["import { CanvasProps } from \"../api/canvas-props\";\nimport { FromLngLat } from \"./generic-map\";\nimport { useCoords } from \"./use-coords\";\nimport { useCreateRoot } from \"./use-create-root\";\nimport { useRender } from \"./use-render\";\n\nexport interface useCanvasProps extends CanvasProps {\n fromLngLat: FromLngLat,\n}\n\nexport function useCanvas({\n longitude, latitude, altitude = 0,\n frameloop = 'always',\n fromLngLat,\n ...renderProps\n}: useCanvasProps) {\n\n const m4 = useCoords({\n latitude, longitude, altitude, fromLngLat,\n });\n\n const { id, onAdd, onRemove, r3mRef } = useCreateRoot({ frameloop, fromLngLat, ...renderProps });\n\n const render = useRender(m4, r3mRef, frameloop);\n\n return { id, onAdd, onRemove, render }\n}"],"names":[],"mappings":";;;AAUO,SAAS,UAAU;AAAA,EACxB;AAAA,EAAW;AAAA,EAAU,WAAW;AAAA,EAChC,YAAY;AAAA,EACZ;AAAA,EACA,GAAG;AACL,GAAmB;AAEjB,QAAM,KAAK,UAAU;AAAA,IACnB;AAAA,IAAU;AAAA,IAAW;AAAA,IAAU;AAAA,EAAA,CAChC;AAED,QAAM,EAAE,IAAI,OAAO,UAAU,OAAO,IAAI,cAAc,EAAE,WAAW,YAAY,GAAG,YAAa,CAAA;AAE/F,QAAM,SAAS,UAAU,IAAI,QAAQ,SAAS;AAE9C,SAAO,EAAE,IAAI,OAAO,UAAU,OAAO;AACvC;"}
|
package/dist/es/main5.mjs
CHANGED
package/dist/es/main5.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main5.mjs","sources":["../../src/core/store.ts"],"sourcesContent":["import { ReconcilerRoot, RootState, useThree } from \"@react-three/fiber\";\nimport { Matrix4Tuple } from \"three\";\nimport { FromLngLat, MapInstance } from \"./generic-map\";\n\n/** react-three-map store */\nexport interface R3mStore {\n fromLngLat: FromLngLat,\n map?: MapInstance;\n mapCamMx?: Matrix4Tuple;\n state?: RootState\n root?: ReconcilerRoot<HTMLCanvasElement>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useR3M = (): R3mStore => useThree((s: any) => s.r3m);"],"names":[
|
|
1
|
+
{"version":3,"file":"main5.mjs","sources":["../../src/core/store.ts"],"sourcesContent":["import { ReconcilerRoot, RootState, useThree } from \"@react-three/fiber\";\nimport { Matrix4Tuple } from \"three\";\nimport { FromLngLat, MapInstance } from \"./generic-map\";\n\n/** react-three-map store */\nexport interface R3mStore {\n fromLngLat: FromLngLat,\n map?: MapInstance;\n mapCamMx?: Matrix4Tuple;\n state?: RootState\n root?: ReconcilerRoot<HTMLCanvasElement>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useR3M = (): R3mStore => useThree((s: any) => s.r3m);"],"names":[],"mappings":";AAcO,MAAM,SAAS,MAAgB,SAAS,CAAC,MAAW,EAAE,GAAG;"}
|
package/dist/es/main6.mjs
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
|
-
import { Matrix4
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Matrix4, Vector3 } from "three";
|
|
2
|
+
const originMx = new Matrix4();
|
|
3
|
+
const projByView = new Matrix4();
|
|
4
|
+
const projByViewInv = new Matrix4();
|
|
5
|
+
const fwd = new Vector3();
|
|
6
|
+
function syncCamera(camera, origin, mapCamMx) {
|
|
7
|
+
projByView.fromArray(mapCamMx).multiply(originMx.fromArray(origin));
|
|
8
|
+
projByViewInv.copy(projByView).invert();
|
|
9
|
+
updateCamera(camera, projByViewInv);
|
|
10
|
+
camera.updateMatrix();
|
|
11
|
+
camera.updateMatrixWorld(true);
|
|
12
|
+
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
13
|
+
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
14
|
+
camera.far = calculateFar(
|
|
15
|
+
camera.matrix.elements[10],
|
|
16
|
+
camera.matrix.elements[14],
|
|
17
|
+
camera.near
|
|
18
|
+
);
|
|
19
|
+
camera.userData.projByView = projByView.toArray();
|
|
20
|
+
camera.userData.projByViewInv = projByViewInv.toArray();
|
|
21
|
+
}
|
|
22
|
+
const updateCamera = (target, projByViewInv2) => {
|
|
23
|
+
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
24
|
+
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
25
|
+
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
26
|
+
target.lookAt(fwd);
|
|
27
|
+
};
|
|
28
|
+
function calculateFar(c, d, near) {
|
|
29
|
+
const numerator = d * (c - 1);
|
|
30
|
+
const denominator = c * near + near;
|
|
31
|
+
const far = numerator / denominator;
|
|
32
|
+
return far;
|
|
5
33
|
}
|
|
6
34
|
export {
|
|
7
|
-
|
|
35
|
+
syncCamera
|
|
8
36
|
};
|
|
9
37
|
//# sourceMappingURL=main6.mjs.map
|
package/dist/es/main6.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main6.mjs","sources":["../../src/core/sync-camera.ts"],"sourcesContent":["import { Matrix4, Matrix4Tuple, PerspectiveCamera } from \"three\";\n\nconst
|
|
1
|
+
{"version":3,"file":"main6.mjs","sources":["../../src/core/sync-camera.ts"],"sourcesContent":["import { Matrix4, Matrix4Tuple, Object3D, PerspectiveCamera, Vector3 } from \"three\";\n\nconst originMx = new Matrix4();\n\n/** projection * view matrix */\nconst projByView = new Matrix4();\n/** projection * view matrix inverted */\nconst projByViewInv = new Matrix4();\n\n/** forward */\nconst fwd = new Vector3();\n\n\nexport function syncCamera(camera: PerspectiveCamera, origin: Matrix4Tuple, mapCamMx: Matrix4Tuple) {\n\n projByView\n .fromArray(mapCamMx)\n .multiply(originMx.fromArray(origin));\n projByViewInv\n .copy(projByView)\n .invert();\n\n updateCamera(camera, projByViewInv);\n camera.updateMatrix();\n camera.updateMatrixWorld(true); \n\n camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n\n camera.far = calculateFar(\n camera.matrix.elements[10], camera.matrix.elements[14], camera.near\n )\n\n camera.userData.projByView = projByView.toArray();\n camera.userData.projByViewInv = projByViewInv.toArray();\n\n}\n\nconst updateCamera = (target: Object3D, projByViewInv: Matrix4) => {\n\n target.position\n .setScalar(0)\n .applyMatrix4(projByViewInv)\n\n target.up\n .set(0, -1, 0)\n .applyMatrix4(projByViewInv)\n .negate()\n .add(target.position)\n .normalize()\n\n fwd\n .set(0, 0, 1)\n .applyMatrix4(projByViewInv)\n\n target.lookAt(fwd);\n\n}\n\nfunction calculateFar(c: number, d: number, near: number): number {\n const numerator = d * (c - 1);\n const denominator = c * near + near;\n const far = numerator / denominator;\n return far;\n}"],"names":["projByViewInv"],"mappings":";AAEA,MAAM,WAAW,IAAI;AAGrB,MAAM,aAAa,IAAI;AAEvB,MAAM,gBAAgB,IAAI;AAG1B,MAAM,MAAM,IAAI;AAGA,SAAA,WAAW,QAA2B,QAAsB,UAAwB;AAElG,aACG,UAAU,QAAQ,EAClB,SAAS,SAAS,UAAU,MAAM,CAAC;AAEnC,gBAAA,KAAK,UAAU,EACf,OAAO;AAEV,eAAa,QAAQ,aAAa;AAClC,SAAO,aAAa;AACpB,SAAO,kBAAkB,IAAI;AAE7B,SAAO,iBAAiB,KAAK,OAAO,MAAM,EAAE,YAAY,UAAU;AAClE,SAAO,wBAAwB,KAAK,OAAO,gBAAgB,EAAE;AAE7D,SAAO,MAAM;AAAA,IACX,OAAO,OAAO,SAAS,EAAE;AAAA,IAAG,OAAO,OAAO,SAAS,EAAE;AAAA,IAAG,OAAO;AAAA,EAAA;AAG1D,SAAA,SAAS,aAAa,WAAW,QAAQ;AACzC,SAAA,SAAS,gBAAgB,cAAc,QAAQ;AAExD;AAEA,MAAM,eAAe,CAAC,QAAkBA,mBAA2B;AAEjE,SAAO,SACJ,UAAU,CAAC,EACX,aAAaA,cAAa;AAE7B,SAAO,GACJ,IAAI,GAAG,IAAI,CAAC,EACZ,aAAaA,cAAa,EAC1B,SACA,IAAI,OAAO,QAAQ,EACnB;AAEH,MACG,IAAI,GAAG,GAAG,CAAC,EACX,aAAaA,cAAa;AAE7B,SAAO,OAAO,GAAG;AAEnB;AAEA,SAAS,aAAa,GAAW,GAAW,MAAsB;AAC1D,QAAA,YAAY,KAAK,IAAI;AACrB,QAAA,cAAc,IAAI,OAAO;AAC/B,QAAM,MAAM,YAAY;AACjB,SAAA;AACT;"}
|
package/dist/es/main7.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { useMemo
|
|
2
|
-
import { coordsToMatrix
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
latitude
|
|
6
|
-
longitude
|
|
7
|
-
altitude
|
|
8
|
-
fromLngLat
|
|
9
|
-
}), [
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { coordsToMatrix } from "./main10.mjs";
|
|
3
|
+
function useCoords({ 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;
|
|
10
11
|
}
|
|
11
12
|
export {
|
|
12
|
-
|
|
13
|
+
useCoords
|
|
13
14
|
};
|
|
14
15
|
//# sourceMappingURL=main7.mjs.map
|
package/dist/es/main7.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main7.mjs","sources":["../../src/core/use-coords.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 useCoords({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":[
|
|
1
|
+
{"version":3,"file":"main7.mjs","sources":["../../src/core/use-coords.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 useCoords({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,UAAU,EAAC,UAAU,WAAW,UAAU,cAAoB;AACtE,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;"}
|
package/dist/es/main8.mjs
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import { useId
|
|
3
|
-
import { useOnAdd
|
|
4
|
-
const
|
|
5
|
-
children
|
|
6
|
-
frameloop
|
|
7
|
-
fromLngLat
|
|
8
|
-
...
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useEffect } from "react";
|
|
3
|
+
import { useOnAdd } from "./main11.mjs";
|
|
4
|
+
const useCreateRoot = ({
|
|
5
|
+
children,
|
|
6
|
+
frameloop,
|
|
7
|
+
fromLngLat,
|
|
8
|
+
...renderProps
|
|
9
9
|
}) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const id = useId();
|
|
11
|
+
const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat, { frameloop, ...renderProps });
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!mounted)
|
|
14
|
+
return;
|
|
15
|
+
if (!r3mRef.current.root)
|
|
16
|
+
return;
|
|
17
|
+
r3mRef.current.root.render(/* @__PURE__ */ jsx(Fragment, { children }));
|
|
18
|
+
}, [r3mRef, mounted, children]);
|
|
19
|
+
return { id, onAdd, onRemove, r3mRef };
|
|
14
20
|
};
|
|
15
21
|
export {
|
|
16
|
-
|
|
22
|
+
useCreateRoot
|
|
17
23
|
};
|
|
18
24
|
//# sourceMappingURL=main8.mjs.map
|
package/dist/es/main8.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main8.mjs","sources":["../../src/core/use-create-root.tsx"],"sourcesContent":["import { RenderProps } from \"@react-three/fiber\";\nimport { PropsWithChildren, useEffect, useId } from \"react\";\nimport { FromLngLat } from \"./generic-map\";\nimport { useOnAdd } from \"./use-on-add\";\n\nexport interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {\n frameloop: 'always' | 'demand',\n fromLngLat: FromLngLat\n}\n\nexport const useCreateRoot = (({\n children, frameloop, fromLngLat, ...renderProps\n}: useCanvasProps) => {\n\n const id = useId();\n\n const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat, { frameloop, ...renderProps });\n\n useEffect(() => {\n if (!mounted) return;\n if (!r3mRef.current.root) return;\n r3mRef.current.root.render(<>\n {children}\n </>);\n }, [r3mRef, mounted, children])\n\n return { id, onAdd, onRemove, r3mRef }\n})"],"names":[
|
|
1
|
+
{"version":3,"file":"main8.mjs","sources":["../../src/core/use-create-root.tsx"],"sourcesContent":["import { RenderProps } from \"@react-three/fiber\";\nimport { PropsWithChildren, useEffect, useId } from \"react\";\nimport { FromLngLat } from \"./generic-map\";\nimport { useOnAdd } from \"./use-on-add\";\n\nexport interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {\n frameloop: 'always' | 'demand',\n fromLngLat: FromLngLat\n}\n\nexport const useCreateRoot = (({\n children, frameloop, fromLngLat, ...renderProps\n}: useCanvasProps) => {\n\n const id = useId();\n\n const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat, { frameloop, ...renderProps });\n\n useEffect(() => {\n if (!mounted) return;\n if (!r3mRef.current.root) return;\n r3mRef.current.root.render(<>\n {children}\n </>);\n }, [r3mRef, mounted, children])\n\n return { id, onAdd, onRemove, r3mRef }\n})"],"names":[],"mappings":";;;AAUO,MAAM,gBAAiB,CAAC;AAAA,EAC7B;AAAA,EAAU;AAAA,EAAW;AAAA,EAAY,GAAG;AACtC,MAAsB;AAEpB,QAAM,KAAK;AAEX,QAAM,EAAE,OAAO,UAAU,SAAS,OAAO,IAAI,SAAS,YAAY,EAAE,WAAW,GAAG,YAAa,CAAA;AAE/F,YAAU,MAAM;AACd,QAAI,CAAC;AAAS;AACV,QAAA,CAAC,OAAO,QAAQ;AAAM;AAC1B,WAAO,QAAQ,KAAK,OAAO,oBAAA,UAAA,EACxB,SACH,CAAA,CAAG;AAAA,EACF,GAAA,CAAC,QAAQ,SAAS,QAAQ,CAAC;AAE9B,SAAO,EAAE,IAAI,OAAO,UAAU,OAAO;AACvC;"}
|
package/dist/es/main9.mjs
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import { syncCamera
|
|
2
|
-
import { useFunction
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
1
|
+
import { syncCamera } from "./main6.mjs";
|
|
2
|
+
import { useFunction } from "./main12.mjs";
|
|
3
|
+
function useRender(origin, r3mRef, frameloop) {
|
|
4
|
+
const render = useFunction((_gl, mapCamMx) => {
|
|
5
|
+
const r3m = r3mRef.current;
|
|
6
|
+
if (!r3m.state || !r3m.map)
|
|
7
7
|
return;
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const camera = r3m.state.camera;
|
|
9
|
+
const gl = r3m.state.gl;
|
|
10
|
+
const advance = r3m.state.advance;
|
|
11
|
+
r3m.mapCamMx = mapCamMx;
|
|
12
|
+
syncCamera(camera, origin, mapCamMx);
|
|
13
|
+
gl.resetState();
|
|
14
|
+
advance(Date.now() * 1e-3, true);
|
|
15
|
+
if (frameloop === "always")
|
|
16
|
+
r3m.map.triggerRepaint();
|
|
10
17
|
});
|
|
18
|
+
return render;
|
|
11
19
|
}
|
|
12
20
|
export {
|
|
13
|
-
|
|
21
|
+
useRender
|
|
14
22
|
};
|
|
15
23
|
//# sourceMappingURL=main9.mjs.map
|
package/dist/es/main9.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main9.mjs","sources":["../../src/core/use-render.ts"],"sourcesContent":["import { MutableRefObject } from \"react\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { R3mStore } from \"./store\";\nimport { syncCamera } from \"./sync-camera\";\nimport { useFunction } from \"./use-function\";\n\nexport function useRender(\n origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'\n) {\n\n const render = useFunction((_gl: WebGL2RenderingContext, mapCamMx: number[]) => {\n const r3m = r3mRef.current;\n if (!r3m.state || !r3m.map) return;\n const camera = r3m.state.camera;\n const gl = r3m.state.gl;\n const advance = r3m.state.advance;\n r3m.mapCamMx = mapCamMx as Matrix4Tuple;\n syncCamera(camera as PerspectiveCamera, origin, mapCamMx as Matrix4Tuple);\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (frameloop === 'always') r3m.map.triggerRepaint();\n })\n\n return render;\n\n}"],"names":[
|
|
1
|
+
{"version":3,"file":"main9.mjs","sources":["../../src/core/use-render.ts"],"sourcesContent":["import { MutableRefObject } from \"react\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { R3mStore } from \"./store\";\nimport { syncCamera } from \"./sync-camera\";\nimport { useFunction } from \"./use-function\";\n\nexport function useRender(\n origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'\n) {\n\n const render = useFunction((_gl: WebGL2RenderingContext, mapCamMx: number[]) => {\n const r3m = r3mRef.current;\n if (!r3m.state || !r3m.map) return;\n const camera = r3m.state.camera;\n const gl = r3m.state.gl;\n const advance = r3m.state.advance;\n r3m.mapCamMx = mapCamMx as Matrix4Tuple;\n syncCamera(camera as PerspectiveCamera, origin, mapCamMx as Matrix4Tuple);\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (frameloop === 'always') r3m.map.triggerRepaint();\n })\n\n return render;\n\n}"],"names":[],"mappings":";;AAMgB,SAAA,UACd,QAAsB,QAAoC,WAC1D;AAEA,QAAM,SAAS,YAAY,CAAC,KAA6B,aAAuB;AAC9E,UAAM,MAAM,OAAO;AACnB,QAAI,CAAC,IAAI,SAAS,CAAC,IAAI;AAAK;AACtB,UAAA,SAAS,IAAI,MAAM;AACnB,UAAA,KAAK,IAAI,MAAM;AACf,UAAA,UAAU,IAAI,MAAM;AAC1B,QAAI,WAAW;AACJ,eAAA,QAA6B,QAAQ,QAAwB;AACxE,OAAG,WAAW;AACd,YAAQ,KAAK,IAAQ,IAAA,MAAO,IAAI;AAChC,QAAI,cAAc;AAAU,UAAI,IAAI;EAAe,CACpD;AAEM,SAAA;AAET;"}
|