react-three-map 0.5.0 → 0.6.0
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 +10 -0
- package/dist/cjs/main.js +84 -84
- package/dist/es/main.mjs +2 -2
- package/dist/es/main.mjs.map +1 -1
- package/dist/es/main10.mjs +20 -19
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +19 -14
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main3.mjs +52 -23
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main4.mjs +23 -52
- package/dist/es/main4.mjs.map +1 -1
- package/dist/es/main5.mjs +3 -22
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +34 -3
- package/dist/es/main6.mjs.map +1 -1
- package/dist/es/main7.mjs +11 -33
- package/dist/es/main7.mjs.map +1 -1
- package/dist/es/main8.mjs +17 -7
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +15 -21
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +84 -84
- package/dist/maplibre/es/main.mjs +2 -2
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main11.mjs +1 -1
- package/dist/maplibre/es/main3.mjs +52 -23
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +23 -52
- package/dist/maplibre/es/main4.mjs.map +1 -1
- package/dist/maplibre/es/main5.mjs +3 -22
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/es/main6.mjs +34 -3
- package/dist/maplibre/es/main6.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +11 -33
- package/dist/maplibre/es/main7.mjs.map +1 -1
- package/dist/maplibre/es/main8.mjs +17 -7
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/types/maplibre.index.d.ts +3 -3
- package/dist/types/mapbox.index.d.ts +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/main.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fiber = require("@react-three/fiber");
|
|
4
4
|
const jsxRuntime = require("react/jsx-runtime");
|
|
5
|
-
const mapboxGl = require("mapbox-gl");
|
|
6
5
|
const react = require("react");
|
|
7
|
-
const reactMapGl = require("react-map-gl");
|
|
8
6
|
const THREE = require("three");
|
|
7
|
+
const mapboxGl = require("mapbox-gl");
|
|
8
|
+
const reactMapGl = require("react-map-gl");
|
|
9
9
|
function _interopNamespaceDefault(e) {
|
|
10
10
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
11
|
if (e) {
|
|
@@ -27,6 +27,39 @@ const useMap$1 = () => fiber.useThree((s) => {
|
|
|
27
27
|
var _a;
|
|
28
28
|
return (_a = s.r3m) == null ? void 0 : _a.map;
|
|
29
29
|
});
|
|
30
|
+
const useR3M = () => fiber.useThree((s) => s.r3m);
|
|
31
|
+
const originMx = new THREE.Matrix4();
|
|
32
|
+
const projByView = new THREE.Matrix4();
|
|
33
|
+
const projByViewInv$1 = new THREE.Matrix4();
|
|
34
|
+
const fwd = new THREE.Vector3();
|
|
35
|
+
function syncCamera(camera, origin, mapCamMx) {
|
|
36
|
+
projByView.fromArray(mapCamMx).multiply(originMx.fromArray(origin));
|
|
37
|
+
projByViewInv$1.copy(projByView).invert();
|
|
38
|
+
updateCamera(camera, projByViewInv$1);
|
|
39
|
+
camera.updateMatrix();
|
|
40
|
+
camera.updateMatrixWorld(true);
|
|
41
|
+
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
42
|
+
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
43
|
+
camera.far = calculateFar(
|
|
44
|
+
camera.matrix.elements[10],
|
|
45
|
+
camera.matrix.elements[14],
|
|
46
|
+
camera.near
|
|
47
|
+
);
|
|
48
|
+
camera.userData.projByView = projByView.toArray();
|
|
49
|
+
camera.userData.projByViewInv = projByViewInv$1.toArray();
|
|
50
|
+
}
|
|
51
|
+
const updateCamera = (target, projByViewInv2) => {
|
|
52
|
+
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
53
|
+
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
54
|
+
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
55
|
+
target.lookAt(fwd);
|
|
56
|
+
};
|
|
57
|
+
function calculateFar(c, d, near) {
|
|
58
|
+
const numerator = d * (c - 1);
|
|
59
|
+
const denominator = c * near + near;
|
|
60
|
+
const far = numerator / denominator;
|
|
61
|
+
return far;
|
|
62
|
+
}
|
|
30
63
|
const quat = new THREE.Quaternion();
|
|
31
64
|
const euler = new THREE.Euler();
|
|
32
65
|
const pos = new THREE.Vector3();
|
|
@@ -49,6 +82,51 @@ function useCoords({ latitude, longitude, altitude, fromLngLat: fromLngLat2 }) {
|
|
|
49
82
|
}), [latitude, longitude, altitude, fromLngLat2]);
|
|
50
83
|
return m42;
|
|
51
84
|
}
|
|
85
|
+
const Coordinates = react.memo(({
|
|
86
|
+
latitude,
|
|
87
|
+
longitude,
|
|
88
|
+
altitude = 0,
|
|
89
|
+
children
|
|
90
|
+
}) => {
|
|
91
|
+
const [scene] = react.useState(() => new THREE.Scene());
|
|
92
|
+
const r3m = useR3M();
|
|
93
|
+
const origin = useCoords({
|
|
94
|
+
latitude,
|
|
95
|
+
longitude,
|
|
96
|
+
altitude,
|
|
97
|
+
fromLngLat: r3m.fromLngLat
|
|
98
|
+
});
|
|
99
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fiber.createPortal(/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
100
|
+
/* @__PURE__ */ jsxRuntime.jsx(RenderAtCoords, { r3m, origin }),
|
|
101
|
+
children
|
|
102
|
+
] }), scene, { events: { priority: 2 } }) });
|
|
103
|
+
});
|
|
104
|
+
Coordinates.displayName = "Coordinates";
|
|
105
|
+
function RenderAtCoords({ r3m, origin }) {
|
|
106
|
+
const { gl, scene, set } = fiber.useThree();
|
|
107
|
+
const cameraRef = react.useRef(null);
|
|
108
|
+
fiber.useFrame(() => {
|
|
109
|
+
if (!r3m.mapCamMx)
|
|
110
|
+
return;
|
|
111
|
+
if (!cameraRef.current)
|
|
112
|
+
return;
|
|
113
|
+
syncCamera(cameraRef.current, origin, r3m.mapCamMx);
|
|
114
|
+
gl.render(scene, cameraRef.current);
|
|
115
|
+
});
|
|
116
|
+
react.useLayoutEffect(() => {
|
|
117
|
+
if (!cameraRef.current)
|
|
118
|
+
return;
|
|
119
|
+
set({
|
|
120
|
+
invalidate: () => {
|
|
121
|
+
if (!r3m.map)
|
|
122
|
+
return;
|
|
123
|
+
r3m.map.triggerRepaint();
|
|
124
|
+
},
|
|
125
|
+
camera: cameraRef.current
|
|
126
|
+
});
|
|
127
|
+
}, [set, r3m]);
|
|
128
|
+
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
129
|
+
}
|
|
52
130
|
const DOM_EVENTS = {
|
|
53
131
|
onClick: ["click", false],
|
|
54
132
|
onContextMenu: ["contextmenu", false],
|
|
@@ -61,7 +139,7 @@ const DOM_EVENTS = {
|
|
|
61
139
|
onPointerCancel: ["pointercancel", true],
|
|
62
140
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
63
141
|
};
|
|
64
|
-
const projByViewInv
|
|
142
|
+
const projByViewInv = new THREE.Matrix4();
|
|
65
143
|
function createEvents() {
|
|
66
144
|
return (store) => {
|
|
67
145
|
const { handlePointer } = fiber.createEvents(store);
|
|
@@ -72,10 +150,10 @@ function createEvents() {
|
|
|
72
150
|
state.pointer.x = event.offsetX / state.size.width * 2 - 1;
|
|
73
151
|
state.pointer.y = 1 - event.offsetY / state.size.height * 2;
|
|
74
152
|
if (state.camera.userData.projByViewInv)
|
|
75
|
-
projByViewInv
|
|
153
|
+
projByViewInv.fromArray(state.camera.userData.projByViewInv);
|
|
76
154
|
state.raycaster.camera = state.camera;
|
|
77
|
-
state.raycaster.ray.origin.setScalar(0).applyMatrix4(projByViewInv
|
|
78
|
-
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(projByViewInv
|
|
155
|
+
state.raycaster.ray.origin.setScalar(0).applyMatrix4(projByViewInv);
|
|
156
|
+
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(projByViewInv).sub(state.raycaster.ray.origin).normalize();
|
|
79
157
|
},
|
|
80
158
|
connected: void 0,
|
|
81
159
|
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
@@ -208,38 +286,6 @@ const useCreateRoot = ({
|
|
|
208
286
|
}, [r3mRef, mounted, children]);
|
|
209
287
|
return { id, onAdd, onRemove, r3mRef };
|
|
210
288
|
};
|
|
211
|
-
const originMx = new THREE.Matrix4();
|
|
212
|
-
const projByView = new THREE.Matrix4();
|
|
213
|
-
const projByViewInv = new THREE.Matrix4();
|
|
214
|
-
const fwd = new THREE.Vector3();
|
|
215
|
-
function syncCamera(camera, origin, mapCamMx) {
|
|
216
|
-
projByView.fromArray(mapCamMx).multiply(originMx.fromArray(origin));
|
|
217
|
-
projByViewInv.copy(projByView).invert();
|
|
218
|
-
updateCamera(camera, projByViewInv);
|
|
219
|
-
camera.updateMatrix();
|
|
220
|
-
camera.updateMatrixWorld(true);
|
|
221
|
-
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
222
|
-
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
223
|
-
camera.far = calculateFar(
|
|
224
|
-
camera.matrix.elements[10],
|
|
225
|
-
camera.matrix.elements[14],
|
|
226
|
-
camera.near
|
|
227
|
-
);
|
|
228
|
-
camera.userData.projByView = projByView.toArray();
|
|
229
|
-
camera.userData.projByViewInv = projByViewInv.toArray();
|
|
230
|
-
}
|
|
231
|
-
const updateCamera = (target, projByViewInv2) => {
|
|
232
|
-
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
233
|
-
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
234
|
-
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
235
|
-
target.lookAt(fwd);
|
|
236
|
-
};
|
|
237
|
-
function calculateFar(c, d, near) {
|
|
238
|
-
const numerator = d * (c - 1);
|
|
239
|
-
const denominator = c * near + near;
|
|
240
|
-
const far = numerator / denominator;
|
|
241
|
-
return far;
|
|
242
|
-
}
|
|
243
289
|
function useRender(origin, r3mRef, frameloop) {
|
|
244
290
|
const render = useFunction((_gl, mapCamMx) => {
|
|
245
291
|
const r3m = r3mRef.current;
|
|
@@ -291,52 +337,6 @@ const Canvas = react.memo((props) => {
|
|
|
291
337
|
}
|
|
292
338
|
);
|
|
293
339
|
});
|
|
294
|
-
const useR3M = () => fiber.useThree((s) => s.r3m);
|
|
295
|
-
const Coordinates = react.memo(({
|
|
296
|
-
latitude,
|
|
297
|
-
longitude,
|
|
298
|
-
altitude = 0,
|
|
299
|
-
children
|
|
300
|
-
}) => {
|
|
301
|
-
const [scene] = react.useState(() => new THREE.Scene());
|
|
302
|
-
const r3m = useR3M();
|
|
303
|
-
const origin = useCoords({
|
|
304
|
-
latitude,
|
|
305
|
-
longitude,
|
|
306
|
-
altitude,
|
|
307
|
-
fromLngLat: r3m.fromLngLat
|
|
308
|
-
});
|
|
309
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fiber.createPortal(/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
310
|
-
/* @__PURE__ */ jsxRuntime.jsx(RenderAtCoords, { r3m, origin }),
|
|
311
|
-
children
|
|
312
|
-
] }), scene, { events: { priority: 2 } }) });
|
|
313
|
-
});
|
|
314
|
-
Coordinates.displayName = "Coordinates";
|
|
315
|
-
function RenderAtCoords({ r3m, origin }) {
|
|
316
|
-
const { gl, scene, set } = fiber.useThree();
|
|
317
|
-
const cameraRef = react.useRef(null);
|
|
318
|
-
fiber.useFrame(() => {
|
|
319
|
-
if (!r3m.mapCamMx)
|
|
320
|
-
return;
|
|
321
|
-
if (!cameraRef.current)
|
|
322
|
-
return;
|
|
323
|
-
syncCamera(cameraRef.current, origin, r3m.mapCamMx);
|
|
324
|
-
gl.render(scene, cameraRef.current);
|
|
325
|
-
});
|
|
326
|
-
react.useLayoutEffect(() => {
|
|
327
|
-
if (!cameraRef.current)
|
|
328
|
-
return;
|
|
329
|
-
set({
|
|
330
|
-
invalidate: () => {
|
|
331
|
-
if (!r3m.map)
|
|
332
|
-
return;
|
|
333
|
-
r3m.map.triggerRepaint();
|
|
334
|
-
},
|
|
335
|
-
camera: cameraRef.current
|
|
336
|
-
});
|
|
337
|
-
}, [set, r3m]);
|
|
338
|
-
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
339
|
-
}
|
|
340
340
|
const useMap = useMap$1;
|
|
341
341
|
exports.Canvas = Canvas;
|
|
342
342
|
exports.Coordinates = Coordinates;
|
package/dist/es/main.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMap as useMap$1 } from "./main2.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Coordinates } from "./main3.mjs";
|
|
3
|
+
import { Canvas } from "./main4.mjs";
|
|
4
4
|
const useMap = useMap$1;
|
|
5
5
|
export {
|
|
6
6
|
Canvas,
|
package/dist/es/main.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":["../../src/mapbox.index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":["../../src/mapbox.index.ts"],"sourcesContent":["import type { Map } from 'mapbox-gl';\nimport { useMap as useMapGeneric } from './api/use-map';\n\nexport * from './api/canvas-props';\nexport * from './api/coordinates';\nexport * from './mapbox/canvas';\n\nexport const useMap = useMapGeneric<Map>;\n"],"names":["useMapGeneric"],"mappings":";;;AAOO,MAAM,SAASA;"}
|
package/dist/es/main10.mjs
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useEffect } from "react";
|
|
3
|
+
import { useOnAdd } from "./main12.mjs";
|
|
4
|
+
const useCreateRoot = ({
|
|
5
|
+
children,
|
|
6
|
+
frameloop,
|
|
7
|
+
fromLngLat,
|
|
8
|
+
...renderProps
|
|
9
|
+
}) => {
|
|
10
|
+
const id = useId();
|
|
11
|
+
const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat, { frameloop, ...renderProps });
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!mounted)
|
|
7
14
|
return;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
advance(Date.now() * 1e-3, true);
|
|
15
|
-
if (frameloop === "always")
|
|
16
|
-
r3m.map.triggerRepaint();
|
|
17
|
-
});
|
|
18
|
-
return render;
|
|
19
|
-
}
|
|
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 };
|
|
20
|
+
};
|
|
20
21
|
export {
|
|
21
|
-
|
|
22
|
+
useCreateRoot
|
|
22
23
|
};
|
|
23
24
|
//# sourceMappingURL=main10.mjs.map
|
package/dist/es/main10.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main10.mjs","sources":["../../src/core/use-
|
|
1
|
+
{"version":3,"file":"main10.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/main11.mjs
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { syncCamera } from "./main6.mjs";
|
|
2
|
+
import { useFunction } from "./main13.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
|
+
return;
|
|
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();
|
|
17
|
+
});
|
|
18
|
+
return render;
|
|
14
19
|
}
|
|
15
20
|
export {
|
|
16
|
-
|
|
21
|
+
useRender
|
|
17
22
|
};
|
|
18
23
|
//# sourceMappingURL=main11.mjs.map
|
package/dist/es/main11.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main11.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main11.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;"}
|
package/dist/es/main3.mjs
CHANGED
|
@@ -1,27 +1,56 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
}) => {
|
|
14
|
+
const [scene] = useState(() => new Scene());
|
|
15
|
+
const r3m = useR3M();
|
|
16
|
+
const origin = useCoords({
|
|
17
|
+
latitude,
|
|
18
|
+
longitude,
|
|
19
|
+
altitude,
|
|
20
|
+
fromLngLat: r3m.fromLngLat
|
|
21
|
+
});
|
|
22
|
+
return /* @__PURE__ */ jsx(Fragment, { children: createPortal(/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
23
|
+
/* @__PURE__ */ jsx(RenderAtCoords, { r3m, origin }),
|
|
24
|
+
children
|
|
25
|
+
] }), scene, { events: { priority: 2 } }) });
|
|
23
26
|
});
|
|
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({
|
|
43
|
+
invalidate: () => {
|
|
44
|
+
if (!r3m.map)
|
|
45
|
+
return;
|
|
46
|
+
r3m.map.triggerRepaint();
|
|
47
|
+
},
|
|
48
|
+
camera: cameraRef.current
|
|
49
|
+
});
|
|
50
|
+
}, [set, r3m]);
|
|
51
|
+
return /* @__PURE__ */ jsx("perspectiveCamera", { ref: cameraRef });
|
|
52
|
+
}
|
|
24
53
|
export {
|
|
25
|
-
|
|
54
|
+
Coordinates
|
|
26
55
|
};
|
|
27
56
|
//# sourceMappingURL=main3.mjs.map
|
package/dist/es/main3.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main3.mjs","sources":["../../src/
|
|
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,56 +1,27 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/* @__PURE__ */ jsx(RenderAtCoords, { r3m, origin }),
|
|
24
|
-
children
|
|
25
|
-
] }), scene, { events: { priority: 2 } }) });
|
|
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 "./main8.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,
|
|
14
|
+
{
|
|
15
|
+
id,
|
|
16
|
+
type: "custom",
|
|
17
|
+
renderingMode: "3d",
|
|
18
|
+
onAdd,
|
|
19
|
+
onRemove,
|
|
20
|
+
render
|
|
21
|
+
}
|
|
22
|
+
);
|
|
26
23
|
});
|
|
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({
|
|
43
|
-
invalidate: () => {
|
|
44
|
-
if (!r3m.map)
|
|
45
|
-
return;
|
|
46
|
-
r3m.map.triggerRepaint();
|
|
47
|
-
},
|
|
48
|
-
camera: cameraRef.current
|
|
49
|
-
});
|
|
50
|
-
}, [set, r3m]);
|
|
51
|
-
return /* @__PURE__ */ jsx("perspectiveCamera", { ref: cameraRef });
|
|
52
|
-
}
|
|
53
24
|
export {
|
|
54
|
-
|
|
25
|
+
Canvas
|
|
55
26
|
};
|
|
56
27
|
//# sourceMappingURL=main4.mjs.map
|
package/dist/es/main4.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main4.mjs","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"main4.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/main5.mjs
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { useRender } from "./main10.mjs";
|
|
4
|
-
function useCanvas({
|
|
5
|
-
longitude,
|
|
6
|
-
latitude,
|
|
7
|
-
altitude = 0,
|
|
8
|
-
frameloop = "always",
|
|
9
|
-
fromLngLat,
|
|
10
|
-
...renderProps
|
|
11
|
-
}) {
|
|
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 };
|
|
21
|
-
}
|
|
1
|
+
import { useThree } from "@react-three/fiber";
|
|
2
|
+
const useR3M = () => useThree((s) => s.r3m);
|
|
22
3
|
export {
|
|
23
|
-
|
|
4
|
+
useR3M
|
|
24
5
|
};
|
|
25
6
|
//# sourceMappingURL=main5.mjs.map
|
package/dist/es/main5.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main5.mjs","sources":["../../src/core/
|
|
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,6 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
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;
|
|
33
|
+
}
|
|
3
34
|
export {
|
|
4
|
-
|
|
35
|
+
syncCamera
|
|
5
36
|
};
|
|
6
37
|
//# sourceMappingURL=main6.mjs.map
|