react-three-map 0.3.5 → 0.4.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 +6 -0
- package/README.md +25 -0
- package/dist/cjs/main.js +1 -1
- package/dist/es/main.mjs +4 -2
- package/dist/es/main.mjs.map +1 -1
- package/dist/es/main10.mjs +10 -0
- package/dist/es/main10.mjs.map +1 -0
- package/dist/es/main11.mjs +52 -0
- package/dist/es/main11.mjs.map +1 -0
- package/dist/es/main12.mjs +9 -0
- package/dist/es/main12.mjs.map +1 -0
- package/dist/es/main13.mjs +56 -0
- package/dist/es/main13.mjs.map +1 -0
- package/dist/es/main2.mjs +17 -29
- package/dist/es/main2.mjs.map +1 -1
- package/dist/es/main3.mjs +38 -6
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main4.mjs +20 -16
- package/dist/es/main4.mjs.map +1 -1
- package/dist/es/main5.mjs +3 -60
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +5 -12
- package/dist/es/main6.mjs.map +1 -1
- package/dist/es/main7.mjs +10 -52
- package/dist/es/main7.mjs.map +1 -1
- package/dist/es/main8.mjs +14 -5
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +15 -0
- package/dist/es/main9.mjs.map +1 -0
- package/dist/maplibre/cjs/main.js +1 -1
- package/dist/maplibre/es/main.mjs +4 -2
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main10.mjs +10 -0
- package/dist/maplibre/es/main10.mjs.map +1 -0
- package/dist/maplibre/es/main11.mjs +52 -0
- package/dist/maplibre/es/main11.mjs.map +1 -0
- package/dist/maplibre/es/main12.mjs +9 -0
- package/dist/maplibre/es/main12.mjs.map +1 -0
- package/dist/maplibre/es/main13.mjs +56 -0
- package/dist/maplibre/es/main13.mjs.map +1 -0
- package/dist/maplibre/es/main2.mjs +17 -29
- package/dist/maplibre/es/main2.mjs.map +1 -1
- package/dist/maplibre/es/main3.mjs +38 -6
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +20 -16
- package/dist/maplibre/es/main4.mjs.map +1 -1
- package/dist/maplibre/es/main5.mjs +3 -60
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/es/main6.mjs +5 -12
- package/dist/maplibre/es/main6.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +10 -52
- package/dist/maplibre/es/main7.mjs.map +1 -1
- package/dist/maplibre/es/main8.mjs +14 -5
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/es/main9.mjs +15 -0
- package/dist/maplibre/es/main9.mjs.map +1 -0
- package/dist/maplibre/types/api/canvas-props.d.ts +8 -0
- package/dist/maplibre/types/api/coordinates.d.ts +7 -0
- package/dist/maplibre/types/core/store.d.ts +12 -0
- package/dist/maplibre/types/core/sync-camera.d.ts +2 -0
- package/dist/maplibre/types/core/use-canvas.d.ts +7 -9
- package/dist/maplibre/types/core/use-coords.d.ts +5 -0
- package/dist/maplibre/types/core/use-create-root.d.ts +13 -0
- package/dist/maplibre/types/core/use-on-add.d.ts +6 -4
- package/dist/maplibre/types/core/use-render.d.ts +3 -2
- package/dist/maplibre/types/maplibre/canvas.d.ts +2 -8
- package/dist/maplibre/types/maplibre.index.d.ts +2 -0
- package/dist/types/api/canvas-props.d.ts +8 -0
- package/dist/types/api/coordinates.d.ts +7 -0
- package/dist/types/core/store.d.ts +12 -0
- package/dist/types/core/sync-camera.d.ts +2 -0
- package/dist/types/core/use-canvas.d.ts +7 -9
- package/dist/types/core/use-coords.d.ts +5 -0
- package/dist/types/core/use-create-root.d.ts +13 -0
- package/dist/types/core/use-on-add.d.ts +6 -4
- package/dist/types/core/use-render.d.ts +3 -2
- package/dist/types/mapbox/canvas.d.ts +3 -9
- package/dist/types/mapbox.index.d.ts +2 -0
- package/package.json +5 -5
- package/stories/README.md +1 -0
- package/stories/package.json +31 -0
- package/stories/sandbox.config.json +3 -0
- package/stories/yarn.lock +4295 -0
- package/dist/maplibre/types/core/state-ref.d.ts +0 -8
- package/dist/types/core/state-ref.d.ts +0 -8
|
@@ -1,63 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { createEvents as d } from "./main7.mjs";
|
|
4
|
-
import { useFunction as c } from "./main8.mjs";
|
|
5
|
-
function w(e, { frameloop: u, ...n }) {
|
|
6
|
-
const [l, r] = h(!1), g = c((t, m) => {
|
|
7
|
-
const o = t.getCanvas(), i = v(o);
|
|
8
|
-
i.configure({
|
|
9
|
-
dpr: window.devicePixelRatio,
|
|
10
|
-
events: d(),
|
|
11
|
-
...n,
|
|
12
|
-
frameloop: "never",
|
|
13
|
-
gl: {
|
|
14
|
-
context: m,
|
|
15
|
-
depth: !0,
|
|
16
|
-
autoClear: !1,
|
|
17
|
-
antialias: !0,
|
|
18
|
-
...n == null ? void 0 : n.gl
|
|
19
|
-
},
|
|
20
|
-
onCreated: (a) => {
|
|
21
|
-
u === "demand" && a.set({
|
|
22
|
-
frameloop: u,
|
|
23
|
-
invalidate: () => {
|
|
24
|
-
t.triggerRepaint();
|
|
25
|
-
}
|
|
26
|
-
}), e.current = {
|
|
27
|
-
state: a,
|
|
28
|
-
map: t,
|
|
29
|
-
root: i
|
|
30
|
-
}, a.gl.forceContextLoss = () => {
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
camera: {
|
|
34
|
-
matrixAutoUpdate: !1
|
|
35
|
-
},
|
|
36
|
-
size: {
|
|
37
|
-
width: o.clientWidth,
|
|
38
|
-
height: o.clientHeight,
|
|
39
|
-
top: 0,
|
|
40
|
-
left: 0,
|
|
41
|
-
...n == null ? void 0 : n.size
|
|
42
|
-
}
|
|
43
|
-
}), e.current = {
|
|
44
|
-
map: t,
|
|
45
|
-
root: i
|
|
46
|
-
}, t.on("resize", s), setTimeout(() => r(!0));
|
|
47
|
-
}), s = c(() => {
|
|
48
|
-
var i;
|
|
49
|
-
if (!((i = e.current) != null && i.state))
|
|
50
|
-
return;
|
|
51
|
-
const t = e.current.state, o = e.current.map.getCanvas();
|
|
52
|
-
t.setSize(o.width, o.height);
|
|
53
|
-
}), f = c((t) => {
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
e.current && (e.current.root.unmount(), t.off("resize", s));
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
return { onAdd: g, onRemove: f, mounted: l };
|
|
59
|
-
}
|
|
1
|
+
import { useThree as r } from "@react-three/fiber";
|
|
2
|
+
const m = () => r((e) => e.r3m);
|
|
60
3
|
export {
|
|
61
|
-
|
|
4
|
+
m as useR3M
|
|
62
5
|
};
|
|
63
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":["useR3M","useThree","s"],"mappings":";AAcO,MAAMA,IAAS,MAAgBC,EAAS,CAACC,MAAWA,EAAE,GAAG;"}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import { Matrix4 as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return m((l, a) => {
|
|
6
|
-
var e;
|
|
7
|
-
if (!((e = r.current) != null && e.state))
|
|
8
|
-
return;
|
|
9
|
-
const t = r.current.state.camera, c = r.current.state.gl, i = r.current.state.advance;
|
|
10
|
-
t.projectionMatrix.fromArray(a).multiply(p.fromArray(n)), t.projectionMatrixInverse.copy(t.projectionMatrix).invert(), c.resetState(), i(Date.now() * 1e-3, !0), o === "always" && r.current.map.triggerRepaint();
|
|
11
|
-
});
|
|
1
|
+
import { Matrix4 as i } from "three";
|
|
2
|
+
const n = new i();
|
|
3
|
+
function p(r, o, t) {
|
|
4
|
+
r.projectionMatrix.fromArray(t).multiply(n.fromArray(o)), r.projectionMatrixInverse.copy(r.projectionMatrix).invert();
|
|
12
5
|
}
|
|
13
6
|
export {
|
|
14
|
-
|
|
7
|
+
p as syncCamera
|
|
15
8
|
};
|
|
16
9
|
//# 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, PerspectiveCamera } from \"three\";\n\nconst mx = new Matrix4();\n\nexport function syncCamera(camera: PerspectiveCamera, origin: Matrix4Tuple, mapCamMx: Matrix4Tuple) {\n camera.projectionMatrix.fromArray(mapCamMx).multiply(mx.fromArray(origin));\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n}"],"names":["mx","Matrix4","syncCamera","camera","origin","mapCamMx"],"mappings":";AAEA,MAAMA,IAAK,IAAIC;AAEC,SAAAC,EAAWC,GAA2BC,GAAsBC,GAAwB;AAC3F,EAAAF,EAAA,iBAAiB,UAAUE,CAAQ,EAAE,SAASL,EAAG,UAAUI,CAAM,CAAC,GACzED,EAAO,wBAAwB,KAAKA,EAAO,gBAAgB,EAAE;AAC/D;"}
|
|
@@ -1,56 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
onPointerMove: ["pointermove", !0],
|
|
11
|
-
onPointerCancel: ["pointercancel", !0],
|
|
12
|
-
onLostPointerCapture: ["lostpointercapture", !0]
|
|
13
|
-
};
|
|
14
|
-
function u() {
|
|
15
|
-
return (o) => {
|
|
16
|
-
const { handlePointer: a } = p(o);
|
|
17
|
-
return {
|
|
18
|
-
priority: 1,
|
|
19
|
-
enabled: !0,
|
|
20
|
-
compute(n, e) {
|
|
21
|
-
e.size.width = e.gl.domElement.width / window.devicePixelRatio, e.size.height = e.gl.domElement.height / window.devicePixelRatio, e.pointer.x = n.offsetX / e.size.width * 2 - 1, e.pointer.y = 1 - n.offsetY / e.size.height * 2, e.raycaster.camera = e.camera, e.raycaster.ray.origin.setScalar(0).applyMatrix4(e.camera.projectionMatrixInverse), e.raycaster.ray.direction.set(e.pointer.x, e.pointer.y, 1).applyMatrix4(e.camera.projectionMatrixInverse).sub(e.raycaster.ray.origin).normalize();
|
|
22
|
-
},
|
|
23
|
-
connected: void 0,
|
|
24
|
-
handlers: Object.keys(c).reduce(
|
|
25
|
-
(n, e) => ({ ...n, [e]: a(e) }),
|
|
26
|
-
{}
|
|
27
|
-
),
|
|
28
|
-
update: () => {
|
|
29
|
-
var t;
|
|
30
|
-
const { events: n, internal: e } = o.getState();
|
|
31
|
-
(t = e.lastEvent) != null && t.current && n.handlers && n.handlers.onPointerMove(e.lastEvent.current);
|
|
32
|
-
},
|
|
33
|
-
connect: (n) => {
|
|
34
|
-
var i;
|
|
35
|
-
const { set: e, events: t } = o.getState();
|
|
36
|
-
(i = t.disconnect) == null || i.call(t), e((r) => ({ events: { ...r.events, connected: n.parentNode } })), Object.entries(t.handlers ?? []).forEach(([r, l]) => {
|
|
37
|
-
const [s, d] = c[r];
|
|
38
|
-
n.addEventListener(s, l, { passive: d });
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
disconnect: () => {
|
|
42
|
-
const { set: n, events: e } = o.getState();
|
|
43
|
-
e.connected && (Object.entries(e.handlers ?? []).forEach(([t, i]) => {
|
|
44
|
-
if (e && e.connected instanceof HTMLElement) {
|
|
45
|
-
const [r] = c[t];
|
|
46
|
-
e.connected.removeEventListener(r, i);
|
|
47
|
-
}
|
|
48
|
-
}), n((t) => ({ events: { ...t.events, connected: void 0 } })));
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
};
|
|
1
|
+
import { useMemo as c } from "react";
|
|
2
|
+
import { coordsToMatrix as p } from "./main10.mjs";
|
|
3
|
+
function x({ latitude: o, longitude: r, altitude: m, fromLngLat: s }) {
|
|
4
|
+
return c(() => p({
|
|
5
|
+
latitude: o,
|
|
6
|
+
longitude: r,
|
|
7
|
+
altitude: m,
|
|
8
|
+
fromLngLat: s
|
|
9
|
+
}), [o, r, m, s]);
|
|
52
10
|
}
|
|
53
11
|
export {
|
|
54
|
-
|
|
12
|
+
x as useCoords
|
|
55
13
|
};
|
|
56
14
|
//# 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":["useCoords","latitude","longitude","altitude","fromLngLat","useMemo","coordsToMatrix"],"mappings":";;AAMO,SAASA,EAAU,EAAC,UAAAC,GAAU,WAAAC,GAAW,UAAAC,GAAU,YAAAC,KAAoB;AAKrE,SAJIC,EAAQ,MAAMC,EAAe;AAAA,IACtC,UAAAL;AAAA,IAAU,WAAAC;AAAA,IAAW,UAAAC;AAAA,IAAU,YAAAC;AAAA,EAAA,CAChC,GAAG,CAACH,GAAUC,GAAWC,GAAUC,CAAU,CAAC;AAGjD;"}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { jsx as d, Fragment as c } from "react/jsx-runtime";
|
|
2
|
+
import { useId as i, useEffect as p } from "react";
|
|
3
|
+
import { useOnAdd as R } from "./main11.mjs";
|
|
4
|
+
const g = ({
|
|
5
|
+
children: o,
|
|
6
|
+
frameloop: t,
|
|
7
|
+
fromLngLat: n,
|
|
8
|
+
...m
|
|
9
|
+
}) => {
|
|
10
|
+
const u = i(), { onAdd: f, onRemove: s, mounted: e, r3mRef: r } = R(n, { frameloop: t, ...m });
|
|
11
|
+
return p(() => {
|
|
12
|
+
e && r.current.root && r.current.root.render(/* @__PURE__ */ d(c, { children: o }));
|
|
13
|
+
}, [r, e, o]), { id: u, onAdd: f, onRemove: s, r3mRef: r };
|
|
5
14
|
};
|
|
6
15
|
export {
|
|
7
|
-
|
|
16
|
+
g as useCreateRoot
|
|
8
17
|
};
|
|
9
18
|
//# 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-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":["useCreateRoot","children","frameloop","fromLngLat","renderProps","id","useId","onAdd","onRemove","mounted","r3mRef","useOnAdd","useEffect","jsx","Fragment"],"mappings":";;;AAUO,MAAMA,IAAiB,CAAC;AAAA,EAC7B,UAAAC;AAAA,EAAU,WAAAC;AAAA,EAAW,YAAAC;AAAA,EAAY,GAAGC;AACtC,MAAsB;AAEpB,QAAMC,IAAKC,KAEL,EAAE,OAAAC,GAAO,UAAAC,GAAU,SAAAC,GAAS,QAAAC,EAAO,IAAIC,EAASR,GAAY,EAAE,WAAAD,GAAW,GAAGE,EAAa,CAAA;AAE/F,SAAAQ,EAAU,MAAM;AACd,IAAKH,KACAC,EAAO,QAAQ,QACpBA,EAAO,QAAQ,KAAK,OAAO,gBAAAG,EAAAC,GAAA,EACxB,UAAAb,EACH,CAAA,CAAG;AAAA,EACF,GAAA,CAACS,GAAQD,GAASR,CAAQ,CAAC,GAEvB,EAAE,IAAAI,GAAI,OAAAE,GAAO,UAAAC,GAAU,QAAAE,EAAO;AACvC;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { syncCamera as m } from "./main6.mjs";
|
|
2
|
+
import { useFunction as i } from "./main12.mjs";
|
|
3
|
+
function g(r, a, n) {
|
|
4
|
+
return i((p, t) => {
|
|
5
|
+
const e = a.current;
|
|
6
|
+
if (!e.state || !e.map)
|
|
7
|
+
return;
|
|
8
|
+
const s = e.state.camera, c = e.state.gl, o = e.state.advance;
|
|
9
|
+
e.mapCamMx = t, m(s, r, t), c.resetState(), o(Date.now() * 1e-3, !0), n === "always" && e.map.triggerRepaint();
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
g as useRender
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=main9.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main9.mjs","sources":["../../../src/core/use-render.ts"],"sourcesContent":["import { MutableRefObject } from \"react\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { R3mStore } from \"./store\";\nimport { syncCamera } from \"./sync-camera\";\nimport { useFunction } from \"./use-function\";\n\nexport function useRender(\n origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'\n) {\n\n const render = useFunction((_gl: WebGL2RenderingContext, mapCamMx: number[]) => {\n const r3m = r3mRef.current;\n if (!r3m.state || !r3m.map) return;\n const camera = r3m.state.camera;\n const gl = r3m.state.gl;\n const advance = r3m.state.advance;\n r3m.mapCamMx = mapCamMx as Matrix4Tuple;\n syncCamera(camera as PerspectiveCamera, origin, mapCamMx as Matrix4Tuple);\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (frameloop === 'always') r3m.map.triggerRepaint();\n })\n\n return render;\n\n}"],"names":["useRender","origin","r3mRef","frameloop","useFunction","_gl","mapCamMx","r3m","camera","gl","advance","syncCamera"],"mappings":";;AAMgB,SAAAA,EACdC,GAAsBC,GAAoCC,GAC1D;AAeO,SAbQC,EAAY,CAACC,GAA6BC,MAAuB;AAC9E,UAAMC,IAAML,EAAO;AACnB,QAAI,CAACK,EAAI,SAAS,CAACA,EAAI;AAAK;AACtB,UAAAC,IAASD,EAAI,MAAM,QACnBE,IAAKF,EAAI,MAAM,IACfG,IAAUH,EAAI,MAAM;AAC1B,IAAAA,EAAI,WAAWD,GACJK,EAAAH,GAA6BP,GAAQK,CAAwB,GACxEG,EAAG,WAAW,GACdC,EAAQ,KAAK,IAAQ,IAAA,MAAO,EAAI,GAC5BP,MAAc,YAAUI,EAAI,IAAI;EAAe,CACpD;AAIH;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
4
|
+
longitude: number;
|
|
5
|
+
latitude: number;
|
|
6
|
+
altitude?: number;
|
|
7
|
+
frameloop?: 'always' | 'demand';
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReconcilerRoot, RootState } from "@react-three/fiber";
|
|
2
|
+
import { Matrix4Tuple } from "three";
|
|
3
|
+
import { FromLngLat, MapInstance } from "./generic-map";
|
|
4
|
+
/** react-three-map store */
|
|
5
|
+
export interface R3mStore {
|
|
6
|
+
fromLngLat: FromLngLat;
|
|
7
|
+
map?: MapInstance;
|
|
8
|
+
mapCamMx?: Matrix4Tuple;
|
|
9
|
+
state?: RootState;
|
|
10
|
+
root?: ReconcilerRoot<HTMLCanvasElement>;
|
|
11
|
+
}
|
|
12
|
+
export declare const useR3M: () => R3mStore;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
frameloop: 'always' | 'demand';
|
|
6
|
-
m4: Matrix4Tuple;
|
|
1
|
+
import { CanvasProps } from "../api/canvas-props";
|
|
2
|
+
import { FromLngLat } from "./generic-map";
|
|
3
|
+
export interface useCanvasProps extends CanvasProps {
|
|
4
|
+
fromLngLat: FromLngLat;
|
|
7
5
|
}
|
|
8
|
-
export declare
|
|
6
|
+
export declare function useCanvas({ longitude, latitude, altitude, frameloop, fromLngLat, ...renderProps }: useCanvasProps): {
|
|
9
7
|
id: string;
|
|
10
8
|
onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
|
|
11
|
-
onRemove: (
|
|
12
|
-
render: (_gl: WebGL2RenderingContext,
|
|
9
|
+
onRemove: () => void;
|
|
10
|
+
render: (_gl: WebGL2RenderingContext, mapCamMx: number[]) => void;
|
|
13
11
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { coordsToMatrix } from "./coords-to-matrix";
|
|
2
|
+
type Props = Parameters<typeof coordsToMatrix>[0];
|
|
3
|
+
/** calculate matrix from coordinates */
|
|
4
|
+
export declare function useCoords({ latitude, longitude, altitude, fromLngLat }: Props): import("three").Matrix4Tuple;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
import { FromLngLat } from "./generic-map";
|
|
4
|
+
export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
5
|
+
frameloop: 'always' | 'demand';
|
|
6
|
+
fromLngLat: FromLngLat;
|
|
7
|
+
}
|
|
8
|
+
export declare const useCreateRoot: ({ children, frameloop, fromLngLat, ...renderProps }: useCanvasProps) => {
|
|
9
|
+
id: string;
|
|
10
|
+
onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
|
|
11
|
+
onRemove: () => void;
|
|
12
|
+
r3mRef: import("react").MutableRefObject<import("./store").R3mStore>;
|
|
13
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { RenderProps } from "@react-three/fiber";
|
|
2
|
-
import { MapInstance } from "./generic-map";
|
|
3
|
-
import {
|
|
4
|
-
export declare function useOnAdd(
|
|
3
|
+
import { FromLngLat, MapInstance } from "./generic-map";
|
|
4
|
+
import { R3mStore } from "./store";
|
|
5
|
+
export declare function useOnAdd(fromLngLat: FromLngLat, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>): {
|
|
5
6
|
onAdd: (map: MapInstance, gl: WebGLRenderingContext) => void;
|
|
6
|
-
onRemove: (
|
|
7
|
+
onRemove: () => void;
|
|
7
8
|
mounted: boolean;
|
|
9
|
+
r3mRef: import("react").MutableRefObject<R3mStore>;
|
|
8
10
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MutableRefObject } from "react";
|
|
1
2
|
import { Matrix4Tuple } from "three";
|
|
2
|
-
import {
|
|
3
|
-
export declare function useRender(
|
|
3
|
+
import { R3mStore } from "./store";
|
|
4
|
+
export declare function useRender(origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'): (_gl: WebGL2RenderingContext, mapCamMx: number[]) => void;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
4
|
-
longitude: number;
|
|
5
|
-
latitude: number;
|
|
6
|
-
altitude?: number;
|
|
7
|
-
frameloop?: 'always' | 'demand';
|
|
8
|
-
}
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CanvasProps } from "../api/canvas-props";
|
|
9
3
|
/** react`-three-fiber` canvas inside `MapLibre` */
|
|
10
4
|
export declare const Canvas: import("react").NamedExoticComponent<CanvasProps>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
4
|
+
longitude: number;
|
|
5
|
+
latitude: number;
|
|
6
|
+
altitude?: number;
|
|
7
|
+
frameloop?: 'always' | 'demand';
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReconcilerRoot, RootState } from "@react-three/fiber";
|
|
2
|
+
import { Matrix4Tuple } from "three";
|
|
3
|
+
import { FromLngLat, MapInstance } from "./generic-map";
|
|
4
|
+
/** react-three-map store */
|
|
5
|
+
export interface R3mStore {
|
|
6
|
+
fromLngLat: FromLngLat;
|
|
7
|
+
map?: MapInstance;
|
|
8
|
+
mapCamMx?: Matrix4Tuple;
|
|
9
|
+
state?: RootState;
|
|
10
|
+
root?: ReconcilerRoot<HTMLCanvasElement>;
|
|
11
|
+
}
|
|
12
|
+
export declare const useR3M: () => R3mStore;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
frameloop: 'always' | 'demand';
|
|
6
|
-
m4: Matrix4Tuple;
|
|
1
|
+
import { CanvasProps } from "../api/canvas-props";
|
|
2
|
+
import { FromLngLat } from "./generic-map";
|
|
3
|
+
export interface useCanvasProps extends CanvasProps {
|
|
4
|
+
fromLngLat: FromLngLat;
|
|
7
5
|
}
|
|
8
|
-
export declare
|
|
6
|
+
export declare function useCanvas({ longitude, latitude, altitude, frameloop, fromLngLat, ...renderProps }: useCanvasProps): {
|
|
9
7
|
id: string;
|
|
10
8
|
onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
|
|
11
|
-
onRemove: (
|
|
12
|
-
render: (_gl: WebGL2RenderingContext,
|
|
9
|
+
onRemove: () => void;
|
|
10
|
+
render: (_gl: WebGL2RenderingContext, mapCamMx: number[]) => void;
|
|
13
11
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { coordsToMatrix } from "./coords-to-matrix";
|
|
2
|
+
type Props = Parameters<typeof coordsToMatrix>[0];
|
|
3
|
+
/** calculate matrix from coordinates */
|
|
4
|
+
export declare function useCoords({ latitude, longitude, altitude, fromLngLat }: Props): import("three").Matrix4Tuple;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RenderProps } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
import { FromLngLat } from "./generic-map";
|
|
4
|
+
export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
5
|
+
frameloop: 'always' | 'demand';
|
|
6
|
+
fromLngLat: FromLngLat;
|
|
7
|
+
}
|
|
8
|
+
export declare const useCreateRoot: ({ children, frameloop, fromLngLat, ...renderProps }: useCanvasProps) => {
|
|
9
|
+
id: string;
|
|
10
|
+
onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
|
|
11
|
+
onRemove: () => void;
|
|
12
|
+
r3mRef: import("react").MutableRefObject<import("./store").R3mStore>;
|
|
13
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { RenderProps } from "@react-three/fiber";
|
|
2
|
-
import { MapInstance } from "./generic-map";
|
|
3
|
-
import {
|
|
4
|
-
export declare function useOnAdd(
|
|
3
|
+
import { FromLngLat, MapInstance } from "./generic-map";
|
|
4
|
+
import { R3mStore } from "./store";
|
|
5
|
+
export declare function useOnAdd(fromLngLat: FromLngLat, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>): {
|
|
5
6
|
onAdd: (map: MapInstance, gl: WebGLRenderingContext) => void;
|
|
6
|
-
onRemove: (
|
|
7
|
+
onRemove: () => void;
|
|
7
8
|
mounted: boolean;
|
|
9
|
+
r3mRef: import("react").MutableRefObject<R3mStore>;
|
|
8
10
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MutableRefObject } from "react";
|
|
1
2
|
import { Matrix4Tuple } from "three";
|
|
2
|
-
import {
|
|
3
|
-
export declare function useRender(
|
|
3
|
+
import { R3mStore } from "./store";
|
|
4
|
+
export declare function useRender(origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'): (_gl: WebGL2RenderingContext, mapCamMx: number[]) => void;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
longitude: number;
|
|
5
|
-
latitude: number;
|
|
6
|
-
altitude?: number;
|
|
7
|
-
frameloop?: 'always' | 'demand';
|
|
8
|
-
}
|
|
9
|
-
/** react`-three-fiber` canvas inside `MapLibre` */
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CanvasProps } from "../api/canvas-props";
|
|
3
|
+
/** react`-three-fiber` canvas inside `Mapbox` */
|
|
10
4
|
export declare const Canvas: import("react").NamedExoticComponent<CanvasProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-three-map",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Use react-three-fiber inside MapLibre and Mapbox",
|
|
5
5
|
"main": "dist/cjs/main.js",
|
|
6
6
|
"module": "dist/es/main.mjs",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"build:mapbox": "cross-env LIB_MODE=1 MAP_MODE=1 vite build",
|
|
22
22
|
"postbuild:mapbox": "cross-env LIB_MODE=2 MAP_MODE=1 vite build",
|
|
23
23
|
"release": "yarn build && yarn changeset publish",
|
|
24
|
-
"lint": "eslint src example-maplibre/src example-mapbox/src --ext ts,tsx --fix",
|
|
24
|
+
"lint": "eslint src example-maplibre/src example-mapbox/src stories --ext ts,tsx --fix",
|
|
25
25
|
"preview": "vite preview",
|
|
26
26
|
"ts": "tsc -w",
|
|
27
27
|
"ts:check": "tsc",
|
|
28
|
-
"
|
|
28
|
+
"dev": "yarn ladle serve",
|
|
29
29
|
"build:stories": "yarn ladle build"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@types/node": "^20.3.1",
|
|
38
38
|
"@types/react": "^18.0.37",
|
|
39
39
|
"@types/react-dom": "^18.0.11",
|
|
40
|
-
"@types/three": "^0.
|
|
40
|
+
"@types/three": "^0.154.0",
|
|
41
41
|
"@typescript-eslint/eslint-plugin": "^5.59.11",
|
|
42
42
|
"@typescript-eslint/parser": "^5.59.11",
|
|
43
43
|
"@vitejs/plugin-react": "^4.0.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"three": "^0.153.0",
|
|
56
56
|
"three-stdlib": "^2.23.8",
|
|
57
57
|
"typescript": "~5.0.2",
|
|
58
|
-
"vite": "^4.
|
|
58
|
+
"vite": "^4.4.4",
|
|
59
59
|
"web-ifc-three": "^0.0.125"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This folder is being used as both a CodeSandbox CI and also as the main main stories from the root folder.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stories",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "yarn ladle serve"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@ladle/react": "^2.16.0",
|
|
10
|
+
"@react-three/drei": "^9.78.2",
|
|
11
|
+
"@react-three/fiber": "^8.13.5",
|
|
12
|
+
"leva": "^0.9.35",
|
|
13
|
+
"mapbox-gl": "^2.15.0",
|
|
14
|
+
"maplibre-gl": "^3.2.0",
|
|
15
|
+
"react": "^18.2.0",
|
|
16
|
+
"react-dom": "^18.2.0",
|
|
17
|
+
"react-map-gl": "^7.1.2",
|
|
18
|
+
"react-three-map": "^0.3.5",
|
|
19
|
+
"three": "^0.154.0",
|
|
20
|
+
"three-stdlib": "^2.23.13",
|
|
21
|
+
"web-ifc-three": "^0.0.125"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/react": "^18.2.15",
|
|
25
|
+
"@types/react-dom": "^18.2.7",
|
|
26
|
+
"@types/three": "^0.154.0",
|
|
27
|
+
"@vitejs/plugin-react": "^4.0.3",
|
|
28
|
+
"typescript": "^5.1.6",
|
|
29
|
+
"vite": "^4.4.4"
|
|
30
|
+
}
|
|
31
|
+
}
|