react-three-map 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/main.js +85 -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/main12.mjs +1 -0
- package/dist/es/main12.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 +85 -84
- package/dist/maplibre/es/main.mjs +2 -2
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main10.mjs +19 -20
- package/dist/maplibre/es/main10.mjs.map +1 -1
- package/dist/maplibre/es/main11.mjs +14 -19
- package/dist/maplibre/es/main11.mjs.map +1 -1
- package/dist/maplibre/es/main12.mjs +1 -0
- package/dist/maplibre/es/main12.mjs.map +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/es/main9.mjs +21 -15
- package/dist/maplibre/es/main9.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
|
@@ -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
|
|
@@ -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;"}
|
|
@@ -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
|
|
@@ -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;"}
|
|
@@ -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 "./main11.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
|
|
@@ -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;"}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { useCoords } from "./main7.mjs";
|
|
2
|
+
import { useCreateRoot } from "./main9.mjs";
|
|
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({
|
|
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
|
|
@@ -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;"}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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)
|
|
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 };
|
|
20
|
+
};
|
|
15
21
|
export {
|
|
16
|
-
|
|
22
|
+
useCreateRoot
|
|
17
23
|
};
|
|
18
24
|
//# sourceMappingURL=main9.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main9.mjs","sources":["../../../src/core/
|
|
1
|
+
{"version":3,"file":"main9.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;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export * from './maplibre/canvas';
|
|
1
|
+
import type { Map } from 'maplibre-gl';
|
|
3
2
|
export * from './api/canvas-props';
|
|
4
3
|
export * from './api/coordinates';
|
|
5
|
-
export
|
|
4
|
+
export * from './maplibre/canvas';
|
|
5
|
+
export declare const useMap: () => Map | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export * from './mapbox/canvas';
|
|
1
|
+
import type { Map } from 'mapbox-gl';
|
|
3
2
|
export * from './api/canvas-props';
|
|
4
3
|
export * from './api/coordinates';
|
|
5
|
-
export
|
|
4
|
+
export * from './mapbox/canvas';
|
|
5
|
+
export declare const useMap: () => Map | undefined;
|