react-three-map 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +18 -3
- package/dist/cjs/main.js +35 -18
- package/dist/es/main.mjs +5 -3
- package/dist/es/main.mjs.map +1 -1
- package/dist/es/main10.mjs +8 -33
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +33 -11
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main12.mjs +11 -22
- package/dist/es/main12.mjs.map +1 -1
- package/dist/es/main13.mjs +17 -24
- package/dist/es/main13.mjs.map +1 -1
- package/dist/es/main14.mjs +2 -23
- package/dist/es/main14.mjs.map +1 -1
- package/dist/es/main15.mjs +28 -93
- package/dist/es/main15.mjs.map +1 -1
- package/dist/es/main16.mjs +21 -61
- package/dist/es/main16.mjs.map +1 -1
- package/dist/es/main17.mjs +94 -19
- package/dist/es/main17.mjs.map +1 -1
- package/dist/es/main18.mjs +62 -23
- package/dist/es/main18.mjs.map +1 -1
- package/dist/es/main19.mjs +17 -13
- package/dist/es/main19.mjs.map +1 -1
- package/dist/es/main20.mjs +23 -68
- package/dist/es/main20.mjs.map +1 -1
- package/dist/es/main21.mjs +19 -0
- package/dist/es/main21.mjs.map +1 -0
- package/dist/es/main22.mjs +83 -0
- package/dist/es/main22.mjs.map +1 -0
- package/dist/es/main3.mjs +3 -3
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main4.mjs +3 -3
- package/dist/es/main5.mjs +12 -19
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +19 -15
- package/dist/es/main6.mjs.map +1 -1
- package/dist/es/main7.mjs +10 -22
- package/dist/es/main7.mjs.map +1 -1
- package/dist/es/main8.mjs +22 -26
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +26 -8
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +35 -18
- package/dist/maplibre/es/main.mjs +5 -3
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main10.mjs +8 -33
- package/dist/maplibre/es/main10.mjs.map +1 -1
- package/dist/maplibre/es/main11.mjs +33 -11
- package/dist/maplibre/es/main11.mjs.map +1 -1
- package/dist/maplibre/es/main12.mjs +11 -22
- package/dist/maplibre/es/main12.mjs.map +1 -1
- package/dist/maplibre/es/main13.mjs +17 -24
- package/dist/maplibre/es/main13.mjs.map +1 -1
- package/dist/maplibre/es/main14.mjs +2 -23
- package/dist/maplibre/es/main14.mjs.map +1 -1
- package/dist/maplibre/es/main15.mjs +28 -93
- package/dist/maplibre/es/main15.mjs.map +1 -1
- package/dist/maplibre/es/main16.mjs +21 -61
- package/dist/maplibre/es/main16.mjs.map +1 -1
- package/dist/maplibre/es/main17.mjs +94 -19
- package/dist/maplibre/es/main17.mjs.map +1 -1
- package/dist/maplibre/es/main18.mjs +62 -23
- package/dist/maplibre/es/main18.mjs.map +1 -1
- package/dist/maplibre/es/main19.mjs +17 -13
- package/dist/maplibre/es/main19.mjs.map +1 -1
- package/dist/maplibre/es/main20.mjs +23 -68
- package/dist/maplibre/es/main20.mjs.map +1 -1
- package/dist/maplibre/es/main21.mjs +19 -0
- package/dist/maplibre/es/main21.mjs.map +1 -0
- package/dist/maplibre/es/main22.mjs +83 -0
- package/dist/maplibre/es/main22.mjs.map +1 -0
- package/dist/maplibre/es/main3.mjs +3 -3
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +3 -3
- package/dist/maplibre/es/main5.mjs +12 -19
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/es/main6.mjs +19 -15
- package/dist/maplibre/es/main6.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +10 -22
- package/dist/maplibre/es/main7.mjs.map +1 -1
- package/dist/maplibre/es/main8.mjs +22 -26
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/es/main9.mjs +26 -8
- package/dist/maplibre/es/main9.mjs.map +1 -1
- package/dist/maplibre/types/api/coords-to-vector-3.d.ts +2 -3
- package/dist/maplibre/types/api/index.d.ts +2 -1
- package/dist/maplibre/types/api/vector-3-to-coords.d.ts +3 -0
- package/dist/maplibre/types/core/canvas-overlay/sync-camera-fc.d.ts +2 -1
- package/dist/maplibre/types/core/earth-radius.d.ts +1 -0
- package/dist/types/api/coords-to-vector-3.d.ts +2 -3
- package/dist/types/api/index.d.ts +2 -1
- package/dist/types/api/vector-3-to-coords.d.ts +3 -0
- package/dist/types/core/canvas-overlay/sync-camera-fc.d.ts +2 -1
- package/dist/types/core/earth-radius.d.ts +1 -0
- package/package.json +6 -9
- package/stories/package.json +4 -4
- package/stories/yarn.lock +1931 -1085
- package/vitest.config.ts +1 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main22.mjs","sources":["../../src/core/canvas-overlay/sync-camera-fc.tsx"],"sourcesContent":["import { useFrame, useThree } from \"@react-three/fiber\";\nimport { memo, useEffect, useLayoutEffect, useMemo, useRef } from \"react\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { Coords } from \"../../api/coords\";\nimport { MapInstance } from \"../generic-map\";\nimport { syncCamera } from \"../sync-camera\";\nimport { useCoordsToMatrix } from \"../use-coords-to-matrix\";\nimport { useFunction } from \"../use-function\";\nimport { useR3M } from \"../use-r3m\";\n\ninterface SyncCameraFCProps extends Coords {\n setOnRender?: (callback: () => (mx: Matrix4Tuple) => void) => void,\n /** on `useFrame` it will manually render (used by `<Coordinates>`) */\n manualRender?: boolean,\n onReady?: () => void,\n map: MapInstance,\n}\n\n/** React Component (FC) to sync the Three camera with the map provider */\nexport const SyncCameraFC = memo<SyncCameraFCProps>(({\n latitude, longitude, altitude = 0, setOnRender, manualRender, onReady, map\n}) => {\n\n const mapCanvas = map.getCanvas();\n\n const r3m = useR3M();\n\n const camRef = useRef<PerspectiveCamera>(null);\n\n const camera = useThree(s => s.camera) as PerspectiveCamera;\n const gl = useThree(s => s.gl);\n const threeCanvas = useThree(s => s.gl.domElement);\n const scene = useThree(s => s.scene);\n const advance = useThree(s => s.advance);\n const setSize = useThree(s => s.setSize);\n const set = useThree(s => s.set);\n\n const origin = useCoordsToMatrix({ latitude, longitude, altitude, fromLngLat: r3m.fromLngLat });\n\n const ready = useRef(false);\n\n const triggerRepaint = useMemo(() => map.triggerRepaint, [map]);\n const mapPaintRequests = useRef(0);\n const triggerRepaintOff = useFunction(() => {\n mapPaintRequests.current++;\n })\n\n useFrame(() => {\n syncCamera(camera, origin, r3m.viewProjMx)\n\n if (manualRender) gl.render(scene, camera);\n\n map.triggerRepaint = triggerRepaint;\n if (mapPaintRequests.current > 0) {\n mapPaintRequests.current = 0;\n map.triggerRepaint();\n }\n }, -Infinity)\n\n const onRender = useFunction((viewProjMx: Matrix4Tuple) => {\n map.triggerRepaint = triggerRepaintOff;\n\n if (threeCanvas.width !== mapCanvas.width || threeCanvas.height !== mapCanvas.height) {\n setSize(\n mapCanvas.clientWidth,\n mapCanvas.clientHeight,\n true,\n mapCanvas.offsetTop,\n mapCanvas.offsetLeft,\n );\n }\n\n r3m.viewProjMx = viewProjMx;\n if (!ready.current && onReady) {\n ready.current = true;\n onReady();\n }\n advance(Date.now() * .001, true);\n })\n\n useEffect(() => {\n setOnRender && setOnRender(() => onRender)\n }, [setOnRender, onRender])\n\n useLayoutEffect(() => {\n if (!manualRender) return;\n set({ camera: camRef.current! }); // eslint-disable-line @typescript-eslint/no-non-null-assertion\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n return <>\n {manualRender && <perspectiveCamera\n ref={camRef}\n matrixAutoUpdate={false}\n matrixWorldAutoUpdate={false}\n />}\n </>\n})\n\nSyncCameraFC.displayName = 'SyncCameraFC';"],"names":[],"mappings":";;;;;;;AAmBa,MAAA,eAAe,KAAwB,CAAC;AAAA,EACnD;AAAA,EAAU;AAAA,EAAW,WAAW;AAAA,EAAG;AAAA,EAAa;AAAA,EAAc;AAAA,EAAS;AACzE,MAAM;AAEE,QAAA,YAAY,IAAI;AAEtB,QAAM,MAAM;AAEN,QAAA,SAAS,OAA0B,IAAI;AAE7C,QAAM,SAAS,SAAS,CAAK,MAAA,EAAE,MAAM;AACrC,QAAM,KAAK,SAAS,CAAK,MAAA,EAAE,EAAE;AAC7B,QAAM,cAAc,SAAS,CAAK,MAAA,EAAE,GAAG,UAAU;AACjD,QAAM,QAAQ,SAAS,CAAK,MAAA,EAAE,KAAK;AACnC,QAAM,UAAU,SAAS,CAAK,MAAA,EAAE,OAAO;AACvC,QAAM,UAAU,SAAS,CAAK,MAAA,EAAE,OAAO;AACvC,QAAM,MAAM,SAAS,CAAK,MAAA,EAAE,GAAG;AAEzB,QAAA,SAAS,kBAAkB,EAAE,UAAU,WAAW,UAAU,YAAY,IAAI,WAAA,CAAY;AAExF,QAAA,QAAQ,OAAO,KAAK;AAE1B,QAAM,iBAAiB,QAAQ,MAAM,IAAI,gBAAgB,CAAC,GAAG,CAAC;AACxD,QAAA,mBAAmB,OAAO,CAAC;AAC3B,QAAA,oBAAoB,YAAY,MAAM;AACzB,qBAAA;AAAA,EAAA,CAClB;AAED,WAAS,MAAM;AACF,eAAA,QAAQ,QAAQ,IAAI,UAAU;AAErC,QAAA;AAAiB,SAAA,OAAO,OAAO,MAAM;AAEzC,QAAI,iBAAiB;AACjB,QAAA,iBAAiB,UAAU,GAAG;AAChC,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AAAA,IACrB;AAAA,EAAA,GACC,SAAS;AAEN,QAAA,WAAW,YAAY,CAAC,eAA6B;AACzD,QAAI,iBAAiB;AAErB,QAAI,YAAY,UAAU,UAAU,SAAS,YAAY,WAAW,UAAU,QAAQ;AACpF;AAAA,QACE,UAAU;AAAA,QACV,UAAU;AAAA,QACV;AAAA,QACA,UAAU;AAAA,QACV,UAAU;AAAA,MAAA;AAAA,IAEd;AAEA,QAAI,aAAa;AACb,QAAA,CAAC,MAAM,WAAW,SAAS;AAC7B,YAAM,UAAU;AACR;IACV;AACA,YAAQ,KAAK,IAAQ,IAAA,MAAM,IAAI;AAAA,EAAA,CAChC;AAED,YAAU,MAAM;AACC,mBAAA,YAAY,MAAM,QAAQ;AAAA,EAAA,GACxC,CAAC,aAAa,QAAQ,CAAC;AAE1B,kBAAgB,MAAM;AACpB,QAAI,CAAC;AAAc;AACnB,QAAI,EAAE,QAAQ,OAAO,QAAU,CAAA;AAAA,EACjC,GAAG,CAAE,CAAA;AAEL,yCACG,UAAgB,gBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MAChB,KAAK;AAAA,MACL,kBAAkB;AAAA,MAClB,uBAAuB;AAAA,IAAA;AAAA,EAE3B,EAAA,CAAA;AACF,CAAC;AAED,aAAa,cAAc;"}
|
package/dist/es/main3.mjs
CHANGED
|
@@ -4,9 +4,9 @@ import { MercatorCoordinate } from "mapbox-gl";
|
|
|
4
4
|
import { memo, useState } from "react";
|
|
5
5
|
import { useMap, Layer } from "react-map-gl";
|
|
6
6
|
import * as THREE from "three";
|
|
7
|
-
import { useCanvasInLayer } from "./
|
|
8
|
-
import { InitCanvasFC } from "./
|
|
9
|
-
import { useFunction } from "./
|
|
7
|
+
import { useCanvasInLayer } from "./main8.mjs";
|
|
8
|
+
import { InitCanvasFC } from "./main9.mjs";
|
|
9
|
+
import { useFunction } from "./main10.mjs";
|
|
10
10
|
extend(THREE);
|
|
11
11
|
const fromLngLat = MercatorCoordinate.fromLngLat;
|
|
12
12
|
const Canvas = memo(({ overlay, ...props }) => {
|
package/dist/es/main3.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main3.mjs","sources":["../../src/mapbox/canvas.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"main3.mjs","sources":["../../src/mapbox/canvas.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { extend } from \"@react-three/fiber\";\nimport { MercatorCoordinate } from \"mapbox-gl\";\nimport { memo, useState } from \"react\";\nimport { Layer, useMap } from \"react-map-gl\";\nimport * as THREE from \"three\";\nimport { Matrix4Tuple } from \"three\";\nimport { CanvasProps } from \"../api/canvas-props\";\nimport { useCanvasInLayer } from \"../core/canvas-in-layer/use-canvas-in-layer\";\nimport { InitCanvasFC } from \"../core/canvas-overlay/init-canvas-fc\";\nimport { Render } from \"../core/canvas-overlay/render\";\nimport { MapInstance } from \"../core/generic-map\";\nimport { useFunction } from \"../core/use-function\";\n\nextend(THREE);\n\nconst fromLngLat = MercatorCoordinate.fromLngLat\n\n/** react`-three-fiber` canvas inside `Mapbox` */\nexport const Canvas = memo<CanvasProps>(({ overlay, ...props }) => {\n\n const map = useMap().current!.getMap(); // eslint-disable-line @typescript-eslint/no-non-null-assertion\n\n return <>\n {overlay && <CanvasOverlay map={map} {...props} />}\n {!overlay && <CanvasInLayer map={map} {...props} />}\n </>\n})\nCanvas.displayName = 'Canvas'\n\ninterface CanvasPropsAndMap extends CanvasProps {\n map: MapInstance;\n}\n\nconst CanvasInLayer = memo<CanvasPropsAndMap>(({ map, ...props }) => {\n const layerProps = useCanvasInLayer(props, fromLngLat, map);\n /* @ts-ignore */ // eslint-disable-line @typescript-eslint/ban-ts-comment\n return <Layer {...layerProps} />\n})\nCanvasInLayer.displayName = 'CanvasInLayer';\n\nconst CanvasOverlay = memo<CanvasPropsAndMap>(({ map, id, beforeId, ...props }) => {\n const [onRender, setOnRender] = useState<(mx: Matrix4Tuple) => void>();\n\n const render = useFunction<Render>((_gl, mx) => {\n if (!onRender) return;\n onRender(mx as Matrix4Tuple);\n })\n\n return <>\n {/* @ts-ignore */}\n <Layer id={id} beforeId={beforeId} type=\"custom\" render={render} />\n <InitCanvasFC {...props}\n setOnRender={setOnRender}\n map={map}\n fromLngLat={fromLngLat}\n />\n </>\n})\nCanvasInLayer.displayName = 'CanvasInLayer';"],"names":[],"mappings":";;;;;;;;;AAcA,OAAO,KAAK;AAEZ,MAAM,aAAa,mBAAmB;AAG/B,MAAM,SAAS,KAAkB,CAAC,EAAE,SAAS,GAAG,YAAY;AAEjE,QAAM,MAAM,OAAA,EAAS,QAAS,OAAO;AAErC,SACG,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA,WAAY,oBAAA,eAAA,EAAc,KAAW,GAAG,MAAO,CAAA;AAAA,IAC/C,CAAC,WAAW,oBAAC,eAAc,EAAA,KAAW,GAAG,OAAO;AAAA,EACnD,EAAA,CAAA;AACF,CAAC;AACD,OAAO,cAAc;AAMrB,MAAM,gBAAgB,KAAwB,CAAC,EAAE,KAAK,GAAG,YAAY;AACnE,QAAM,aAAa,iBAAiB,OAAO,YAAY,GAAG;AAEnD,SAAA,oBAAC,OAAO,EAAA,GAAG,WAAY,CAAA;AAChC,CAAC;AACD,cAAc,cAAc;AAE5B,MAAM,gBAAgB,KAAwB,CAAC,EAAE,KAAK,IAAI,UAAU,GAAG,YAAY;AACjF,QAAM,CAAC,UAAU,WAAW,IAAI,SAAqC;AAErE,QAAM,SAAS,YAAoB,CAAC,KAAK,OAAO;AAC9C,QAAI,CAAC;AAAU;AACf,aAAS,EAAkB;AAAA,EAAA,CAC5B;AAED,SAEE,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA,oBAAC,OAAM,EAAA,IAAQ,UAAoB,MAAK,UAAS,QAAgB;AAAA,IACjE;AAAA,MAAC;AAAA,MAAA;AAAA,QAAc,GAAG;AAAA,QAChB;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,IACF;AAAA,EACF,EAAA,CAAA;AACF,CAAC;AACD,cAAc,cAAc;"}
|
package/dist/es/main4.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { createPortal, useThree, useFrame } from "@react-three/fiber";
|
|
3
3
|
import { memo, useState, useRef, useLayoutEffect } from "react";
|
|
4
4
|
import { Scene } from "three";
|
|
5
|
-
import { syncCamera } from "./
|
|
6
|
-
import { useCoordsToMatrix } from "./
|
|
7
|
-
import { useR3M } from "./
|
|
5
|
+
import { syncCamera } from "./main11.mjs";
|
|
6
|
+
import { useCoordsToMatrix } from "./main12.mjs";
|
|
7
|
+
import { useR3M } from "./main13.mjs";
|
|
8
8
|
const Coordinates = memo(({
|
|
9
9
|
latitude,
|
|
10
10
|
longitude,
|
package/dist/es/main5.mjs
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
coords.latitude,
|
|
13
|
-
coords.longitude,
|
|
14
|
-
coords.altitude
|
|
15
|
-
]);
|
|
16
|
-
return /* @__PURE__ */ jsx("object3D", { position: pos, children });
|
|
17
|
-
});
|
|
18
|
-
NearCoordinates.displayName = "NearCoordinates";
|
|
1
|
+
import { MathUtils } from "three";
|
|
2
|
+
import { earthRadius } from "./main14.mjs";
|
|
3
|
+
function coordsToVector3(point, origin) {
|
|
4
|
+
const latitudeDiff = (point.latitude - origin.latitude) * MathUtils.DEG2RAD;
|
|
5
|
+
const longitudeDiff = (point.longitude - origin.longitude) * MathUtils.DEG2RAD;
|
|
6
|
+
const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);
|
|
7
|
+
const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * MathUtils.DEG2RAD);
|
|
8
|
+
const y = altitudeDiff;
|
|
9
|
+
const z = -latitudeDiff * earthRadius;
|
|
10
|
+
return [x, y, z];
|
|
11
|
+
}
|
|
19
12
|
export {
|
|
20
|
-
|
|
13
|
+
coordsToVector3
|
|
21
14
|
};
|
|
22
15
|
//# sourceMappingURL=main5.mjs.map
|
package/dist/es/main5.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main5.mjs","sources":["../../src/api/
|
|
1
|
+
{"version":3,"file":"main5.mjs","sources":["../../src/api/coords-to-vector-3.ts"],"sourcesContent":["import { MathUtils, Vector3Tuple } from 'three';\nimport { Coords } from './coords';\nimport { earthRadius } from \"../core/earth-radius\";\n\nexport function coordsToVector3(point: Coords, origin: Coords): Vector3Tuple {\n const latitudeDiff = (point.latitude - origin.latitude) * MathUtils.DEG2RAD;\n const longitudeDiff = (point.longitude - origin.longitude) * MathUtils.DEG2RAD;\n const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);\n\n const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * MathUtils.DEG2RAD);\n const y = altitudeDiff;\n const z = -latitudeDiff * earthRadius;\n\n return [x, y, z] as Vector3Tuple;\n}\n"],"names":[],"mappings":";;AAIgB,SAAA,gBAAgB,OAAe,QAA8B;AAC3E,QAAM,gBAAgB,MAAM,WAAW,OAAO,YAAY,UAAU;AACpE,QAAM,iBAAiB,MAAM,YAAY,OAAO,aAAa,UAAU;AACvE,QAAM,gBAAgB,MAAM,YAAY,MAAM,OAAO,YAAY;AAE3D,QAAA,IAAI,gBAAgB,cAAc,KAAK,IAAI,OAAO,WAAW,UAAU,OAAO;AACpF,QAAM,IAAI;AACJ,QAAA,IAAI,CAAC,eAAe;AAEnB,SAAA,CAAC,GAAG,GAAG,CAAC;AACjB;"}
|
package/dist/es/main6.mjs
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useMemo } from "react";
|
|
3
|
+
import { useCoords } from "./main15.mjs";
|
|
4
|
+
import { coordsToVector3 } from "./main5.mjs";
|
|
5
|
+
const NearCoordinates = memo(({ children, ...coords }) => {
|
|
6
|
+
const { latitude, longitude, altitude } = useCoords();
|
|
7
|
+
const pos = useMemo(() => coordsToVector3(coords, { latitude, longitude, altitude }), [
|
|
8
|
+
// eslint-disable-line react-hooks/exhaustive-deps
|
|
9
|
+
latitude,
|
|
10
|
+
longitude,
|
|
11
|
+
altitude,
|
|
12
|
+
coords.latitude,
|
|
13
|
+
coords.longitude,
|
|
14
|
+
coords.altitude
|
|
15
|
+
]);
|
|
16
|
+
return /* @__PURE__ */ jsx("object3D", { position: pos, children });
|
|
17
|
+
});
|
|
18
|
+
NearCoordinates.displayName = "NearCoordinates";
|
|
15
19
|
export {
|
|
16
|
-
|
|
20
|
+
NearCoordinates
|
|
17
21
|
};
|
|
18
22
|
//# sourceMappingURL=main6.mjs.map
|
package/dist/es/main6.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main6.mjs","sources":["../../src/api/
|
|
1
|
+
{"version":3,"file":"main6.mjs","sources":["../../src/api/near-coordinates.tsx"],"sourcesContent":["import { memo, useMemo } from \"react\";\nimport { useCoords } from \"../core/use-coords\";\nimport { CoordinatesProps } from \"./coordinates\";\nimport { coordsToVector3 } from \"./coords-to-vector-3\";\n\nexport const NearCoordinates = memo<CoordinatesProps>(({children, ...coords})=>{\n const {latitude, longitude, altitude} = useCoords();\n const pos = useMemo(()=>coordsToVector3(coords, {latitude, longitude, altitude}), [ // eslint-disable-line react-hooks/exhaustive-deps\n latitude, longitude, altitude, coords.latitude, coords.longitude, coords.altitude\n ]);\n return <object3D position={pos}>{children}</object3D>\n})\nNearCoordinates.displayName = 'NearCoordinates';"],"names":[],"mappings":";;;;AAKO,MAAM,kBAAkB,KAAuB,CAAC,EAAC,UAAU,GAAG,aAAU;AAC7E,QAAM,EAAC,UAAU,WAAW,aAAY,UAAU;AAC5C,QAAA,MAAM,QAAQ,MAAI,gBAAgB,QAAQ,EAAC,UAAU,WAAW,SAAQ,CAAC,GAAG;AAAA;AAAA,IAChF;AAAA,IAAU;AAAA,IAAW;AAAA,IAAU,OAAO;AAAA,IAAU,OAAO;AAAA,IAAW,OAAO;AAAA,EAAA,CAC1E;AACD,SAAQ,oBAAA,YAAA,EAAS,UAAU,KAAM,SAAS,CAAA;AAC5C,CAAC;AACD,gBAAgB,cAAc;"}
|
package/dist/es/main7.mjs
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
fromLngLat
|
|
11
|
-
});
|
|
12
|
-
const { onRemove, useThree, r3m } = useRoot(fromLngLat, map, props);
|
|
13
|
-
const render = useRender({ origin, frameloop, useThree, map, r3m });
|
|
14
|
-
return {
|
|
15
|
-
id: props.id,
|
|
16
|
-
beforeId: props.beforeId,
|
|
17
|
-
onRemove,
|
|
18
|
-
render,
|
|
19
|
-
type: "custom",
|
|
20
|
-
renderingMode: "3d"
|
|
21
|
-
};
|
|
1
|
+
import { MathUtils } from "three";
|
|
2
|
+
import { earthRadius } from "./main14.mjs";
|
|
3
|
+
function vector3ToCoords(position, origin) {
|
|
4
|
+
const [x, y, z] = position;
|
|
5
|
+
const latitude = origin.latitude + -z / earthRadius * MathUtils.RAD2DEG;
|
|
6
|
+
const longitude = origin.longitude + x / earthRadius * MathUtils.RAD2DEG / Math.cos(origin.latitude * MathUtils.DEG2RAD);
|
|
7
|
+
const altitude = (origin.altitude || 0) + y;
|
|
8
|
+
const coords = { latitude, longitude, altitude };
|
|
9
|
+
return coords;
|
|
22
10
|
}
|
|
23
11
|
export {
|
|
24
|
-
|
|
12
|
+
vector3ToCoords
|
|
25
13
|
};
|
|
26
14
|
//# sourceMappingURL=main7.mjs.map
|
package/dist/es/main7.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main7.mjs","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"main7.mjs","sources":["../../src/api/vector-3-to-coords.ts"],"sourcesContent":["import { MathUtils, Vector3Tuple } from \"three\";\nimport { Coords } from \"./coords\";\nimport { earthRadius } from \"../core/earth-radius\";\n\nexport function vector3ToCoords(position: Vector3Tuple, origin: Coords): Coords {\n const [x, y, z] = position;\n const latitude = origin.latitude + (-z / earthRadius) * MathUtils.RAD2DEG;\n const longitude = origin.longitude + (x / earthRadius) * MathUtils.RAD2DEG / Math.cos(origin.latitude * MathUtils.DEG2RAD);\n const altitude = (origin.altitude || 0) + y;\n const coords: Coords = { latitude, longitude, altitude };\n return coords;\n}"],"names":[],"mappings":";;AAIgB,SAAA,gBAAgB,UAAwB,QAAwB;AAC9E,QAAM,CAAC,GAAG,GAAG,CAAC,IAAI;AAClB,QAAM,WAAW,OAAO,WAAY,CAAC,IAAI,cAAe,UAAU;AAClE,QAAM,YAAY,OAAO,YAAa,IAAI,cAAe,UAAU,UAAU,KAAK,IAAI,OAAO,WAAW,UAAU,OAAO;AACnH,QAAA,YAAY,OAAO,YAAY,KAAK;AAC1C,QAAM,SAAiB,EAAE,UAAU,WAAW,SAAS;AAChD,SAAA;AACT;"}
|
package/dist/es/main8.mjs
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
el2.style.bottom = "0";
|
|
12
|
-
el2.style.left = "0";
|
|
13
|
-
el2.style.right = "0";
|
|
14
|
-
el2.style.pointerEvents = "none";
|
|
15
|
-
return el2;
|
|
1
|
+
import { useCoordsToMatrix } from "./main12.mjs";
|
|
2
|
+
import { useRender } from "./main16.mjs";
|
|
3
|
+
import { useRoot } from "./main17.mjs";
|
|
4
|
+
function useCanvasInLayer(props, fromLngLat, map) {
|
|
5
|
+
const { latitude, longitude, altitude, frameloop } = props;
|
|
6
|
+
const origin = useCoordsToMatrix({
|
|
7
|
+
latitude,
|
|
8
|
+
longitude,
|
|
9
|
+
altitude,
|
|
10
|
+
fromLngLat
|
|
16
11
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
const { onRemove, useThree, r3m } = useRoot(fromLngLat, map, props);
|
|
13
|
+
const render = useRender({ origin, frameloop, useThree, map, r3m });
|
|
14
|
+
return {
|
|
15
|
+
id: props.id,
|
|
16
|
+
beforeId: props.beforeId,
|
|
17
|
+
onRemove,
|
|
18
|
+
render,
|
|
19
|
+
type: "custom",
|
|
20
|
+
renderingMode: "3d"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
27
23
|
export {
|
|
28
|
-
|
|
24
|
+
useCanvasInLayer
|
|
29
25
|
};
|
|
30
26
|
//# sourceMappingURL=main8.mjs.map
|
package/dist/es/main8.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main8.mjs","sources":["../../src/core/canvas-
|
|
1
|
+
{"version":3,"file":"main8.mjs","sources":["../../src/core/canvas-in-layer/use-canvas-in-layer.tsx"],"sourcesContent":["import { CanvasProps } from \"../../api/canvas-props\";\nimport { FromLngLat, MapInstance } from \"../generic-map\";\nimport { useCoordsToMatrix } from \"../use-coords-to-matrix\";\nimport { useRender } from \"./use-render\";\nimport { useRoot } from \"./use-root\";\n\n/** get all the properties that you need to render as a map `<Layer>` */\nexport function useCanvasInLayer(props: CanvasProps,fromLngLat: FromLngLat, map: MapInstance) {\n\n const {latitude, longitude, altitude, frameloop } = props;\n\n const origin = useCoordsToMatrix({\n latitude, longitude, altitude, fromLngLat,\n });\n\n const { onRemove, useThree, r3m } = useRoot(fromLngLat, map, props);\n \n const render = useRender({origin, frameloop, useThree, map, r3m});\n \n return {\n id: props.id,\n beforeId: props.beforeId,\n onRemove,\n render,\n type: 'custom',\n renderingMode: '3d'\n } as const\n\n}"],"names":[],"mappings":";;;AAOgB,SAAA,iBAAiB,OAAmB,YAAwB,KAAkB;AAE5F,QAAM,EAAC,UAAU,WAAW,UAAU,cAAc;AAElD,QAAM,SAAS,kBAAkB;AAAA,IAC/B;AAAA,IAAU;AAAA,IAAW;AAAA,IAAU;AAAA,EAAA,CAChC;AAEK,QAAA,EAAE,UAAU,UAAU,IAAA,IAAQ,QAAQ,YAAY,KAAK,KAAK;AAE5D,QAAA,SAAS,UAAU,EAAC,QAAQ,WAAW,UAAU,KAAK,KAAI;AAEzD,SAAA;AAAA,IACL,IAAI,MAAM;AAAA,IACV,UAAU,MAAM;AAAA,IAChB;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,eAAe;AAAA,EAAA;AAGrB;"}
|
package/dist/es/main9.mjs
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useState, useEffect } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import { CanvasPortal } from "./main18.mjs";
|
|
5
|
+
const InitCanvasFC = memo((props) => {
|
|
6
|
+
const canvas = props.map.getCanvas();
|
|
7
|
+
const [el] = useState(() => {
|
|
8
|
+
const el2 = document.createElement("div");
|
|
9
|
+
el2.style.position = "absolute";
|
|
10
|
+
el2.style.top = "0";
|
|
11
|
+
el2.style.bottom = "0";
|
|
12
|
+
el2.style.left = "0";
|
|
13
|
+
el2.style.right = "0";
|
|
14
|
+
el2.style.pointerEvents = "none";
|
|
15
|
+
return el2;
|
|
16
|
+
});
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const parent = canvas.parentElement;
|
|
19
|
+
parent.appendChild(el);
|
|
20
|
+
return () => {
|
|
21
|
+
parent.removeChild(el);
|
|
22
|
+
};
|
|
7
23
|
}, []);
|
|
8
|
-
};
|
|
24
|
+
return /* @__PURE__ */ jsx(Fragment, { children: createPortal(/* @__PURE__ */ jsx(CanvasPortal, { ...props }), el) });
|
|
25
|
+
});
|
|
26
|
+
InitCanvasFC.displayName = "InitCanvasFC";
|
|
9
27
|
export {
|
|
10
|
-
|
|
28
|
+
InitCanvasFC
|
|
11
29
|
};
|
|
12
30
|
//# 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/canvas-overlay/init-canvas-fc.tsx"],"sourcesContent":["import { memo, useEffect, useState } from \"react\";\nimport { createPortal } from 'react-dom';\nimport { Matrix4Tuple } from \"three\";\nimport { CanvasProps } from \"../../api/canvas-props\";\nimport { FromLngLat, MapInstance } from \"../generic-map\";\nimport { CanvasPortal } from \"./canvas-portal\";\n\ninterface InitCanvasFCProps extends CanvasProps {\n map: MapInstance,\n setOnRender: (callback: () => (mx: Matrix4Tuple) => void) => void,\n frameloop?: 'always' | 'demand',\n fromLngLat: FromLngLat,\n}\nexport const InitCanvasFC = memo<InitCanvasFCProps>((props) => {\n const canvas = props.map.getCanvas() // eslint-disable-line @typescript-eslint/no-non-null-assertion\n\n const [el] = useState(() => {\n const el = document.createElement('div');\n el.style.position = 'absolute';\n el.style.top = '0';\n el.style.bottom = '0';\n el.style.left = '0';\n el.style.right = '0';\n el.style.pointerEvents = 'none';\n return el\n })\n\n useEffect(() => {\n const parent = canvas.parentElement!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n parent.appendChild(el);\n return () => {\n parent.removeChild(el);\n }\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n return <>\n {createPortal((\n <CanvasPortal {...props} />\n ), el)}\n </>\n})\nInitCanvasFC.displayName = 'InitCanvasFC';\n"],"names":["el"],"mappings":";;;;AAaa,MAAA,eAAe,KAAwB,CAAC,UAAU;AACvD,QAAA,SAAS,MAAM,IAAI,UAAU;AAEnC,QAAM,CAAC,EAAE,IAAI,SAAS,MAAM;AACpBA,UAAAA,MAAK,SAAS,cAAc,KAAK;AACvCA,QAAG,MAAM,WAAW;AACpBA,QAAG,MAAM,MAAM;AACfA,QAAG,MAAM,SAAS;AAClBA,QAAG,MAAM,OAAO;AAChBA,QAAG,MAAM,QAAQ;AACjBA,QAAG,MAAM,gBAAgB;AAClBA,WAAAA;AAAAA,EAAA,CACR;AAED,YAAU,MAAM;AACd,UAAM,SAAS,OAAO;AACtB,WAAO,YAAY,EAAE;AACrB,WAAO,MAAM;AACX,aAAO,YAAY,EAAE;AAAA,IAAA;AAAA,EAEzB,GAAG,CAAE,CAAA;AACE,SAAA,oBAAA,UAAA,EACJ,uBACE,oBAAA,cAAA,EAAc,GAAG,MAAO,CAAA,GACxB,EAAE,EACP,CAAA;AACF,CAAC;AACD,aAAa,cAAc;"}
|
|
@@ -7,7 +7,6 @@ const react = require("react");
|
|
|
7
7
|
const reactMapGl = require("react-map-gl");
|
|
8
8
|
const THREE = require("three");
|
|
9
9
|
const reactDom = require("react-dom");
|
|
10
|
-
const turf = require("@turf/turf");
|
|
11
10
|
function _interopNamespaceDefault(e) {
|
|
12
11
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
12
|
if (e) {
|
|
@@ -148,6 +147,16 @@ function RenderAtCoords({ r3m, origin }) {
|
|
|
148
147
|
}, [set, r3m]);
|
|
149
148
|
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
150
149
|
}
|
|
150
|
+
const earthRadius = 6378137;
|
|
151
|
+
function coordsToVector3(point, origin) {
|
|
152
|
+
const latitudeDiff = (point.latitude - origin.latitude) * THREE.MathUtils.DEG2RAD;
|
|
153
|
+
const longitudeDiff = (point.longitude - origin.longitude) * THREE.MathUtils.DEG2RAD;
|
|
154
|
+
const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);
|
|
155
|
+
const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * THREE.MathUtils.DEG2RAD);
|
|
156
|
+
const y = altitudeDiff;
|
|
157
|
+
const z = -latitudeDiff * earthRadius;
|
|
158
|
+
return [x, y, z];
|
|
159
|
+
}
|
|
151
160
|
function useCoords() {
|
|
152
161
|
const coords = fiber.useThree((s) => s.coords);
|
|
153
162
|
return coords;
|
|
@@ -172,18 +181,6 @@ function useSetRootCoords(store, {
|
|
|
172
181
|
function setCoords(store, coords) {
|
|
173
182
|
store.setState({ coords });
|
|
174
183
|
}
|
|
175
|
-
function coordsToVector3(point, origin) {
|
|
176
|
-
const originCoords = [origin.longitude, origin.latitude, origin.altitude || 0];
|
|
177
|
-
const pointCoords = [point.longitude, point.latitude, point.altitude || 0];
|
|
178
|
-
const dist = turf.distance(originCoords, pointCoords, { units: "meters" });
|
|
179
|
-
const angle = turf.bearing(originCoords, pointCoords);
|
|
180
|
-
const adjustedAngle = angle - 90;
|
|
181
|
-
const x = dist * Math.cos(adjustedAngle * THREE.MathUtils.DEG2RAD);
|
|
182
|
-
const y = (point.altitude || 0) - (origin.altitude || 0);
|
|
183
|
-
const z = dist * Math.sin(adjustedAngle * THREE.MathUtils.DEG2RAD);
|
|
184
|
-
const v3 = [x, y, z];
|
|
185
|
-
return v3;
|
|
186
|
-
}
|
|
187
184
|
const NearCoordinates = react.memo(({ children, ...coords }) => {
|
|
188
185
|
const { latitude, longitude, altitude } = useCoords();
|
|
189
186
|
const pos2 = react.useMemo(() => coordsToVector3(coords, { latitude, longitude, altitude }), [
|
|
@@ -198,6 +195,14 @@ const NearCoordinates = react.memo(({ children, ...coords }) => {
|
|
|
198
195
|
return /* @__PURE__ */ jsxRuntime.jsx("object3D", { position: pos2, children });
|
|
199
196
|
});
|
|
200
197
|
NearCoordinates.displayName = "NearCoordinates";
|
|
198
|
+
function vector3ToCoords(position, origin) {
|
|
199
|
+
const [x, y, z] = position;
|
|
200
|
+
const latitude = origin.latitude + -z / earthRadius * THREE.MathUtils.RAD2DEG;
|
|
201
|
+
const longitude = origin.longitude + x / earthRadius * THREE.MathUtils.RAD2DEG / Math.cos(origin.latitude * THREE.MathUtils.DEG2RAD);
|
|
202
|
+
const altitude = (origin.altitude || 0) + y;
|
|
203
|
+
const coords = { latitude, longitude, altitude };
|
|
204
|
+
return coords;
|
|
205
|
+
}
|
|
201
206
|
const useFunction = (callback) => {
|
|
202
207
|
const callbackRef = react.useRef(callback);
|
|
203
208
|
callbackRef.current = callback;
|
|
@@ -370,8 +375,9 @@ const SyncCameraFC = react.memo(({
|
|
|
370
375
|
setOnRender,
|
|
371
376
|
manualRender,
|
|
372
377
|
onReady,
|
|
373
|
-
|
|
378
|
+
map
|
|
374
379
|
}) => {
|
|
380
|
+
const mapCanvas = map.getCanvas();
|
|
375
381
|
const r3m = useR3M();
|
|
376
382
|
const camRef = react.useRef(null);
|
|
377
383
|
const camera = fiber.useThree((s) => s.camera);
|
|
@@ -383,13 +389,23 @@ const SyncCameraFC = react.memo(({
|
|
|
383
389
|
const set = fiber.useThree((s) => s.set);
|
|
384
390
|
const origin = useCoordsToMatrix({ latitude, longitude, altitude, fromLngLat: r3m.fromLngLat });
|
|
385
391
|
const ready = react.useRef(false);
|
|
392
|
+
const triggerRepaint = react.useMemo(() => map.triggerRepaint, [map]);
|
|
393
|
+
const mapPaintRequests = react.useRef(0);
|
|
394
|
+
const triggerRepaintOff = useFunction(() => {
|
|
395
|
+
mapPaintRequests.current++;
|
|
396
|
+
});
|
|
386
397
|
fiber.useFrame(() => {
|
|
387
398
|
syncCamera(camera, origin, r3m.viewProjMx);
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
|
|
399
|
+
if (manualRender)
|
|
400
|
+
gl.render(scene, camera);
|
|
401
|
+
map.triggerRepaint = triggerRepaint;
|
|
402
|
+
if (mapPaintRequests.current > 0) {
|
|
403
|
+
mapPaintRequests.current = 0;
|
|
404
|
+
map.triggerRepaint();
|
|
405
|
+
}
|
|
391
406
|
}, -Infinity);
|
|
392
407
|
const onRender = useFunction((viewProjMx) => {
|
|
408
|
+
map.triggerRepaint = triggerRepaintOff;
|
|
393
409
|
if (threeCanvas.width !== mapCanvas.width || threeCanvas.height !== mapCanvas.height) {
|
|
394
410
|
setSize(
|
|
395
411
|
mapCanvas.clientWidth,
|
|
@@ -470,7 +486,7 @@ const CanvasPortal = react.memo(({
|
|
|
470
486
|
altitude,
|
|
471
487
|
setOnRender,
|
|
472
488
|
onReady,
|
|
473
|
-
|
|
489
|
+
map
|
|
474
490
|
}
|
|
475
491
|
),
|
|
476
492
|
ready && children
|
|
@@ -543,3 +559,4 @@ exports.Coordinates = Coordinates;
|
|
|
543
559
|
exports.NearCoordinates = NearCoordinates;
|
|
544
560
|
exports.coordsToVector3 = coordsToVector3;
|
|
545
561
|
exports.useMap = useMap;
|
|
562
|
+
exports.vector3ToCoords = vector3ToCoords;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useMap as useMap$1 } from "./main2.mjs";
|
|
2
2
|
import { Canvas } from "./main3.mjs";
|
|
3
3
|
import { Coordinates } from "./main4.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { coordsToVector3 } from "./main5.mjs";
|
|
5
|
+
import { NearCoordinates } from "./main6.mjs";
|
|
6
|
+
import { vector3ToCoords } from "./main7.mjs";
|
|
6
7
|
const useMap = useMap$1;
|
|
7
8
|
export {
|
|
8
9
|
Canvas,
|
|
9
10
|
Coordinates,
|
|
10
11
|
NearCoordinates,
|
|
11
12
|
coordsToVector3,
|
|
12
|
-
useMap
|
|
13
|
+
useMap,
|
|
14
|
+
vector3ToCoords
|
|
13
15
|
};
|
|
14
16
|
//# sourceMappingURL=main.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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';\nexport * from './mapbox/canvas';\n\nexport const useMap = useMapGeneric<Map>;\n"],"names":["useMapGeneric"],"mappings":"
|
|
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';\nexport * from './mapbox/canvas';\n\nexport const useMap = useMapGeneric<Map>;\n"],"names":["useMapGeneric"],"mappings":";;;;;;AAMO,MAAM,SAASA;"}
|
|
@@ -1,37 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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);
|
|
1
|
+
import { useRef, useCallback } from "react";
|
|
2
|
+
const useFunction = (callback) => {
|
|
3
|
+
const callbackRef = useRef(callback);
|
|
4
|
+
callbackRef.current = callback;
|
|
5
|
+
return useCallback((...args) => {
|
|
6
|
+
return callbackRef.current(...args);
|
|
7
|
+
}, []);
|
|
27
8
|
};
|
|
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
|
-
}
|
|
34
9
|
export {
|
|
35
|
-
|
|
10
|
+
useFunction
|
|
36
11
|
};
|
|
37
12
|
//# sourceMappingURL=main10.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main10.mjs","sources":["../../../src/core/
|
|
1
|
+
{"version":3,"file":"main10.mjs","sources":["../../../src/core/use-function.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const useFunction = <T extends (...args: any[]) => any>(callback: T): T => {\n const callbackRef = useRef(callback);\n callbackRef.current = callback;\n return useCallback((...args: any[]) => {\n return callbackRef.current(...args);\n }, []) as T;\n};\n"],"names":[],"mappings":";AAGa,MAAA,cAAc,CAAoC,aAAmB;AAC1E,QAAA,cAAc,OAAO,QAAQ;AACnC,cAAY,UAAU;AACf,SAAA,YAAY,IAAI,SAAgB;AAC9B,WAAA,YAAY,QAAQ,GAAG,IAAI;AAAA,EACpC,GAAG,CAAE,CAAA;AACP;"}
|
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
33
|
}
|
|
12
34
|
export {
|
|
13
|
-
|
|
35
|
+
syncCamera
|
|
14
36
|
};
|
|
15
37
|
//# sourceMappingURL=main11.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main11.mjs","sources":["../../../src/core/
|
|
1
|
+
{"version":3,"file":"main11.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;"}
|