react-three-map 0.1.5 → 0.2.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 +15 -0
- package/README.md +105 -48
- package/dist/cjs/main.js.js +1318 -1
- package/dist/es/main.js10.mjs +56 -0
- package/dist/es/main.js10.mjs.map +1 -0
- package/dist/es/main.js11.mjs +9 -0
- package/dist/es/main.js11.mjs.map +1 -0
- package/dist/es/main.js2.mjs +23 -28
- package/dist/es/main.js2.mjs.map +1 -1
- package/dist/es/main.js3.mjs +6 -7
- package/dist/es/main.js3.mjs.map +1 -1
- package/dist/es/main.js4.mjs +28 -56
- package/dist/es/main.js4.mjs.map +1 -1
- package/dist/es/main.js5.mjs +23533 -12
- package/dist/es/main.js5.mjs.map +1 -1
- package/dist/es/main.js6.mjs +2 -53
- package/dist/es/main.js6.mjs.map +1 -1
- package/dist/es/main.js7.mjs +2 -6
- package/dist/es/main.js7.mjs.map +1 -1
- package/dist/es/main.js8.mjs +60 -0
- package/dist/es/main.js8.mjs.map +1 -0
- package/dist/es/main.js9.mjs +16 -0
- package/dist/es/main.js9.mjs.map +1 -0
- package/dist/maplibre/cjs/main.js.js +1 -0
- package/dist/maplibre/es/main.js.mjs +5 -0
- package/dist/maplibre/es/main.js.mjs.map +1 -0
- package/dist/maplibre/es/main.js2.mjs +34 -0
- package/dist/maplibre/es/main.js2.mjs.map +1 -0
- package/dist/maplibre/es/main.js3.mjs +10 -0
- package/dist/maplibre/es/main.js3.mjs.map +1 -0
- package/dist/maplibre/es/main.js4.mjs +31 -0
- package/dist/maplibre/es/main.js4.mjs.map +1 -0
- package/dist/maplibre/es/main.js5.mjs +60 -0
- package/dist/maplibre/es/main.js5.mjs.map +1 -0
- package/dist/maplibre/es/main.js6.mjs +16 -0
- package/dist/maplibre/es/main.js6.mjs.map +1 -0
- package/dist/maplibre/es/main.js7.mjs +56 -0
- package/dist/maplibre/es/main.js7.mjs.map +1 -0
- package/dist/maplibre/es/main.js8.mjs +9 -0
- package/dist/maplibre/es/main.js8.mjs.map +1 -0
- package/docs/basic-app.gif +0 -0
- package/maplibre/package.json +7 -0
- package/package.json +12 -5
- package/src/canvas/canvas-mapbox.tsx +32 -0
- package/src/canvas/canvas-maplibre.tsx +32 -0
- package/src/canvas/core/coords-to-matrix.ts +20 -0
- package/src/canvas/{create-events.ts → core/create-events.ts} +2 -2
- package/src/canvas/core/generic-map.test.ts +2 -0
- package/src/canvas/core/generic-map.ts +44 -0
- package/src/canvas/core/internal-canvas.tsx +43 -0
- package/src/canvas/{state-ref.ts → core/state-ref.ts} +2 -2
- package/src/canvas/{use-on-add.ts → core/use-on-add.ts} +30 -18
- package/src/canvas/core/use-render.ts +25 -0
- package/src/main-mapbox.ts +1 -0
- package/src/main-maplibre.ts +1 -0
- package/src/stories/canvas.basic.stories.tsx +63 -0
- package/src/stories/{canvas.stories.tsx → comparison.stories.tsx} +6 -4
- package/src/stories/html-on-top.stories.tsx +26 -0
- package/src/stories/my-scene.tsx +18 -11
- package/src/stories/render-on-demand.stories.tsx +9 -7
- package/src/stories/story-map.tsx +40 -0
- package/dist/cjs/vite.svg +0 -1
- package/dist/es/vite.svg +0 -1
- package/index.html +0 -13
- package/src/canvas/canvas.tsx +0 -49
- package/src/canvas/coords-to-matrix.ts +0 -19
- package/src/canvas/use-render.ts +0 -29
- package/src/main.ts +0 -1
- /package/src/canvas/{use-function.ts → core/use-function.ts} +0 -0
package/dist/es/main.js6.mjs
CHANGED
|
@@ -1,56 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
const c = {
|
|
3
|
-
onClick: ["click", !1],
|
|
4
|
-
onContextMenu: ["contextmenu", !1],
|
|
5
|
-
onDoubleClick: ["dblclick", !1],
|
|
6
|
-
onWheel: ["wheel", !0],
|
|
7
|
-
onPointerDown: ["pointerdown", !0],
|
|
8
|
-
onPointerUp: ["pointerup", !0],
|
|
9
|
-
onPointerLeave: ["pointerleave", !0],
|
|
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, e.size.height = e.gl.domElement.height, e.pointer.x = n.offsetX / (e.size.width / window.devicePixelRatio) * 2 - 1, e.pointer.y = 1 - n.offsetY / (e.size.height / window.devicePixelRatio) * 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 } })), 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
|
-
};
|
|
52
|
-
}
|
|
1
|
+
var e = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
53
2
|
export {
|
|
54
|
-
|
|
3
|
+
e as commonjsGlobal
|
|
55
4
|
};
|
|
56
5
|
//# sourceMappingURL=main.js6.mjs.map
|
package/dist/es/main.js6.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js6.mjs","sources":[
|
|
1
|
+
{"version":3,"file":"main.js6.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/dist/es/main.js7.mjs
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
const o = (r) => {
|
|
3
|
-
const e = n(r);
|
|
4
|
-
return e.current = r, u((...t) => e.current(...t), []);
|
|
5
|
-
};
|
|
1
|
+
var o = { exports: {} };
|
|
6
2
|
export {
|
|
7
|
-
o as
|
|
3
|
+
o as __module
|
|
8
4
|
};
|
|
9
5
|
//# sourceMappingURL=main.js7.mjs.map
|
package/dist/es/main.js7.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js7.mjs","sources":[
|
|
1
|
+
{"version":3,"file":"main.js7.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createRoot as v } from "@react-three/fiber";
|
|
2
|
+
import { useState as h } from "react";
|
|
3
|
+
import { createEvents as d } from "./main.js10.mjs";
|
|
4
|
+
import { useFunction as a } from "./main.js11.mjs";
|
|
5
|
+
function w(e, { frameloop: u, ...n }) {
|
|
6
|
+
const [l, r] = h(!1), g = a((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: (c) => {
|
|
21
|
+
u === "demand" && c.set({
|
|
22
|
+
frameloop: u,
|
|
23
|
+
invalidate: () => {
|
|
24
|
+
t.triggerRepaint();
|
|
25
|
+
}
|
|
26
|
+
}), e.current = {
|
|
27
|
+
state: c,
|
|
28
|
+
map: t,
|
|
29
|
+
root: i
|
|
30
|
+
}, c.gl.forceContextLoss = () => {
|
|
31
|
+
}, c.camera.matrixAutoUpdate = !1;
|
|
32
|
+
},
|
|
33
|
+
size: {
|
|
34
|
+
width: o.clientWidth,
|
|
35
|
+
height: o.clientHeight,
|
|
36
|
+
top: 0,
|
|
37
|
+
left: 0,
|
|
38
|
+
...n == null ? void 0 : n.size
|
|
39
|
+
}
|
|
40
|
+
}), e.current = {
|
|
41
|
+
map: t,
|
|
42
|
+
root: i
|
|
43
|
+
}, t.on("resize", s), setTimeout(() => r(!0));
|
|
44
|
+
}), s = a(() => {
|
|
45
|
+
var i;
|
|
46
|
+
if (!((i = e.current) != null && i.state))
|
|
47
|
+
return;
|
|
48
|
+
const t = e.current.state, o = e.current.map.getCanvas();
|
|
49
|
+
t.setSize(o.width, o.height);
|
|
50
|
+
}), f = a((t) => {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
e.current && (e.current.root.unmount(), t.off("resize", s));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return { onAdd: g, onRemove: f, mounted: l };
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
w as useOnAdd
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=main.js8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js8.mjs","sources":["../../src/canvas/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, createRoot } from \"@react-three/fiber\";\nimport { Map } from \"./generic-map\";\nimport { useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { StateRef } from \"./state-ref\";\nimport { useFunction } from \"./use-function\";\n\nexport function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>) {\n\n const [mounted, setMounted] = useState(false);\n\n const onAdd = useFunction((map: Map, gl: WebGLRenderingContext) => {\n\n const canvas = map.getCanvas();\n const root = createRoot(canvas);\n root.configure({\n dpr: window.devicePixelRatio,\n events: createEvents(),\n ...renderProps,\n frameloop: 'never',\n gl: {\n context: gl,\n depth: true,\n autoClear: false,\n antialias: true,\n ...renderProps?.gl,\n },\n onCreated: (state) => {\n\n if (frameloop === 'demand') {\n state.set({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n }\n })\n }\n\n ref.current = {\n state,\n map,\n root,\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n state.gl.forceContextLoss = () => { };\n\n // we update the camera on create rather than on config\n // because otherwise some components may use it too early\n // and get NaN values they can't recover from (drei HTML)\n state.camera.matrixAutoUpdate = false;\n },\n size: {\n width: canvas.clientWidth,\n height: canvas.clientHeight,\n top: 0,\n left: 0,\n ...renderProps?.size,\n },\n });\n\n ref.current = {\n map,\n root,\n }\n\n map.on('resize', onResize)\n\n setTimeout(() => setMounted(true));\n\n })\n\n const onResize = useFunction(() => {\n if (!ref.current?.state) return;\n const state = ref.current.state;\n const map = ref.current.map;\n const canvas = map.getCanvas();\n state.setSize(canvas.width, canvas.height);\n })\n\n const onRemove = useFunction((map: Map) => {\n setTimeout(() => {\n if (!ref.current) return;\n ref.current.root.unmount();\n map.off('resize', onResize)\n })\n })\n\n return { onAdd, onRemove, mounted };\n}"],"names":["useOnAdd","ref","frameloop","renderProps","mounted","setMounted","useState","onAdd","useFunction","map","gl","canvas","root","createRoot","createEvents","state","onResize","_a","onRemove"],"mappings":";;;;AAOO,SAASA,EAASC,GAAe,EAAE,WAAAC,GAAW,GAAGC,KAA+C;AAErG,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GAEtCC,IAAQC,EAAY,CAACC,GAAUC,MAA8B;AAE3D,UAAAC,IAASF,EAAI,aACbG,IAAOC,EAAWF,CAAM;AAC9B,IAAAC,EAAK,UAAU;AAAA,MACb,KAAK,OAAO;AAAA,MACZ,QAAQE,EAAa;AAAA,MACrB,GAAGX;AAAA,MACH,WAAW;AAAA,MACX,IAAI;AAAA,QACF,SAASO;AAAA,QACT,OAAO;AAAA,QACP,WAAW;AAAA,QACX,WAAW;AAAA,QACX,GAAGP,KAAA,gBAAAA,EAAa;AAAA,MAClB;AAAA,MACA,WAAW,CAACY,MAAU;AAEpB,QAAIb,MAAc,YAChBa,EAAM,IAAI;AAAA,UACR,WAAAb;AAAA,UACA,YAAY,MAAM;AAChB,YAAAO,EAAI,eAAe;AAAA,UACrB;AAAA,QAAA,CACD,GAGHR,EAAI,UAAU;AAAA,UACZ,OAAAc;AAAA,UACA,KAAAN;AAAA,UACA,MAAAG;AAAA,QAAA,GAIIG,EAAA,GAAG,mBAAmB,MAAM;AAAA,QAAA,GAKlCA,EAAM,OAAO,mBAAmB;AAAA,MAClC;AAAA,MACA,MAAM;AAAA,QACJ,OAAOJ,EAAO;AAAA,QACd,QAAQA,EAAO;AAAA,QACf,KAAK;AAAA,QACL,MAAM;AAAA,QACN,GAAGR,KAAA,gBAAAA,EAAa;AAAA,MAClB;AAAA,IAAA,CACD,GAEDF,EAAI,UAAU;AAAA,MACZ,KAAAQ;AAAA,MACA,MAAAG;AAAA,IAAA,GAGEH,EAAA,GAAG,UAAUO,CAAQ,GAEd,WAAA,MAAMX,EAAW,EAAI,CAAC;AAAA,EAAA,CAElC,GAEKW,IAAWR,EAAY,MAAM;;AAC7B,QAAA,GAACS,IAAAhB,EAAI,YAAJ,QAAAgB,EAAa;AAAO;AACnB,UAAAF,IAAQd,EAAI,QAAQ,OAEpBU,IADMV,EAAI,QAAQ,IACL;AACnB,IAAAc,EAAM,QAAQJ,EAAO,OAAOA,EAAO,MAAM;AAAA,EAAA,CAC1C,GAEKO,IAAWV,EAAY,CAACC,MAAa;AACzC,eAAW,MAAM;AACf,MAAKR,EAAI,YACLA,EAAA,QAAQ,KAAK,WACbQ,EAAA,IAAI,UAAUO,CAAQ;AAAA,IAAA,CAC3B;AAAA,EAAA,CACF;AAEM,SAAA,EAAE,OAAAT,GAAO,UAAAW,GAAU,SAAAd;AAC5B;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Matrix4 as u } from "three";
|
|
2
|
+
import { useFunction as m } from "./main.js11.mjs";
|
|
3
|
+
const p = new u();
|
|
4
|
+
function g(n, r, o) {
|
|
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
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
g as useRender
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=main.js9.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js9.mjs","sources":["../../src/canvas/core/use-render.ts"],"sourcesContent":["import { Matrix4, Matrix4Tuple } from \"three\";\nimport { StateRef } from \"./state-ref\";\nimport { useFunction } from \"./use-function\";\n\nconst mx = new Matrix4();\n\nexport function useRender(\n m4: Matrix4Tuple, stateRef: StateRef, frameloop: 'always' | 'demand'\n) {\n\n const render = useFunction((_gl: WebGL2RenderingContext, matrix: number[]) => {\n if (!stateRef.current?.state) return;\n const camera = stateRef.current.state.camera;\n const gl = stateRef.current.state.gl;\n const advance = stateRef.current.state.advance;\n camera.projectionMatrix.fromArray(matrix).multiply(mx.fromArray(m4));\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (frameloop === 'always') stateRef.current.map.triggerRepaint();\n })\n\n return render;\n\n}"],"names":["mx","Matrix4","useRender","m4","stateRef","frameloop","useFunction","_gl","matrix","_a","camera","gl","advance"],"mappings":";;AAIA,MAAMA,IAAK,IAAIC;AAEC,SAAAC,EACdC,GAAkBC,GAAoBC,GACtC;AAcO,SAZQC,EAAY,CAACC,GAA6BC,MAAqB;;AACxE,QAAA,GAACC,IAAAL,EAAS,YAAT,QAAAK,EAAkB;AAAO;AACxB,UAAAC,IAASN,EAAS,QAAQ,MAAM,QAChCO,IAAKP,EAAS,QAAQ,MAAM,IAC5BQ,IAAUR,EAAS,QAAQ,MAAM;AAChC,IAAAM,EAAA,iBAAiB,UAAUF,CAAM,EAAE,SAASR,EAAG,UAAUG,CAAE,CAAC,GACnEO,EAAO,wBAAwB,KAAKA,EAAO,gBAAgB,EAAE,UAC7DC,EAAG,WAAW,GACdC,EAAQ,KAAK,IAAQ,IAAA,MAAO,EAAI,GAC5BP,MAAc,YAAmBD,EAAA,QAAQ,IAAI;EAAe,CACjE;AAIH;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),y=require("@react-three/fiber"),b=require("maplibre-gl"),u=require("react"),d=require("three"),j=require("react-map-gl");function C(n){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const e=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(r,t,e.get?e:{enumerable:!0,get:()=>n[t]})}}return r.default=n,Object.freeze(r)}const z=C(d),x=new d.Quaternion,R=new d.Euler,w=new d.Vector3,M=new d.Vector3,S=new d.Matrix4;function L({longitude:n,latitude:r,altitude:t,fromLngLat:e}){const o=e([n,r],t),c=o.meterInMercatorCoordinateUnits();return w.set(o.x,o.y,o.z||0),M.set(c,-c,c),x.setFromEuler(R.set(-Math.PI*.5,0,0)),S.compose(w,x,M).toArray()}const h={onClick:["click",!1],onContextMenu:["contextmenu",!1],onDoubleClick:["dblclick",!1],onWheel:["wheel",!0],onPointerDown:["pointerdown",!0],onPointerUp:["pointerup",!0],onPointerLeave:["pointerleave",!0],onPointerMove:["pointermove",!0],onPointerCancel:["pointercancel",!0],onLostPointerCapture:["lostpointercapture",!0]};function O(){return n=>{const{handlePointer:r}=y.createEvents(n);return{priority:1,enabled:!0,compute(t,e){e.size.width=e.gl.domElement.width,e.size.height=e.gl.domElement.height,e.pointer.x=t.offsetX/(e.size.width/window.devicePixelRatio)*2-1,e.pointer.y=1-t.offsetY/(e.size.height/window.devicePixelRatio)*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()},connected:void 0,handlers:Object.keys(h).reduce((t,e)=>({...t,[e]:r(e)}),{}),update:()=>{var o;const{events:t,internal:e}=n.getState();(o=e.lastEvent)!=null&&o.current&&t.handlers&&t.handlers.onPointerMove(e.lastEvent.current)},connect:t=>{var c;const{set:e,events:o}=n.getState();(c=o.disconnect)==null||c.call(o),e(a=>({events:{...a.events,connected:t.parentNode}})),Object.entries(o.handlers??[]).forEach(([a,l])=>{const[i,s]=h[a];t.addEventListener(i,l,{passive:s})})},disconnect:()=>{const{set:t,events:e}=n.getState();e.connected&&(Object.entries(e.handlers??[]).forEach(([o,c])=>{if(e&&e.connected instanceof HTMLElement){const[a]=h[o];e.connected.removeEventListener(a,c)}}),t(o=>({events:{...o.events,connected:void 0}})))}}}}const g=n=>{const r=u.useRef(n);return r.current=n,u.useCallback((...t)=>r.current(...t),[])};function T(n,{frameloop:r,...t}){const[e,o]=u.useState(!1),c=g((i,s)=>{const m=i.getCanvas(),v=y.createRoot(m);v.configure({dpr:window.devicePixelRatio,events:O(),...t,frameloop:"never",gl:{context:s,depth:!0,autoClear:!1,antialias:!0,...t==null?void 0:t.gl},onCreated:f=>{r==="demand"&&f.set({frameloop:r,invalidate:()=>{i.triggerRepaint()}}),n.current={state:f,map:i,root:v},f.gl.forceContextLoss=()=>{},f.camera.matrixAutoUpdate=!1},size:{width:m.clientWidth,height:m.clientHeight,top:0,left:0,...t==null?void 0:t.size}}),n.current={map:i,root:v},i.on("resize",a),setTimeout(()=>o(!0))}),a=g(()=>{var v;if(!((v=n.current)!=null&&v.state))return;const i=n.current.state,m=n.current.map.getCanvas();i.setSize(m.width,m.height)}),l=g(i=>{setTimeout(()=>{n.current&&(n.current.root.unmount(),i.off("resize",a))})});return{onAdd:c,onRemove:l,mounted:e}}const I=new d.Matrix4;function q(n,r,t){return g((o,c)=>{var s;if(!((s=r.current)!=null&&s.state))return;const a=r.current.state.camera,l=r.current.state.gl,i=r.current.state.advance;a.projectionMatrix.fromArray(c).multiply(I.fromArray(n)),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),l.resetState(),i(Date.now()*.001,!0),t==="always"&&r.current.map.triggerRepaint()})}const E=u.memo(({m4:n,children:r,frameloop:t,...e})=>{const o=u.useId(),c=u.useRef(),{onAdd:a,onRemove:l,mounted:i}=T(c,{frameloop:t,...e}),s=q(n,c,t);return u.useEffect(()=>{i&&c.current&&c.current.root.render(p.jsx(p.Fragment,{children:r}))},[c,i,r]),p.jsx(j.Layer,{id:o,type:"custom",renderingMode:"3d",onAdd:a,onRemove:l,render:s})});E.displayName="InternalCanvas";y.extend(z);const A=u.memo(({longitude:n,latitude:r,altitude:t=0,frameloop:e="always",...o})=>{const c=u.useMemo(()=>L({latitude:r,longitude:n,altitude:t,fromLngLat:b.MercatorCoordinate.fromLngLat}),[r,n,t]);return p.jsx(E,{frameloop:e,m4:c,...o})});exports.Canvas=A;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as f } from "react/jsx-runtime";
|
|
2
|
+
import { extend as s } from "@react-three/fiber";
|
|
3
|
+
import { MercatorCoordinate as p } from "maplibre-gl";
|
|
4
|
+
import { memo as e, useMemo as i } from "react";
|
|
5
|
+
import * as c from "three";
|
|
6
|
+
import { coordsToMatrix as x } from "./main.js3.mjs";
|
|
7
|
+
import { InternalCanvas as L } from "./main.js4.mjs";
|
|
8
|
+
s(c);
|
|
9
|
+
const j = e(({
|
|
10
|
+
longitude: o,
|
|
11
|
+
latitude: r,
|
|
12
|
+
altitude: m = 0,
|
|
13
|
+
frameloop: t = "always",
|
|
14
|
+
...a
|
|
15
|
+
}) => {
|
|
16
|
+
const n = i(() => x({
|
|
17
|
+
latitude: r,
|
|
18
|
+
longitude: o,
|
|
19
|
+
altitude: m,
|
|
20
|
+
fromLngLat: p.fromLngLat
|
|
21
|
+
}), [r, o, m]);
|
|
22
|
+
return /* @__PURE__ */ f(
|
|
23
|
+
L,
|
|
24
|
+
{
|
|
25
|
+
frameloop: t,
|
|
26
|
+
m4: n,
|
|
27
|
+
...a
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
export {
|
|
32
|
+
j as Canvas
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=main.js2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js2.mjs","sources":["../../../src/canvas/canvas-maplibre.tsx"],"sourcesContent":["import { RenderProps, extend } from \"@react-three/fiber\";\nimport { MercatorCoordinate } from \"maplibre-gl\";\nimport { PropsWithChildren, memo, useMemo } from \"react\";\nimport * as THREE from \"three\";\nimport { coordsToMatrix } from \"./core/coords-to-matrix\";\nimport { InternalCanvas } from \"./core/internal-canvas\";\n\nextend(THREE);\n\nexport interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {\n longitude: number,\n latitude: number,\n altitude?: number,\n frameloop?: 'always' | 'demand',\n}\n\n/** react`-three-fiber` canvas inside `MapLibre` */\nexport const Canvas = memo<CanvasProps>(({\n longitude, latitude, altitude = 0,\n frameloop = 'always', ...renderProps\n}) => {\n\n const m4 = useMemo(() => coordsToMatrix({\n latitude, longitude, altitude, fromLngLat: MercatorCoordinate.fromLngLat,\n }), [latitude, longitude, altitude])\n\n return <InternalCanvas\n frameloop={frameloop}\n m4={m4}\n {...renderProps}\n />\n})"],"names":["extend","THREE","Canvas","memo","longitude","latitude","altitude","frameloop","renderProps","m4","useMemo","coordsToMatrix","MercatorCoordinate","jsx","InternalCanvas"],"mappings":";;;;;;;AAOAA,EAAOC,CAAK;AAUC,MAAAC,IAASC,EAAkB,CAAC;AAAA,EACvC,WAAAC;AAAA,EAAW,UAAAC;AAAA,EAAU,UAAAC,IAAW;AAAA,EAChC,WAAAC,IAAY;AAAA,EAAU,GAAGC;AAC3B,MAAM;AAEE,QAAAC,IAAKC,EAAQ,MAAMC,EAAe;AAAA,IACtC,UAAAN;AAAA,IAAU,WAAAD;AAAA,IAAW,UAAAE;AAAA,IAAU,YAAYM,EAAmB;AAAA,EAC/D,CAAA,GAAG,CAACP,GAAUD,GAAWE,CAAQ,CAAC;AAE5B,SAAA,gBAAAO;AAAA,IAACC;AAAA,IAAA;AAAA,MACN,WAAAP;AAAA,MACA,IAAAE;AAAA,MACC,GAAGD;AAAA,IAAA;AAAA,EAAA;AAER,CAAC;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Quaternion as m, Euler as l, Vector3 as s, Matrix4 as w } from "three";
|
|
2
|
+
const o = new m(), p = new l(), n = new s(), r = new s(), x = new w();
|
|
3
|
+
function d({ longitude: c, latitude: a, altitude: i, fromLngLat: u }) {
|
|
4
|
+
const t = u([c, a], i), e = t.meterInMercatorCoordinateUnits();
|
|
5
|
+
return n.set(t.x, t.y, t.z || 0), r.set(e, -e, e), o.setFromEuler(p.set(-Math.PI * 0.5, 0, 0)), x.compose(n, o, r).toArray();
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
d as coordsToMatrix
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=main.js3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js3.mjs","sources":["../../../src/canvas/core/coords-to-matrix.ts"],"sourcesContent":["import { Euler, Matrix4, Quaternion, Vector3 } from \"three\";\nimport { FromLngLat } from \"./generic-map\";\n\nconst quat = new Quaternion();\nconst euler = new Euler();\nconst pos = new Vector3();\nconst scale = new Vector3();\nconst m4 = new Matrix4();\n\n/** calculate Matrix4 from coordinates */\nexport function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }: {\n longitude: number, latitude: number, altitude: number, fromLngLat: FromLngLat\n}) {\n const center = fromLngLat([longitude, latitude], altitude);\n const scaleUnit = center.meterInMercatorCoordinateUnits();\n pos.set(center.x, center.y, center.z || 0);\n scale.set(scaleUnit, -scaleUnit, scaleUnit);\n quat.setFromEuler(euler.set(-Math.PI * .5, 0, 0));\n return m4.compose(pos, quat, scale).toArray();\n}\n"],"names":["quat","Quaternion","euler","Euler","pos","Vector3","scale","m4","Matrix4","coordsToMatrix","longitude","latitude","altitude","fromLngLat","center","scaleUnit"],"mappings":";AAGA,MAAMA,IAAO,IAAIC,KACXC,IAAQ,IAAIC,KACZC,IAAM,IAAIC,KACVC,IAAQ,IAAID,KACZE,IAAK,IAAIC;AAGR,SAASC,EAAe,EAAE,WAAAC,GAAW,UAAAC,GAAU,UAAAC,GAAU,YAAAC,KAE7D;AACD,QAAMC,IAASD,EAAW,CAACH,GAAWC,CAAQ,GAAGC,CAAQ,GACnDG,IAAYD,EAAO;AACzB,SAAAV,EAAI,IAAIU,EAAO,GAAGA,EAAO,GAAGA,EAAO,KAAK,CAAC,GACzCR,EAAM,IAAIS,GAAW,CAACA,GAAWA,CAAS,GACrCf,EAAA,aAAaE,EAAM,IAAI,CAAC,KAAK,KAAK,KAAI,GAAG,CAAC,CAAC,GACzCK,EAAG,QAAQH,GAAKJ,GAAMM,CAAK,EAAE;AACtC;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as o, Fragment as i } from "react/jsx-runtime";
|
|
2
|
+
import { memo as c, useId as p, useRef as R, useEffect as v } from "react";
|
|
3
|
+
import { Layer as y } from "react-map-gl";
|
|
4
|
+
import { useOnAdd as I } from "./main.js5.mjs";
|
|
5
|
+
import { useRender as g } from "./main.js6.mjs";
|
|
6
|
+
const x = c(({
|
|
7
|
+
m4: m,
|
|
8
|
+
children: r,
|
|
9
|
+
frameloop: t,
|
|
10
|
+
...s
|
|
11
|
+
}) => {
|
|
12
|
+
const d = p(), e = R(), { onAdd: u, onRemove: a, mounted: n } = I(e, { frameloop: t, ...s }), f = g(m, e, t);
|
|
13
|
+
return v(() => {
|
|
14
|
+
n && e.current && e.current.root.render(/* @__PURE__ */ o(i, { children: r }));
|
|
15
|
+
}, [e, n, r]), /* @__PURE__ */ o(
|
|
16
|
+
y,
|
|
17
|
+
{
|
|
18
|
+
id: d,
|
|
19
|
+
type: "custom",
|
|
20
|
+
renderingMode: "3d",
|
|
21
|
+
onAdd: u,
|
|
22
|
+
onRemove: a,
|
|
23
|
+
render: f
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
x.displayName = "InternalCanvas";
|
|
28
|
+
export {
|
|
29
|
+
x as InternalCanvas
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=main.js4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js4.mjs","sources":["../../../src/canvas/core/internal-canvas.tsx"],"sourcesContent":["import { RenderProps } from \"@react-three/fiber\";\nimport { PropsWithChildren, memo, useEffect, useId, useRef } from \"react\";\nimport { Layer } from \"react-map-gl\";\nimport { Matrix4Tuple } from \"three\";\nimport { StateRef } from \"./state-ref\";\nimport { useOnAdd } from \"./use-on-add\";\nimport { useRender } from \"./use-render\";\n\nexport interface InternalCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {\n frameloop: 'always' | 'demand',\n m4: Matrix4Tuple;\n}\n\nexport const InternalCanvas = memo<InternalCanvasProps>(({\n m4, children, frameloop, ...renderProps\n}) => {\n const id = useId();\n\n const stateRef: StateRef = useRef();\n\n const { onAdd, onRemove, mounted } = useOnAdd(stateRef, { frameloop, ...renderProps });\n\n const render = useRender(m4, stateRef, frameloop);\n\n useEffect(() => {\n if (!mounted) return;\n if (!stateRef.current) return;\n stateRef.current.root.render(<>{children}</>);\n }, [stateRef, mounted, children])\n\n return <Layer\n id={id}\n type=\"custom\"\n renderingMode=\"3d\"\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onAdd={onAdd as any}\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onRemove={onRemove as any}\n render={render}\n />\n})\n\nInternalCanvas.displayName = 'InternalCanvas';"],"names":["InternalCanvas","memo","m4","children","frameloop","renderProps","id","useId","stateRef","useRef","onAdd","onRemove","mounted","useOnAdd","render","useRender","useEffect","jsx","Fragment","Layer"],"mappings":";;;;;AAaa,MAAAA,IAAiBC,EAA0B,CAAC;AAAA,EACvD,IAAAC;AAAA,EAAI,UAAAC;AAAA,EAAU,WAAAC;AAAA,EAAW,GAAGC;AAC9B,MAAM;AACJ,QAAMC,IAAKC,KAELC,IAAqBC,KAErB,EAAE,OAAAC,GAAO,UAAAC,GAAU,SAAAC,MAAYC,EAASL,GAAU,EAAE,WAAAJ,GAAW,GAAGC,EAAA,CAAa,GAE/ES,IAASC,EAAUb,GAAIM,GAAUJ,CAAS;AAEhD,SAAAY,EAAU,MAAM;AACd,IAAKJ,KACAJ,EAAS,WACdA,EAAS,QAAQ,KAAK,OAAO,gBAAAS,EAAAC,GAAA,EAAG,UAAAf,EAAS,CAAA,CAAG;AAAA,EAC3C,GAAA,CAACK,GAAUI,GAAST,CAAQ,CAAC,GAEzB,gBAAAc;AAAA,IAACE;AAAA,IAAA;AAAA,MACN,IAAAb;AAAA,MACA,MAAK;AAAA,MACL,eAAc;AAAA,MAEd,OAAAI;AAAA,MAEA,UAAAC;AAAA,MACA,QAAAG;AAAA,IAAA;AAAA,EAAA;AAEJ,CAAC;AAEDd,EAAe,cAAc;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createRoot as v } from "@react-three/fiber";
|
|
2
|
+
import { useState as h } from "react";
|
|
3
|
+
import { createEvents as d } from "./main.js7.mjs";
|
|
4
|
+
import { useFunction as a } from "./main.js8.mjs";
|
|
5
|
+
function w(e, { frameloop: u, ...n }) {
|
|
6
|
+
const [l, r] = h(!1), g = a((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: (c) => {
|
|
21
|
+
u === "demand" && c.set({
|
|
22
|
+
frameloop: u,
|
|
23
|
+
invalidate: () => {
|
|
24
|
+
t.triggerRepaint();
|
|
25
|
+
}
|
|
26
|
+
}), e.current = {
|
|
27
|
+
state: c,
|
|
28
|
+
map: t,
|
|
29
|
+
root: i
|
|
30
|
+
}, c.gl.forceContextLoss = () => {
|
|
31
|
+
}, c.camera.matrixAutoUpdate = !1;
|
|
32
|
+
},
|
|
33
|
+
size: {
|
|
34
|
+
width: o.clientWidth,
|
|
35
|
+
height: o.clientHeight,
|
|
36
|
+
top: 0,
|
|
37
|
+
left: 0,
|
|
38
|
+
...n == null ? void 0 : n.size
|
|
39
|
+
}
|
|
40
|
+
}), e.current = {
|
|
41
|
+
map: t,
|
|
42
|
+
root: i
|
|
43
|
+
}, t.on("resize", s), setTimeout(() => r(!0));
|
|
44
|
+
}), s = a(() => {
|
|
45
|
+
var i;
|
|
46
|
+
if (!((i = e.current) != null && i.state))
|
|
47
|
+
return;
|
|
48
|
+
const t = e.current.state, o = e.current.map.getCanvas();
|
|
49
|
+
t.setSize(o.width, o.height);
|
|
50
|
+
}), f = a((t) => {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
e.current && (e.current.root.unmount(), t.off("resize", s));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return { onAdd: g, onRemove: f, mounted: l };
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
w as useOnAdd
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=main.js5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js5.mjs","sources":["../../../src/canvas/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, createRoot } from \"@react-three/fiber\";\nimport { Map } from \"./generic-map\";\nimport { useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { StateRef } from \"./state-ref\";\nimport { useFunction } from \"./use-function\";\n\nexport function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>) {\n\n const [mounted, setMounted] = useState(false);\n\n const onAdd = useFunction((map: Map, gl: WebGLRenderingContext) => {\n\n const canvas = map.getCanvas();\n const root = createRoot(canvas);\n root.configure({\n dpr: window.devicePixelRatio,\n events: createEvents(),\n ...renderProps,\n frameloop: 'never',\n gl: {\n context: gl,\n depth: true,\n autoClear: false,\n antialias: true,\n ...renderProps?.gl,\n },\n onCreated: (state) => {\n\n if (frameloop === 'demand') {\n state.set({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n }\n })\n }\n\n ref.current = {\n state,\n map,\n root,\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n state.gl.forceContextLoss = () => { };\n\n // we update the camera on create rather than on config\n // because otherwise some components may use it too early\n // and get NaN values they can't recover from (drei HTML)\n state.camera.matrixAutoUpdate = false;\n },\n size: {\n width: canvas.clientWidth,\n height: canvas.clientHeight,\n top: 0,\n left: 0,\n ...renderProps?.size,\n },\n });\n\n ref.current = {\n map,\n root,\n }\n\n map.on('resize', onResize)\n\n setTimeout(() => setMounted(true));\n\n })\n\n const onResize = useFunction(() => {\n if (!ref.current?.state) return;\n const state = ref.current.state;\n const map = ref.current.map;\n const canvas = map.getCanvas();\n state.setSize(canvas.width, canvas.height);\n })\n\n const onRemove = useFunction((map: Map) => {\n setTimeout(() => {\n if (!ref.current) return;\n ref.current.root.unmount();\n map.off('resize', onResize)\n })\n })\n\n return { onAdd, onRemove, mounted };\n}"],"names":["useOnAdd","ref","frameloop","renderProps","mounted","setMounted","useState","onAdd","useFunction","map","gl","canvas","root","createRoot","createEvents","state","onResize","_a","onRemove"],"mappings":";;;;AAOO,SAASA,EAASC,GAAe,EAAE,WAAAC,GAAW,GAAGC,KAA+C;AAErG,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GAEtCC,IAAQC,EAAY,CAACC,GAAUC,MAA8B;AAE3D,UAAAC,IAASF,EAAI,aACbG,IAAOC,EAAWF,CAAM;AAC9B,IAAAC,EAAK,UAAU;AAAA,MACb,KAAK,OAAO;AAAA,MACZ,QAAQE,EAAa;AAAA,MACrB,GAAGX;AAAA,MACH,WAAW;AAAA,MACX,IAAI;AAAA,QACF,SAASO;AAAA,QACT,OAAO;AAAA,QACP,WAAW;AAAA,QACX,WAAW;AAAA,QACX,GAAGP,KAAA,gBAAAA,EAAa;AAAA,MAClB;AAAA,MACA,WAAW,CAACY,MAAU;AAEpB,QAAIb,MAAc,YAChBa,EAAM,IAAI;AAAA,UACR,WAAAb;AAAA,UACA,YAAY,MAAM;AAChB,YAAAO,EAAI,eAAe;AAAA,UACrB;AAAA,QAAA,CACD,GAGHR,EAAI,UAAU;AAAA,UACZ,OAAAc;AAAA,UACA,KAAAN;AAAA,UACA,MAAAG;AAAA,QAAA,GAIIG,EAAA,GAAG,mBAAmB,MAAM;AAAA,QAAA,GAKlCA,EAAM,OAAO,mBAAmB;AAAA,MAClC;AAAA,MACA,MAAM;AAAA,QACJ,OAAOJ,EAAO;AAAA,QACd,QAAQA,EAAO;AAAA,QACf,KAAK;AAAA,QACL,MAAM;AAAA,QACN,GAAGR,KAAA,gBAAAA,EAAa;AAAA,MAClB;AAAA,IAAA,CACD,GAEDF,EAAI,UAAU;AAAA,MACZ,KAAAQ;AAAA,MACA,MAAAG;AAAA,IAAA,GAGEH,EAAA,GAAG,UAAUO,CAAQ,GAEd,WAAA,MAAMX,EAAW,EAAI,CAAC;AAAA,EAAA,CAElC,GAEKW,IAAWR,EAAY,MAAM;;AAC7B,QAAA,GAACS,IAAAhB,EAAI,YAAJ,QAAAgB,EAAa;AAAO;AACnB,UAAAF,IAAQd,EAAI,QAAQ,OAEpBU,IADMV,EAAI,QAAQ,IACL;AACnB,IAAAc,EAAM,QAAQJ,EAAO,OAAOA,EAAO,MAAM;AAAA,EAAA,CAC1C,GAEKO,IAAWV,EAAY,CAACC,MAAa;AACzC,eAAW,MAAM;AACf,MAAKR,EAAI,YACLA,EAAA,QAAQ,KAAK,WACbQ,EAAA,IAAI,UAAUO,CAAQ;AAAA,IAAA,CAC3B;AAAA,EAAA,CACF;AAEM,SAAA,EAAE,OAAAT,GAAO,UAAAW,GAAU,SAAAd;AAC5B;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Matrix4 as u } from "three";
|
|
2
|
+
import { useFunction as m } from "./main.js8.mjs";
|
|
3
|
+
const p = new u();
|
|
4
|
+
function g(n, r, o) {
|
|
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
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
g as useRender
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=main.js6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js6.mjs","sources":["../../../src/canvas/core/use-render.ts"],"sourcesContent":["import { Matrix4, Matrix4Tuple } from \"three\";\nimport { StateRef } from \"./state-ref\";\nimport { useFunction } from \"./use-function\";\n\nconst mx = new Matrix4();\n\nexport function useRender(\n m4: Matrix4Tuple, stateRef: StateRef, frameloop: 'always' | 'demand'\n) {\n\n const render = useFunction((_gl: WebGL2RenderingContext, matrix: number[]) => {\n if (!stateRef.current?.state) return;\n const camera = stateRef.current.state.camera;\n const gl = stateRef.current.state.gl;\n const advance = stateRef.current.state.advance;\n camera.projectionMatrix.fromArray(matrix).multiply(mx.fromArray(m4));\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (frameloop === 'always') stateRef.current.map.triggerRepaint();\n })\n\n return render;\n\n}"],"names":["mx","Matrix4","useRender","m4","stateRef","frameloop","useFunction","_gl","matrix","_a","camera","gl","advance"],"mappings":";;AAIA,MAAMA,IAAK,IAAIC;AAEC,SAAAC,EACdC,GAAkBC,GAAoBC,GACtC;AAcO,SAZQC,EAAY,CAACC,GAA6BC,MAAqB;;AACxE,QAAA,GAACC,IAAAL,EAAS,YAAT,QAAAK,EAAkB;AAAO;AACxB,UAAAC,IAASN,EAAS,QAAQ,MAAM,QAChCO,IAAKP,EAAS,QAAQ,MAAM,IAC5BQ,IAAUR,EAAS,QAAQ,MAAM;AAChC,IAAAM,EAAA,iBAAiB,UAAUF,CAAM,EAAE,SAASR,EAAG,UAAUG,CAAE,CAAC,GACnEO,EAAO,wBAAwB,KAAKA,EAAO,gBAAgB,EAAE,UAC7DC,EAAG,WAAW,GACdC,EAAQ,KAAK,IAAQ,IAAA,MAAO,EAAI,GAC5BP,MAAc,YAAmBD,EAAA,QAAQ,IAAI;EAAe,CACjE;AAIH;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createEvents as p } from "@react-three/fiber";
|
|
2
|
+
const c = {
|
|
3
|
+
onClick: ["click", !1],
|
|
4
|
+
onContextMenu: ["contextmenu", !1],
|
|
5
|
+
onDoubleClick: ["dblclick", !1],
|
|
6
|
+
onWheel: ["wheel", !0],
|
|
7
|
+
onPointerDown: ["pointerdown", !0],
|
|
8
|
+
onPointerUp: ["pointerup", !0],
|
|
9
|
+
onPointerLeave: ["pointerleave", !0],
|
|
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, e.size.height = e.gl.domElement.height, e.pointer.x = n.offsetX / (e.size.width / window.devicePixelRatio) * 2 - 1, e.pointer.y = 1 - n.offsetY / (e.size.height / window.devicePixelRatio) * 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
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
u as createEvents
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=main.js7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js7.mjs","sources":["../../../src/canvas/core/create-events.ts"],"sourcesContent":["import { Events, RenderProps, RootState, createEvents as createFiberEvents } from \"@react-three/fiber\";\nimport { UseBoundStore } from \"zustand\";\n\ntype DomEvent = PointerEvent | MouseEvent | WheelEvent;\n\nconst DOM_EVENTS = {\n onClick: [\"click\", false],\n onContextMenu: [\"contextmenu\", false],\n onDoubleClick: [\"dblclick\", false],\n onWheel: [\"wheel\", true],\n onPointerDown: [\"pointerdown\", true],\n onPointerUp: [\"pointerup\", true],\n onPointerLeave: [\"pointerleave\", true],\n onPointerMove: [\"pointermove\", true],\n onPointerCancel: [\"pointercancel\", true],\n onLostPointerCapture: [\"lostpointercapture\", true],\n} as const;\n\n/** ThreeLayer event manager for MapLibre and Mapbox */\nexport function createEvents(): RenderProps<HTMLCanvasElement>[\"events\"] {\n return (store: UseBoundStore<RootState>) => {\n const { handlePointer } = createFiberEvents(store);\n return {\n priority: 1,\n enabled: true,\n compute(event: DomEvent, state: RootState) {\n state.size.width = state.gl.domElement.width;\n state.size.height = state.gl.domElement.height;\n state.pointer.x = (event.offsetX / (state.size.width / window.devicePixelRatio)) * 2 - 1;\n state.pointer.y = 1 - (event.offsetY / (state.size.height / window.devicePixelRatio)) * 2;\n state.raycaster.camera = state.camera;\n state.raycaster.ray.origin.setScalar(0).applyMatrix4(state.camera.projectionMatrixInverse);\n state.raycaster.ray.direction\n .set(state.pointer.x, state.pointer.y, 1)\n .applyMatrix4(state.camera.projectionMatrixInverse)\n .sub(state.raycaster.ray.origin)\n .normalize();\n },\n connected: undefined,\n handlers: Object.keys(DOM_EVENTS).reduce(\n (acc, key) => ({ ...acc, [key]: handlePointer(key) }),\n {}\n ) as unknown as Events,\n update: () => {\n const { events, internal } = store.getState();\n if (internal.lastEvent?.current && events.handlers) {\n events.handlers.onPointerMove(internal.lastEvent.current);\n }\n },\n connect: (target: HTMLElement) => {\n const { set, events } = store.getState();\n events.disconnect?.();\n set((state) => ({ events: { ...state.events, connected: target.parentNode } }));\n Object.entries(events.handlers ?? []).forEach(([name, event]) => {\n const [eventName, passive] = DOM_EVENTS[name as keyof typeof DOM_EVENTS];\n target.addEventListener(eventName, event, { passive });\n });\n },\n disconnect: () => {\n const { set, events } = store.getState();\n if (events.connected) {\n Object.entries(events.handlers ?? []).forEach(([name, event]) => {\n if (events && events.connected instanceof HTMLElement) {\n const [eventName] = DOM_EVENTS[name as keyof typeof DOM_EVENTS];\n events.connected.removeEventListener(eventName, event);\n }\n });\n set((state) => ({ events: { ...state.events, connected: undefined } }));\n }\n },\n };\n };\n}\n"],"names":["DOM_EVENTS","createEvents","store","handlePointer","createFiberEvents","event","state","acc","key","events","internal","_a","target","set","name","eventName","passive"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js8.mjs","sources":["../../../src/canvas/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":["useFunction","callback","callbackRef","useRef","useCallback","args"],"mappings":";AAGa,MAAAA,IAAc,CAAoCC,MAAmB;AAC1E,QAAAC,IAAcC,EAAOF,CAAQ;AACnC,SAAAC,EAAY,UAAUD,GACfG,EAAY,IAAIC,MACdH,EAAY,QAAQ,GAAGG,CAAI,GACjC,CAAE,CAAA;AACP;"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-three-map",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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.js",
|
|
7
|
-
"types": "src/main.ts",
|
|
7
|
+
"types": "src/main-mapbox.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"repository": "https://github.com/RodrigoHamuy/react-three-map",
|
|
10
10
|
"homepage": "https://github.com/RodrigoHamuy/react-three-map",
|
|
@@ -16,8 +16,12 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"dev": "vite",
|
|
18
18
|
"prebuild": "tsc",
|
|
19
|
-
"build": "
|
|
20
|
-
"
|
|
19
|
+
"build": "yarn build:maplibre && yarn build:mapbox",
|
|
20
|
+
"build:maplibre": "cross-env LIB_MODE=1 MAP_MODE=0 vite build",
|
|
21
|
+
"postbuild:maplibre": "cross-env LIB_MODE=2 MAP_MODE=0 vite build",
|
|
22
|
+
"build:mapbox": "cross-env LIB_MODE=1 MAP_MODE=1 vite build",
|
|
23
|
+
"postbuild:mapbox": "cross-env LIB_MODE=2 MAP_MODE=1 vite build",
|
|
24
|
+
"release": "yarn build && yarn changeset publish",
|
|
21
25
|
"lint": "eslint src --ext ts,tsx --fix",
|
|
22
26
|
"preview": "vite preview",
|
|
23
27
|
"ts": "tsc -w",
|
|
@@ -26,6 +30,7 @@
|
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {},
|
|
28
32
|
"devDependencies": {
|
|
33
|
+
"@changesets/cli": "^2.26.1",
|
|
29
34
|
"@ladle/react": "^2.13.0",
|
|
30
35
|
"@react-three/drei": "^9.74.5",
|
|
31
36
|
"@react-three/fiber": "^8.13.3",
|
|
@@ -40,10 +45,12 @@
|
|
|
40
45
|
"eslint": "^8.38.0",
|
|
41
46
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
42
47
|
"eslint-plugin-react-refresh": "^0.3.4",
|
|
48
|
+
"leva": "^0.9.35",
|
|
49
|
+
"mapbox-gl": "^2.15.0",
|
|
43
50
|
"maplibre-gl": "^3.1.0",
|
|
44
51
|
"react": "^18.2.0",
|
|
45
52
|
"react-dom": "^18.2.0",
|
|
46
|
-
"react-map-gl": "^7.
|
|
53
|
+
"react-map-gl": "^7.0.25",
|
|
47
54
|
"three": "^0.153.0",
|
|
48
55
|
"three-stdlib": "^2.23.8",
|
|
49
56
|
"typescript": "~5.0.2",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RenderProps, extend } from "@react-three/fiber";
|
|
2
|
+
import { PropsWithChildren, memo, useMemo } from "react";
|
|
3
|
+
import * as THREE from "three";
|
|
4
|
+
import { coordsToMatrix } from "./core/coords-to-matrix";
|
|
5
|
+
import { InternalCanvas } from "./core/internal-canvas";
|
|
6
|
+
import { MercatorCoordinate } from "mapbox-gl";
|
|
7
|
+
|
|
8
|
+
extend(THREE);
|
|
9
|
+
|
|
10
|
+
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
11
|
+
longitude: number,
|
|
12
|
+
latitude: number,
|
|
13
|
+
altitude?: number,
|
|
14
|
+
frameloop?: 'always' | 'demand',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** react`-three-fiber` canvas inside `Mapbox` */
|
|
18
|
+
export const Canvas = memo<CanvasProps>(({
|
|
19
|
+
longitude, latitude, altitude = 0,
|
|
20
|
+
frameloop = 'always', ...renderProps
|
|
21
|
+
}) => {
|
|
22
|
+
|
|
23
|
+
const m4 = useMemo(() => coordsToMatrix({
|
|
24
|
+
latitude, longitude, altitude, fromLngLat: MercatorCoordinate.fromLngLat,
|
|
25
|
+
}), [latitude, longitude, altitude])
|
|
26
|
+
|
|
27
|
+
return <InternalCanvas
|
|
28
|
+
frameloop={frameloop}
|
|
29
|
+
m4={m4}
|
|
30
|
+
{...renderProps}
|
|
31
|
+
/>
|
|
32
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RenderProps, extend } from "@react-three/fiber";
|
|
2
|
+
import { MercatorCoordinate } from "maplibre-gl";
|
|
3
|
+
import { PropsWithChildren, memo, useMemo } from "react";
|
|
4
|
+
import * as THREE from "three";
|
|
5
|
+
import { coordsToMatrix } from "./core/coords-to-matrix";
|
|
6
|
+
import { InternalCanvas } from "./core/internal-canvas";
|
|
7
|
+
|
|
8
|
+
extend(THREE);
|
|
9
|
+
|
|
10
|
+
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
11
|
+
longitude: number,
|
|
12
|
+
latitude: number,
|
|
13
|
+
altitude?: number,
|
|
14
|
+
frameloop?: 'always' | 'demand',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** react`-three-fiber` canvas inside `MapLibre` */
|
|
18
|
+
export const Canvas = memo<CanvasProps>(({
|
|
19
|
+
longitude, latitude, altitude = 0,
|
|
20
|
+
frameloop = 'always', ...renderProps
|
|
21
|
+
}) => {
|
|
22
|
+
|
|
23
|
+
const m4 = useMemo(() => coordsToMatrix({
|
|
24
|
+
latitude, longitude, altitude, fromLngLat: MercatorCoordinate.fromLngLat,
|
|
25
|
+
}), [latitude, longitude, altitude])
|
|
26
|
+
|
|
27
|
+
return <InternalCanvas
|
|
28
|
+
frameloop={frameloop}
|
|
29
|
+
m4={m4}
|
|
30
|
+
{...renderProps}
|
|
31
|
+
/>
|
|
32
|
+
})
|