react-three-map 0.8.1 → 1.0.0-next.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 +19 -0
- package/README.md +41 -24
- package/dist/cjs/main.js +1283 -44
- package/dist/es/main.mjs +2 -1
- package/dist/es/main10.mjs +71 -10
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +12 -35
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main12.mjs +12 -13
- package/dist/es/main12.mjs.map +1 -1
- package/dist/es/main13.mjs +42 -24
- package/dist/es/main13.mjs.map +1 -1
- package/dist/es/main14.mjs +13 -4
- package/dist/es/main14.mjs.map +1 -1
- package/dist/es/main15.mjs +22 -31
- package/dist/es/main15.mjs.map +1 -1
- package/dist/es/main16.mjs +87 -22
- package/dist/es/main16.mjs.map +1 -1
- package/dist/es/main17.mjs +14 -94
- package/dist/es/main17.mjs.map +1 -1
- package/dist/es/main18.mjs +22 -62
- package/dist/es/main18.mjs.map +1 -1
- package/dist/es/main19.mjs +27 -20
- package/dist/es/main19.mjs.map +1 -1
- package/dist/es/main20.mjs +8 -23
- package/dist/es/main20.mjs.map +1 -1
- package/dist/es/main21.mjs +34 -16
- package/dist/es/main21.mjs.map +1 -1
- package/dist/es/main22.mjs +12 -80
- package/dist/es/main22.mjs.map +1 -1
- package/dist/es/main23.mjs +26 -0
- package/dist/es/main23.mjs.map +1 -0
- package/dist/es/main24.mjs +5 -0
- package/dist/es/main24.mjs.map +1 -0
- package/dist/es/main25.mjs +33 -0
- package/dist/es/main25.mjs.map +1 -0
- package/dist/es/main26.mjs +27 -0
- package/dist/es/main26.mjs.map +1 -0
- package/dist/es/main27.mjs +98 -0
- package/dist/es/main27.mjs.map +1 -0
- package/dist/es/main28.mjs +66 -0
- package/dist/es/main28.mjs.map +1 -0
- package/dist/es/main29.mjs +23 -0
- package/dist/es/main29.mjs.map +1 -0
- package/dist/es/main3.mjs +13 -4
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main30.mjs +27 -0
- package/dist/es/main30.mjs.map +1 -0
- package/dist/es/main31.mjs +19 -0
- package/dist/es/main31.mjs.map +1 -0
- package/dist/es/main32.mjs +83 -0
- package/dist/es/main32.mjs.map +1 -0
- package/dist/es/main33.mjs +501 -0
- package/dist/es/main33.mjs.map +1 -0
- package/dist/es/main34.mjs +90 -0
- package/dist/es/main34.mjs.map +1 -0
- package/dist/es/main35.mjs +6 -0
- package/dist/es/main35.mjs.map +1 -0
- package/dist/es/main36.mjs +26 -0
- package/dist/es/main36.mjs.map +1 -0
- package/dist/es/main37.mjs +19 -0
- package/dist/es/main37.mjs.map +1 -0
- package/dist/es/main38.mjs +50 -0
- package/dist/es/main38.mjs.map +1 -0
- package/dist/es/main39.mjs +31 -0
- package/dist/es/main39.mjs.map +1 -0
- package/dist/es/main4.mjs +3 -3
- package/dist/es/main40.mjs +9 -0
- package/dist/es/main40.mjs.map +1 -0
- package/dist/es/main41.mjs +62 -0
- package/dist/es/main41.mjs.map +1 -0
- package/dist/es/main42.mjs +42 -0
- package/dist/es/main42.mjs.map +1 -0
- package/dist/es/main5.mjs +22 -2
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +1 -1
- package/dist/es/main7.mjs +1 -1
- package/dist/es/main8.mjs +87 -20
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +80 -24
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +30 -9
- package/dist/maplibre/es/main.mjs +2 -1
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main14.mjs +1 -1
- package/dist/maplibre/es/main14.mjs.map +1 -1
- package/dist/maplibre/es/main16.mjs +2 -1
- package/dist/maplibre/es/main16.mjs.map +1 -1
- package/dist/maplibre/es/main3.mjs +2 -2
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main5.mjs +21 -1
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/types/api/coords-to-vector-3.d.ts +1 -0
- package/dist/maplibre/types/core/canvas-in-layer/use-canvas-in-layer.d.ts +5 -1
- package/dist/maplibre/types/core/canvas-in-layer/use-render.d.ts +5 -1
- package/dist/maplibre/types/core/earth-radius.d.ts +1 -1
- package/dist/maplibre/types/core/generic-map.d.ts +2 -2
- package/dist/maplibre/types/{mapbox → maplibre}/canvas.d.ts +1 -1
- package/dist/maplibre/types/maplibre.index.d.ts +1 -1
- package/dist/types/api/coords-to-vector-3.d.ts +1 -0
- package/dist/types/core/canvas-in-layer/use-canvas-in-layer.d.ts +5 -1
- package/dist/types/core/canvas-in-layer/use-render.d.ts +5 -1
- package/dist/types/core/earth-radius.d.ts +1 -1
- package/dist/types/core/generic-map.d.ts +2 -2
- package/dist/types/mapbox/canvas.d.ts +1 -1
- package/made-with/studio-carto-urban-project.webp +0 -0
- package/package.json +7 -7
- package/stories/package.json +4 -4
- package/stories/yarn.lock +175 -98
package/dist/es/main17.mjs
CHANGED
|
@@ -1,98 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
root2.configure({
|
|
14
|
-
dpr: window.devicePixelRatio,
|
|
15
|
-
events,
|
|
16
|
-
...props,
|
|
17
|
-
frameloop: "never",
|
|
18
|
-
gl: {
|
|
19
|
-
context: gl,
|
|
20
|
-
autoClear: false,
|
|
21
|
-
antialias: true,
|
|
22
|
-
...props == null ? void 0 : props.gl
|
|
23
|
-
},
|
|
24
|
-
onCreated: (state) => {
|
|
25
|
-
state.gl.forceContextLoss = () => {
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
camera: {
|
|
29
|
-
matrixAutoUpdate: false,
|
|
30
|
-
near: 0
|
|
31
|
-
},
|
|
32
|
-
size: {
|
|
33
|
-
width: canvas2.clientWidth,
|
|
34
|
-
height: canvas2.clientHeight,
|
|
35
|
-
top: canvas2.offsetTop,
|
|
36
|
-
left: canvas2.offsetLeft,
|
|
37
|
-
updateStyle: false,
|
|
38
|
-
...props == null ? void 0 : props.size
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const store = _roots.get(canvas2).store;
|
|
42
|
-
const r3m2 = initR3M({ map, fromLngLat, store });
|
|
43
|
-
setCoords(store, { longitude, latitude, altitude });
|
|
44
|
-
if (frameloop === "demand") {
|
|
45
|
-
store.setState({
|
|
46
|
-
frameloop,
|
|
47
|
-
invalidate: () => {
|
|
48
|
-
map.triggerRepaint();
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return { root: root2, useThree: store, map, canvas: canvas2, r3m: r3m2 };
|
|
53
|
-
});
|
|
54
|
-
const onResize = useFunction(() => {
|
|
55
|
-
const { setDpr, setSize } = useThree.getState();
|
|
56
|
-
setDpr(window.devicePixelRatio);
|
|
57
|
-
setSize(
|
|
58
|
-
canvas.clientWidth,
|
|
59
|
-
canvas.clientHeight,
|
|
60
|
-
false,
|
|
61
|
-
canvas.offsetTop,
|
|
62
|
-
canvas.offsetLeft
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
const onRemove = useFunction(() => {
|
|
66
|
-
root.unmount();
|
|
67
|
-
});
|
|
68
|
-
useSetRootCoords(useThree, { longitude, latitude, altitude });
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (frameloop !== "demand")
|
|
71
|
-
return;
|
|
72
|
-
const setState = useThree.setState;
|
|
73
|
-
const { invalidate } = useThree.getState();
|
|
74
|
-
setState({
|
|
75
|
-
frameloop,
|
|
76
|
-
invalidate: () => {
|
|
77
|
-
map.triggerRepaint();
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return () => {
|
|
81
|
-
setState({ frameloop: "never", invalidate });
|
|
82
|
-
};
|
|
83
|
-
}, [frameloop]);
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
map.on("resize", onResize);
|
|
86
|
-
return () => {
|
|
87
|
-
map.off("resize", onResize);
|
|
88
|
-
};
|
|
89
|
-
}, []);
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
root.render(/* @__PURE__ */ jsx(Fragment, { children: props.children }));
|
|
92
|
-
}, [props.children]);
|
|
93
|
-
return { onRemove, useThree, r3m };
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
3
|
+
import { MapContext } from "./main8.mjs";
|
|
4
|
+
const MountedMapsContext = React.createContext(null);
|
|
5
|
+
function useMap() {
|
|
6
|
+
var _a;
|
|
7
|
+
const maps = (_a = useContext(MountedMapsContext)) == null ? void 0 : _a.maps;
|
|
8
|
+
const currentMap = useContext(MapContext);
|
|
9
|
+
const mapsWithCurrent = useMemo(() => {
|
|
10
|
+
return { ...maps, current: currentMap == null ? void 0 : currentMap.map };
|
|
11
|
+
}, [maps, currentMap]);
|
|
12
|
+
return mapsWithCurrent;
|
|
94
13
|
}
|
|
95
14
|
export {
|
|
96
|
-
|
|
15
|
+
MountedMapsContext,
|
|
16
|
+
useMap
|
|
97
17
|
};
|
|
98
18
|
//# sourceMappingURL=main17.mjs.map
|
package/dist/es/main17.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main17.mjs","sources":["../../
|
|
1
|
+
{"version":3,"file":"main17.mjs","sources":["../../node_modules/@vis.gl/react-mapbox/dist/components/use-map.js"],"sourcesContent":["import * as React from 'react';\nimport { useState, useCallback, useMemo, useContext } from 'react';\nimport { MapContext } from \"./map.js\";\nexport const MountedMapsContext = React.createContext(null);\nexport const MapProvider = props => {\n const [maps, setMaps] = useState({});\n const onMapMount = useCallback((map, id = 'default') => {\n setMaps(currMaps => {\n if (id === 'current') {\n throw new Error(\"'current' cannot be used as map id\");\n }\n if (currMaps[id]) {\n throw new Error(`Multiple maps with the same id: ${id}`);\n }\n return { ...currMaps, [id]: map };\n });\n }, []);\n const onMapUnmount = useCallback((id = 'default') => {\n setMaps(currMaps => {\n if (currMaps[id]) {\n const nextMaps = { ...currMaps };\n delete nextMaps[id];\n return nextMaps;\n }\n return currMaps;\n });\n }, []);\n return (React.createElement(MountedMapsContext.Provider, { value: {\n maps,\n onMapMount,\n onMapUnmount\n } }, props.children));\n};\nexport function useMap() {\n const maps = useContext(MountedMapsContext)?.maps;\n const currentMap = useContext(MapContext);\n const mapsWithCurrent = useMemo(() => {\n return { ...maps, current: currentMap?.map };\n }, [maps, currentMap]);\n return mapsWithCurrent;\n}\n//# sourceMappingURL=use-map.js.map"],"names":[],"mappings":";;;AAGY,MAAC,qBAAqB,MAAM,cAAc,IAAI;AA8BnD,SAAS,SAAS;;AACrB,QAAM,QAAO,gBAAW,kBAAkB,MAA7B,mBAAgC;AAC7C,QAAM,aAAa,WAAW,UAAU;AACxC,QAAM,kBAAkB,QAAQ,MAAM;AAClC,WAAO,EAAE,GAAG,MAAM,SAAS,yCAAY,IAAG;AAAA,EAClD,GAAO,CAAC,MAAM,UAAU,CAAC;AACrB,SAAO;AACX;","x_google_ignoreList":[0]}
|
package/dist/es/main18.mjs
CHANGED
|
@@ -1,66 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
longitude,
|
|
12
|
-
altitude,
|
|
13
|
-
setOnRender,
|
|
14
|
-
map,
|
|
15
|
-
fromLngLat,
|
|
16
|
-
...props
|
|
17
|
-
}) => {
|
|
18
|
-
const mapCanvas = map.getCanvas();
|
|
19
|
-
const eventSource = mapCanvas.parentElement;
|
|
20
|
-
const [ready, setReady] = useState(false);
|
|
21
|
-
const onReady = useFunction(() => {
|
|
22
|
-
setReady(true);
|
|
1
|
+
import { useCoordsToMatrix } from "./main22.mjs";
|
|
2
|
+
import { useRender } from "./main26.mjs";
|
|
3
|
+
import { useRoot } from "./main27.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
|
|
23
11
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
children: [
|
|
36
|
-
/* @__PURE__ */ jsx(
|
|
37
|
-
InitR3M,
|
|
38
|
-
{
|
|
39
|
-
map,
|
|
40
|
-
fromLngLat,
|
|
41
|
-
latitude,
|
|
42
|
-
longitude,
|
|
43
|
-
altitude
|
|
44
|
-
}
|
|
45
|
-
),
|
|
46
|
-
/* @__PURE__ */ jsx(
|
|
47
|
-
SyncCameraFC,
|
|
48
|
-
{
|
|
49
|
-
latitude,
|
|
50
|
-
longitude,
|
|
51
|
-
altitude,
|
|
52
|
-
setOnRender,
|
|
53
|
-
onReady,
|
|
54
|
-
map
|
|
55
|
-
}
|
|
56
|
-
),
|
|
57
|
-
ready && children
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
CanvasPortal.displayName = "CanvasPortal";
|
|
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
|
+
}
|
|
63
23
|
export {
|
|
64
|
-
|
|
24
|
+
useCanvasInLayer
|
|
65
25
|
};
|
|
66
26
|
//# sourceMappingURL=main18.mjs.map
|
package/dist/es/main18.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main18.mjs","sources":["../../src/core/canvas-
|
|
1
|
+
{"version":3,"file":"main18.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/main19.mjs
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 "./main28.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
|
+
};
|
|
23
|
+
}, []);
|
|
24
|
+
return /* @__PURE__ */ jsx(Fragment, { children: createPortal(/* @__PURE__ */ jsx(CanvasPortal, { ...props }), el) });
|
|
25
|
+
});
|
|
26
|
+
InitCanvasFC.displayName = "InitCanvasFC";
|
|
20
27
|
export {
|
|
21
|
-
|
|
28
|
+
InitCanvasFC
|
|
22
29
|
};
|
|
23
30
|
//# sourceMappingURL=main19.mjs.map
|
package/dist/es/main19.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main19.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main19.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;"}
|
package/dist/es/main20.mjs
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
connect: (target) => {
|
|
9
|
-
if (!originalEvents.connect)
|
|
10
|
-
return;
|
|
11
|
-
originalEvents.connect(target.parentElement);
|
|
12
|
-
},
|
|
13
|
-
compute: (event, state) => {
|
|
14
|
-
state.pointer.x = event.offsetX / state.size.width * 2 - 1;
|
|
15
|
-
state.pointer.y = 1 - event.offsetY / state.size.height * 2;
|
|
16
|
-
if (state.camera.userData.projByViewInv)
|
|
17
|
-
projViewInv.fromArray(state.camera.userData.projByViewInv);
|
|
18
|
-
state.raycaster.camera = state.camera;
|
|
19
|
-
state.raycaster.ray.origin.setScalar(0).applyMatrix4(projViewInv);
|
|
20
|
-
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(projViewInv).sub(state.raycaster.ray.origin).normalize();
|
|
21
|
-
}
|
|
22
|
-
};
|
|
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
|
+
}, []);
|
|
23
8
|
};
|
|
24
9
|
export {
|
|
25
|
-
|
|
10
|
+
useFunction
|
|
26
11
|
};
|
|
27
12
|
//# sourceMappingURL=main20.mjs.map
|
package/dist/es/main20.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main20.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main20.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;"}
|
package/dist/es/main21.mjs
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
|
16
34
|
export {
|
|
17
|
-
|
|
35
|
+
syncCamera
|
|
18
36
|
};
|
|
19
37
|
//# sourceMappingURL=main21.mjs.map
|
package/dist/es/main21.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main21.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main21.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/main22.mjs
CHANGED
|
@@ -1,83 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
latitude,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
setOnRender,
|
|
13
|
-
manualRender,
|
|
14
|
-
onReady,
|
|
15
|
-
map
|
|
16
|
-
}) => {
|
|
17
|
-
const mapCanvas = map.getCanvas();
|
|
18
|
-
const r3m = useR3M();
|
|
19
|
-
const camRef = useRef(null);
|
|
20
|
-
const camera = useThree((s) => s.camera);
|
|
21
|
-
const gl = useThree((s) => s.gl);
|
|
22
|
-
const threeCanvas = useThree((s) => s.gl.domElement);
|
|
23
|
-
const scene = useThree((s) => s.scene);
|
|
24
|
-
const advance = useThree((s) => s.advance);
|
|
25
|
-
const setSize = useThree((s) => s.setSize);
|
|
26
|
-
const set = useThree((s) => s.set);
|
|
27
|
-
const origin = useCoordsToMatrix({ latitude, longitude, altitude, fromLngLat: r3m.fromLngLat });
|
|
28
|
-
const ready = useRef(false);
|
|
29
|
-
const triggerRepaint = useMemo(() => map.triggerRepaint, [map]);
|
|
30
|
-
const mapPaintRequests = useRef(0);
|
|
31
|
-
const triggerRepaintOff = useFunction(() => {
|
|
32
|
-
mapPaintRequests.current++;
|
|
33
|
-
});
|
|
34
|
-
useFrame(() => {
|
|
35
|
-
syncCamera(camera, origin, r3m.viewProjMx);
|
|
36
|
-
if (manualRender)
|
|
37
|
-
gl.render(scene, camera);
|
|
38
|
-
map.triggerRepaint = triggerRepaint;
|
|
39
|
-
if (mapPaintRequests.current > 0) {
|
|
40
|
-
mapPaintRequests.current = 0;
|
|
41
|
-
map.triggerRepaint();
|
|
42
|
-
}
|
|
43
|
-
}, -Infinity);
|
|
44
|
-
const onRender = useFunction((viewProjMx) => {
|
|
45
|
-
map.triggerRepaint = triggerRepaintOff;
|
|
46
|
-
if (threeCanvas.width !== mapCanvas.width || threeCanvas.height !== mapCanvas.height) {
|
|
47
|
-
setSize(
|
|
48
|
-
mapCanvas.clientWidth,
|
|
49
|
-
mapCanvas.clientHeight,
|
|
50
|
-
true,
|
|
51
|
-
mapCanvas.offsetTop,
|
|
52
|
-
mapCanvas.offsetLeft
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
r3m.viewProjMx = viewProjMx;
|
|
56
|
-
if (!ready.current && onReady) {
|
|
57
|
-
ready.current = true;
|
|
58
|
-
onReady();
|
|
59
|
-
}
|
|
60
|
-
advance(Date.now() * 1e-3, true);
|
|
61
|
-
});
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
setOnRender && setOnRender(() => onRender);
|
|
64
|
-
}, [setOnRender, onRender]);
|
|
65
|
-
useLayoutEffect(() => {
|
|
66
|
-
if (!manualRender)
|
|
67
|
-
return;
|
|
68
|
-
set({ camera: camRef.current });
|
|
69
|
-
}, []);
|
|
70
|
-
return /* @__PURE__ */ jsx(Fragment, { children: manualRender && /* @__PURE__ */ jsx(
|
|
71
|
-
"perspectiveCamera",
|
|
72
|
-
{
|
|
73
|
-
ref: camRef,
|
|
74
|
-
matrixAutoUpdate: false,
|
|
75
|
-
matrixWorldAutoUpdate: false
|
|
76
|
-
}
|
|
77
|
-
) });
|
|
78
|
-
});
|
|
79
|
-
SyncCameraFC.displayName = "SyncCameraFC";
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { coordsToMatrix } from "./main29.mjs";
|
|
3
|
+
function useCoordsToMatrix({ 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;
|
|
11
|
+
}
|
|
80
12
|
export {
|
|
81
|
-
|
|
13
|
+
useCoordsToMatrix
|
|
82
14
|
};
|
|
83
15
|
//# sourceMappingURL=main22.mjs.map
|
package/dist/es/main22.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main22.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main22.mjs","sources":["../../src/core/use-coords-to-matrix.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 useCoordsToMatrix({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,kBAAkB,EAAC,UAAU,WAAW,UAAU,cAAoB;AAC9E,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;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useThree, _roots } from "@react-three/fiber";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Matrix4 } from "three";
|
|
4
|
+
function useR3M() {
|
|
5
|
+
const r3m = useThree((s) => s.r3m);
|
|
6
|
+
return r3m;
|
|
7
|
+
}
|
|
8
|
+
function useInitR3M(props) {
|
|
9
|
+
const canvas = useThree((s) => s.gl.domElement);
|
|
10
|
+
useState(() => {
|
|
11
|
+
const store = _roots.get(canvas).store;
|
|
12
|
+
initR3M({ ...props, store });
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function initR3M({ store, ...props }) {
|
|
16
|
+
const viewProjMx = new Matrix4().identity().toArray();
|
|
17
|
+
const r3m = { ...props, viewProjMx };
|
|
18
|
+
store.setState({ r3m });
|
|
19
|
+
return r3m;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
initR3M,
|
|
23
|
+
useInitR3M,
|
|
24
|
+
useR3M
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=main23.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main23.mjs","sources":["../../src/core/use-r3m.ts"],"sourcesContent":["import { RootState, _roots, useThree } from \"@react-three/fiber\";\nimport { useState } from \"react\";\nimport { Matrix4, Matrix4Tuple } from \"three\";\nimport { UseBoundStore } from 'zustand';\nimport { FromLngLat, MapInstance } from \"./generic-map\";\n\nexport interface R3M<T extends MapInstance = MapInstance> {\n /** Map provider */\n map: T,\n /** view projection matrix coming from the map provider */\n viewProjMx: Matrix4Tuple,\n fromLngLat: FromLngLat,\n}\n\nexport function useR3M<T extends MapInstance> () {\n const r3m = useThree(s=>(s as any).r3m) as R3M<T>; // eslint-disable-line @typescript-eslint/no-explicit-any\n return r3m;\n}\n\n/** init `useR3M` hook */\nexport function useInitR3M<T extends MapInstance>(props: {\n map: T; fromLngLat: FromLngLat;\n}) {\n const canvas = useThree(s => s.gl.domElement);\n // to run only once\n useState(()=>{\n const store = _roots.get(canvas)!.store; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n initR3M({...props, store})\n })\n}\n\nexport function initR3M<T extends MapInstance>({store, ...props}: {\n map: T;\n fromLngLat: FromLngLat;\n store: UseBoundStore<RootState>;\n}) {\n const viewProjMx = new Matrix4().identity().toArray();\n const r3m : R3M<T> = { ...props, viewProjMx };\n store.setState({r3m} as any); // eslint-disable-line @typescript-eslint/no-explicit-any\n return r3m;\n}"],"names":[],"mappings":";;;AAcO,SAAS,SAAiC;AAC/C,QAAM,MAAM,SAAS,CAAI,MAAA,EAAU,GAAG;AAC/B,SAAA;AACT;AAGO,SAAS,WAAkC,OAE/C;AACD,QAAM,SAAS,SAAS,CAAK,MAAA,EAAE,GAAG,UAAU;AAE5C,WAAS,MAAI;AACX,UAAM,QAAQ,OAAO,IAAI,MAAM,EAAG;AAClC,YAAQ,EAAC,GAAG,OAAO,MAAM,CAAA;AAAA,EAAA,CAC1B;AACH;AAEO,SAAS,QAA+B,EAAC,OAAO,GAAG,SAIvD;AACD,QAAM,aAAa,IAAI,QAAA,EAAU,WAAW,QAAQ;AACpD,QAAM,MAAe,EAAE,GAAG,OAAO,WAAW;AACtC,QAAA,SAAS,EAAC,IAAA,CAAW;AACpB,SAAA;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main24.mjs","sources":["../../src/core/earth-radius.ts"],"sourcesContent":["export const earthRadius = 6371008.8;\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useThree, _roots } from "@react-three/fiber";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
function useCoords() {
|
|
4
|
+
const coords = useThree((s) => s.coords);
|
|
5
|
+
return coords;
|
|
6
|
+
}
|
|
7
|
+
function useSetCoords({ longitude, latitude, altitude }) {
|
|
8
|
+
const canvas = useThree((s) => s.gl.domElement);
|
|
9
|
+
useMemo(() => {
|
|
10
|
+
const store = _roots.get(canvas).store;
|
|
11
|
+
const coords = { longitude, latitude, altitude };
|
|
12
|
+
setCoords(store, coords);
|
|
13
|
+
}, [longitude, latitude, altitude]);
|
|
14
|
+
}
|
|
15
|
+
function useSetRootCoords(store, {
|
|
16
|
+
longitude,
|
|
17
|
+
latitude,
|
|
18
|
+
altitude
|
|
19
|
+
}) {
|
|
20
|
+
useMemo(() => {
|
|
21
|
+
setCoords(store, { longitude, latitude, altitude });
|
|
22
|
+
}, [longitude, latitude, altitude]);
|
|
23
|
+
}
|
|
24
|
+
function setCoords(store, coords) {
|
|
25
|
+
store.setState({ coords });
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
setCoords,
|
|
29
|
+
useCoords,
|
|
30
|
+
useSetCoords,
|
|
31
|
+
useSetRootCoords
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=main25.mjs.map
|