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/dist/es/main6.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main6.mjs","sources":["../../src/core/
|
|
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,37 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { coordsToMatrix } from "./main9.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;
|
|
33
11
|
}
|
|
34
12
|
export {
|
|
35
|
-
|
|
13
|
+
useCoords
|
|
36
14
|
};
|
|
37
15
|
//# sourceMappingURL=main7.mjs.map
|
package/dist/es/main7.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main7.mjs","sources":["../../src/core/
|
|
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,15 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { useCoords } from "./main7.mjs";
|
|
2
|
+
import { useCreateRoot } from "./main10.mjs";
|
|
3
|
+
import { useRender } from "./main11.mjs";
|
|
4
|
+
function useCanvas({
|
|
5
|
+
longitude,
|
|
6
|
+
latitude,
|
|
7
|
+
altitude = 0,
|
|
8
|
+
frameloop = "always",
|
|
9
|
+
fromLngLat,
|
|
10
|
+
...renderProps
|
|
11
|
+
}) {
|
|
12
|
+
const m4 = useCoords({
|
|
5
13
|
latitude,
|
|
6
14
|
longitude,
|
|
7
15
|
altitude,
|
|
8
16
|
fromLngLat
|
|
9
|
-
})
|
|
10
|
-
|
|
17
|
+
});
|
|
18
|
+
const { id, onAdd, onRemove, r3mRef } = useCreateRoot({ frameloop, fromLngLat, ...renderProps });
|
|
19
|
+
const render = useRender(m4, r3mRef, frameloop);
|
|
20
|
+
return { id, onAdd, onRemove, render };
|
|
11
21
|
}
|
|
12
22
|
export {
|
|
13
|
-
|
|
23
|
+
useCanvas
|
|
14
24
|
};
|
|
15
25
|
//# sourceMappingURL=main8.mjs.map
|
package/dist/es/main8.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main8.mjs","sources":["../../src/core/use-
|
|
1
|
+
{"version":3,"file":"main8.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/main9.mjs
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
};
|
|
1
|
+
import { Quaternion, Euler, Vector3, Matrix4 } from "three";
|
|
2
|
+
const quat = new Quaternion();
|
|
3
|
+
const euler = new Euler();
|
|
4
|
+
const pos = new Vector3();
|
|
5
|
+
const scale = new Vector3();
|
|
6
|
+
const m4 = new Matrix4();
|
|
7
|
+
function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }) {
|
|
8
|
+
const center = fromLngLat([longitude, latitude], altitude);
|
|
9
|
+
const scaleUnit = center.meterInMercatorCoordinateUnits();
|
|
10
|
+
pos.set(center.x, center.y, center.z || 0);
|
|
11
|
+
scale.set(scaleUnit, -scaleUnit, scaleUnit);
|
|
12
|
+
quat.setFromEuler(euler.set(-Math.PI * 0.5, 0, 0));
|
|
13
|
+
return m4.compose(pos, quat, scale).toArray();
|
|
14
|
+
}
|
|
21
15
|
export {
|
|
22
|
-
|
|
16
|
+
coordsToMatrix
|
|
23
17
|
};
|
|
24
18
|
//# sourceMappingURL=main9.mjs.map
|
package/dist/es/main9.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main9.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main9.mjs","sources":["../../src/core/coords-to-matrix.ts"],"sourcesContent":["import { Euler, Matrix4, Quaternion, Vector3 } from \"three\";\nimport { FromLngLat } from \"./generic-map\";\n\nconst quat = new Quaternion();\nconst euler = new Euler();\nconst pos = new Vector3();\nconst scale = new Vector3();\nconst m4 = new Matrix4();\n\n/** calculate Matrix4 from coordinates */\nexport function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }: {\n longitude: number, latitude: number, altitude: number, fromLngLat: FromLngLat\n}) {\n const center = fromLngLat([longitude, latitude], altitude);\n const scaleUnit = center.meterInMercatorCoordinateUnits();\n pos.set(center.x, center.y, center.z || 0);\n scale.set(scaleUnit, -scaleUnit, scaleUnit);\n quat.setFromEuler(euler.set(-Math.PI * .5, 0, 0));\n return m4.compose(pos, quat, scale).toArray();\n}\n"],"names":[],"mappings":";AAGA,MAAM,OAAO,IAAI;AACjB,MAAM,QAAQ,IAAI;AAClB,MAAM,MAAM,IAAI;AAChB,MAAM,QAAQ,IAAI;AAClB,MAAM,KAAK,IAAI;AAGR,SAAS,eAAe,EAAE,WAAW,UAAU,UAAU,cAE7D;AACD,QAAM,SAAS,WAAW,CAAC,WAAW,QAAQ,GAAG,QAAQ;AACnD,QAAA,YAAY,OAAO;AACzB,MAAI,IAAI,OAAO,GAAG,OAAO,GAAG,OAAO,KAAK,CAAC;AACzC,QAAM,IAAI,WAAW,CAAC,WAAW,SAAS;AACrC,OAAA,aAAa,MAAM,IAAI,CAAC,KAAK,KAAK,KAAI,GAAG,CAAC,CAAC;AAChD,SAAO,GAAG,QAAQ,KAAK,MAAM,KAAK,EAAE;AACtC;"}
|
|
@@ -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 maplibreGl = require("maplibre-gl");
|
|
6
5
|
const react = require("react");
|
|
7
|
-
const maplibre = require("react-map-gl/maplibre");
|
|
8
6
|
const THREE = require("three");
|
|
7
|
+
const maplibreGl = require("maplibre-gl");
|
|
8
|
+
const maplibre = require("react-map-gl/maplibre");
|
|
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;
|
|
@@ -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,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":["../../../src/maplibre.index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":["../../../src/maplibre.index.ts"],"sourcesContent":["import type { Map } from 'maplibre-gl';\nimport { useMap as useMapGeneric } from './api/use-map';\n\nexport * from './api/canvas-props';\nexport * from './api/coordinates';\nexport * from './maplibre/canvas';\n\nexport const useMap = useMapGeneric<Map>;"],"names":["useMapGeneric"],"mappings":";;;AAOO,MAAM,SAASA;"}
|
|
@@ -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
|
|
@@ -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;"}
|
|
@@ -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 "maplibre-gl";
|
|
4
|
+
import { memo } from "react";
|
|
5
|
+
import { Layer } from "react-map-gl/maplibre";
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main4.mjs","sources":["../../../src/
|
|
1
|
+
{"version":3,"file":"main4.mjs","sources":["../../../src/maplibre/canvas.tsx"],"sourcesContent":["import { extend } from \"@react-three/fiber\";\nimport { MercatorCoordinate } from \"maplibre-gl\";\nimport { memo } from \"react\";\nimport { Layer } from \"react-map-gl/maplibre\";\nimport * as THREE from \"three\";\nimport { useCanvas } from \"../core/use-canvas\";\nimport { CanvasProps } from \"../api/canvas-props\";\n\nextend(THREE);\n\nconst fromLngLat = MercatorCoordinate.fromLngLat\n\n/** react`-three-fiber` canvas inside `MapLibre` */\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;"}
|
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { useRender } from "./main11.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
|