react-three-map 0.3.0 → 0.3.2
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 +12 -0
- package/README.md +9 -5
- package/dist/cjs/favicon.svg +1 -0
- package/dist/cjs/main.js +1 -0
- package/dist/es/favicon.svg +1 -0
- package/dist/es/main.mjs +5 -0
- package/dist/es/main.mjs.map +1 -0
- package/dist/es/{main.js2.mjs → main2.mjs} +3 -3
- package/dist/es/main2.mjs.map +1 -0
- package/dist/es/{main.js3.mjs → main3.mjs} +1 -1
- package/dist/es/main3.mjs.map +1 -0
- package/dist/es/{main.js4.mjs → main4.mjs} +3 -3
- package/dist/es/main4.mjs.map +1 -0
- package/dist/es/{main.js5.mjs → main5.mjs} +3 -3
- package/dist/es/main5.mjs.map +1 -0
- package/dist/{maplibre/es/main.js6.mjs → es/main6.mjs} +2 -2
- package/dist/es/main6.mjs.map +1 -0
- package/dist/es/{main.js7.mjs → main7.mjs} +2 -2
- package/dist/es/main7.mjs.map +1 -0
- package/dist/es/{main.js8.mjs → main8.mjs} +1 -1
- package/dist/es/main8.mjs.map +1 -0
- package/dist/maplibre/cjs/favicon.svg +1 -0
- package/dist/maplibre/cjs/main.js +1 -0
- package/dist/maplibre/es/favicon.svg +1 -0
- package/dist/maplibre/es/main.mjs +5 -0
- package/dist/maplibre/es/main.mjs.map +1 -0
- package/dist/maplibre/es/{main.js2.mjs → main2.mjs} +3 -3
- package/dist/maplibre/es/main2.mjs.map +1 -0
- package/dist/maplibre/es/{main.js3.mjs → main3.mjs} +1 -1
- package/dist/{es/main.js3.mjs.map → maplibre/es/main3.mjs.map} +1 -1
- package/dist/maplibre/es/{main.js4.mjs → main4.mjs} +3 -3
- package/dist/{es/main.js4.mjs.map → maplibre/es/main4.mjs.map} +1 -1
- package/dist/maplibre/es/{main.js5.mjs → main5.mjs} +3 -3
- package/dist/{es/main.js5.mjs.map → maplibre/es/main5.mjs.map} +1 -1
- package/dist/{es/main.js6.mjs → maplibre/es/main6.mjs} +2 -2
- package/dist/{es/main.js6.mjs.map → maplibre/es/main6.mjs.map} +1 -1
- package/dist/maplibre/es/{main.js7.mjs → main7.mjs} +2 -2
- package/dist/maplibre/es/main7.mjs.map +1 -0
- package/dist/maplibre/es/{main.js8.mjs → main8.mjs} +1 -1
- package/dist/{es/main.js8.mjs.map → maplibre/es/main8.mjs.map} +1 -1
- package/example-mapbox/src/canvas.basic.stories.tsx +19 -4
- package/example-mapbox/src/comparison.stories.tsx +16 -3
- package/example-mapbox/src/html-on-top.stories.tsx +1 -1
- package/example-mapbox/src/my-scene.tsx +3 -10
- package/example-mapbox/src/render-on-demand.stories.tsx +1 -1
- package/example-mapbox/src/story-map.tsx +18 -3
- package/example-maplibre/src/comparison.stories.tsx +15 -2
- package/example-maplibre/src/html-on-top.stories.tsx +1 -1
- package/example-maplibre/src/my-scene.tsx +3 -11
- package/maplibre/package.json +1 -1
- package/package.json +16 -4
- package/src/core/create-events.ts +4 -4
- package/src/core/use-on-add.ts +1 -1
- package/src/stories/comparison.stories.tsx +16 -2
- package/src/stories/html-on-top.stories.tsx +2 -2
- package/src/stories/mapbox/story-mapbox.tsx +20 -5
- package/src/stories/mapbox-example.stories.tsx +18 -3
- package/src/stories/my-scene.tsx +3 -11
- package/src/stories/render-on-demand.stories.tsx +7 -2
- package/src/stories/story-map.tsx +4 -11
- package/dist/cjs/main.js.js +0 -1
- package/dist/es/main.js.mjs +0 -5
- package/dist/es/main.js.mjs.map +0 -1
- package/dist/es/main.js2.mjs.map +0 -1
- package/dist/es/main.js7.mjs.map +0 -1
- package/dist/maplibre/cjs/main.js.js +0 -1
- package/dist/maplibre/es/main.js.mjs +0 -5
- package/dist/maplibre/es/main.js.mjs.map +0 -1
- package/dist/maplibre/es/main.js2.mjs.map +0 -1
- package/dist/maplibre/es/main.js3.mjs.map +0 -1
- package/dist/maplibre/es/main.js4.mjs.map +0 -1
- package/dist/maplibre/es/main.js5.mjs.map +0 -1
- package/dist/maplibre/es/main.js6.mjs.map +0 -1
- package/dist/maplibre/es/main.js7.mjs.map +0 -1
- package/dist/maplibre/es/main.js8.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# react-three-map
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b169844: Bug fix related to DPR devices and pointer events.
|
|
8
|
+
|
|
9
|
+
## 0.3.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 39acb3b: Fix build typo and add more detailed peer dependencies.
|
|
14
|
+
|
|
3
15
|
## 0.3.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
# React Three Map
|
|
1
|
+
# React Three Map
|
|
2
2
|
|
|
3
|
-
[](https://github.com/RodrigoHamuy/react-three-map)
|
|
4
|
+
[](https://npmjs.com/package/react-three-map)
|
|
5
|
+
[](https://bundlephobia.com/result?p=react-three-map)
|
|
6
|
+
[](https://rodrigohamuy.github.io/react-three-map/?story=canvas--a-maplibre-example)
|
|
7
|
+
[](https://github.com/RodrigoHamuy/react-three-map/actions?query=workflow%3Arelease)
|
|
4
8
|
|
|
5
9
|
`react-three-map` is a bridge to use [`react-three-fiber`](https://github.com/pmndrs/react-three-fiber) inside [`react-map-gl`](https://github.com/visgl/react-map-gl).
|
|
6
10
|
|
|
@@ -11,7 +15,7 @@ Until now you had:
|
|
|
11
15
|
| Mapbox GL JS | react-map-gl |
|
|
12
16
|
| THREE.js | react-three-fiber |
|
|
13
17
|
|
|
14
|
-
Now with `react-three-map`, you can use them together :fist_right::fist_left:.
|
|
18
|
+
Now with `react-three-map`, you can use them together :fist_right::star::fist_left:.
|
|
15
19
|
|
|
16
20
|
```sh
|
|
17
21
|
npm install react-three-map
|
|
@@ -19,7 +23,7 @@ npm install react-three-map
|
|
|
19
23
|
|
|
20
24
|
## :book: Examples
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
Check out our examples [here](https://rodrigohamuy.github.io/react-three-map) (powered by [Ladle](https://ladle.dev/)).
|
|
23
27
|
|
|
24
28
|
## :mag: What does it look like?
|
|
25
29
|
|
|
@@ -115,7 +119,7 @@ It shares most of the props from R3F `<Canvas>`, so you can check them directly
|
|
|
115
119
|
|
|
116
120
|
#### Render Props
|
|
117
121
|
|
|
118
|
-
|
|
|
122
|
+
| Prop | Description | Default |
|
|
119
123
|
| --------- | ------------------------------------------------ | ---------- |
|
|
120
124
|
| latitude | The latitude coordinate where to add the scene. | |
|
|
121
125
|
| longitude | The longitude coordinate where to add the scene. | |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#83af9b"></stop><stop offset="100%" stop-color="#fe4365"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path></svg>
|
package/dist/cjs/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),x=require("@react-three/fiber"),E=require("mapbox-gl"),l=require("react"),b=require("react-map-gl"),d=require("three");function j(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 C=j(d),y=new d.Quaternion,R=new d.Euler,w=new d.Vector3,M=new d.Vector3,z=new d.Matrix4;function S({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),y.setFromEuler(R.set(-Math.PI*.5,0,0)),z.compose(w,y,M).toArray()}const g={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 L(){return n=>{const{handlePointer:r}=x.createEvents(n);return{priority:1,enabled:!0,compute(t,e){e.size.width=e.gl.domElement.width/window.devicePixelRatio,e.size.height=e.gl.domElement.height/window.devicePixelRatio,e.pointer.x=t.offsetX/e.size.width*2-1,e.pointer.y=1-t.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()},connected:void 0,handlers:Object.keys(g).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,u])=>{const[i,s]=g[a];t.addEventListener(i,u,{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]=g[o];e.connected.removeEventListener(a,c)}}),t(o=>({events:{...o.events,connected:void 0}})))}}}}const p=n=>{const r=l.useRef(n);return r.current=n,l.useCallback((...t)=>r.current(...t),[])};function O(n,{frameloop:r,...t}){const[e,o]=l.useState(!1),c=p((i,s)=>{const m=i.getCanvas(),v=x.createRoot(m);v.configure({dpr:window.devicePixelRatio,events:L(),...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=p(()=>{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)}),u=p(i=>{setTimeout(()=>{n.current&&(n.current.root.unmount(),i.off("resize",a))})});return{onAdd:c,onRemove:u,mounted:e}}const T=new d.Matrix4;function A(n,r,t){return p((o,c)=>{var s;if(!((s=r.current)!=null&&s.state))return;const a=r.current.state.camera,u=r.current.state.gl,i=r.current.state.advance;a.projectionMatrix.fromArray(c).multiply(T.fromArray(n)),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),u.resetState(),i(Date.now()*.001,!0),t==="always"&&r.current.map.triggerRepaint()})}const q=({m4:n,children:r,frameloop:t,...e})=>{const o=l.useId(),c=l.useRef(),{onAdd:a,onRemove:u,mounted:i}=O(c,{frameloop:t,...e}),s=A(n,c,t);return l.useEffect(()=>{i&&c.current&&c.current.root.render(h.jsx(h.Fragment,{children:r}))},[c,i,r]),{id:o,onAdd:a,onRemove:u,render:s}};x.extend(C);const k=l.memo(({longitude:n,latitude:r,altitude:t=0,frameloop:e="always",...o})=>{const c=l.useMemo(()=>S({latitude:r,longitude:n,altitude:t,fromLngLat:E.MercatorCoordinate.fromLngLat}),[r,n,t]),{id:a,onAdd:u,onRemove:i,render:s}=q({m4:c,frameloop:e,...o});return h.jsx(b.Layer,{id:a,type:"custom",renderingMode:"3d",onAdd:u,onRemove:i,render:s})});exports.Canvas=k;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#83af9b"></stop><stop offset="100%" stop-color="#fe4365"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path></svg>
|
package/dist/es/main.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -4,8 +4,8 @@ import { MercatorCoordinate as c } from "mapbox-gl";
|
|
|
4
4
|
import { memo as L, useMemo as x } from "react";
|
|
5
5
|
import { Layer as M } from "react-map-gl";
|
|
6
6
|
import * as v from "three";
|
|
7
|
-
import { coordsToMatrix as y } from "./
|
|
8
|
-
import { useCanvas as C } from "./
|
|
7
|
+
import { coordsToMatrix as y } from "./main3.mjs";
|
|
8
|
+
import { useCanvas as C } from "./main4.mjs";
|
|
9
9
|
d(v);
|
|
10
10
|
const A = L(({
|
|
11
11
|
longitude: o,
|
|
@@ -35,4 +35,4 @@ const A = L(({
|
|
|
35
35
|
export {
|
|
36
36
|
A as Canvas
|
|
37
37
|
};
|
|
38
|
-
//# sourceMappingURL=
|
|
38
|
+
//# sourceMappingURL=main2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main2.mjs","sources":["../../src/mapbox/canvas.tsx"],"sourcesContent":["import { RenderProps, extend } from \"@react-three/fiber\";\nimport { MercatorCoordinate } from \"mapbox-gl\";\nimport { PropsWithChildren, memo, useMemo } from \"react\";\nimport { Layer } from \"react-map-gl\";\nimport * as THREE from \"three\";\nimport { coordsToMatrix } from \"../core/coords-to-matrix\";\nimport { useCanvas } from \"../core/use-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 const { id, onAdd, onRemove, render } = useCanvas({ m4, frameloop, ...renderProps });\n\n return <Layer\n id={id}\n type=\"custom\"\n renderingMode=\"3d\"\n onAdd={onAdd}\n onRemove={onRemove}\n render={render}\n />\n})"],"names":["extend","THREE","Canvas","memo","longitude","latitude","altitude","frameloop","renderProps","m4","useMemo","coordsToMatrix","MercatorCoordinate","id","onAdd","onRemove","render","useCanvas","jsx","Layer"],"mappings":";;;;;;;;AAQAA,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,GAE7B,EAAE,IAAAO,GAAI,OAAAC,GAAO,UAAAC,GAAU,QAAAC,EAAO,IAAIC,EAAU,EAAE,IAAAR,GAAI,WAAAF,GAAW,GAAGC,EAAa,CAAA;AAE5E,SAAA,gBAAAU;AAAA,IAACC;AAAA,IAAA;AAAA,MACN,IAAAN;AAAA,MACA,MAAK;AAAA,MACL,eAAc;AAAA,MACd,OAAAC;AAAA,MACA,UAAAC;AAAA,MACA,QAAAC;AAAA,IAAA;AAAA,EAAA;AAEJ,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main3.mjs","sources":["../../src/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;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as c, Fragment as i } from "react/jsx-runtime";
|
|
2
2
|
import { useId as p, useRef as R, useEffect as a } from "react";
|
|
3
|
-
import { useOnAdd as v } from "./
|
|
4
|
-
import { useRender as x } from "./
|
|
3
|
+
import { useOnAdd as v } from "./main5.mjs";
|
|
4
|
+
import { useRender as x } from "./main6.mjs";
|
|
5
5
|
const E = ({
|
|
6
6
|
m4: o,
|
|
7
7
|
children: r,
|
|
@@ -16,4 +16,4 @@ const E = ({
|
|
|
16
16
|
export {
|
|
17
17
|
E as useCanvas
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=main4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main4.mjs","sources":["../../src/core/use-canvas.tsx"],"sourcesContent":["import { RenderProps } from \"@react-three/fiber\";\nimport { PropsWithChildren, useEffect, useId, useRef } from \"react\";\nimport { Matrix4Tuple } from \"three\";\nimport { StateRef } from \"./state-ref\";\nimport { useOnAdd } from \"./use-on-add\";\nimport { useRender } from \"./use-render\";\n\nexport interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {\n frameloop: 'always' | 'demand',\n m4: Matrix4Tuple;\n}\n\nexport const useCanvas = (({\n m4, children, frameloop, ...renderProps\n}: useCanvasProps) => {\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 { id, onAdd, onRemove, render }\n})"],"names":["useCanvas","m4","children","frameloop","renderProps","id","useId","stateRef","useRef","onAdd","onRemove","mounted","useOnAdd","render","useRender","useEffect","jsx","Fragment"],"mappings":";;;;AAYO,MAAMA,IAAa,CAAC;AAAA,EACzB,IAAAC;AAAA,EAAI,UAAAC;AAAA,EAAU,WAAAC;AAAA,EAAW,GAAGC;AAC9B,MAAsB;AACpB,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,EAAE,IAAAG,GAAI,OAAAI,GAAO,UAAAC,GAAU,QAAAG,EAAO;AACvC;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRoot as v } from "@react-three/fiber";
|
|
2
2
|
import { useState as h } from "react";
|
|
3
|
-
import { createEvents as d } from "./
|
|
4
|
-
import { useFunction as a } from "./
|
|
3
|
+
import { createEvents as d } from "./main7.mjs";
|
|
4
|
+
import { useFunction as a } from "./main8.mjs";
|
|
5
5
|
function w(e, { frameloop: u, ...n }) {
|
|
6
6
|
const [l, r] = h(!1), g = a((t, m) => {
|
|
7
7
|
const o = t.getCanvas(), i = v(o);
|
|
@@ -57,4 +57,4 @@ function w(e, { frameloop: u, ...n }) {
|
|
|
57
57
|
export {
|
|
58
58
|
w as useOnAdd
|
|
59
59
|
};
|
|
60
|
-
//# sourceMappingURL=
|
|
60
|
+
//# sourceMappingURL=main5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main5.mjs","sources":["../../src/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, createRoot } from \"@react-three/fiber\";\nimport { useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { MapInstance } from \"./generic-map\";\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: MapInstance, 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: MapInstance) => {\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,GAAkBC,MAA8B;AAEnE,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,MAAqB;AACjD,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;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Matrix4 as u } from "three";
|
|
2
|
-
import { useFunction as m } from "./
|
|
2
|
+
import { useFunction as m } from "./main8.mjs";
|
|
3
3
|
const p = new u();
|
|
4
4
|
function g(n, r, o) {
|
|
5
5
|
return m((l, a) => {
|
|
@@ -13,4 +13,4 @@ function g(n, r, o) {
|
|
|
13
13
|
export {
|
|
14
14
|
g as useRender
|
|
15
15
|
};
|
|
16
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=main6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main6.mjs","sources":["../../src/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;"}
|
|
@@ -18,7 +18,7 @@ function u() {
|
|
|
18
18
|
priority: 1,
|
|
19
19
|
enabled: !0,
|
|
20
20
|
compute(n, e) {
|
|
21
|
-
e.size.width = e.gl.domElement.width, e.size.height = e.gl.domElement.height, e.pointer.x = n.offsetX /
|
|
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
22
|
},
|
|
23
23
|
connected: void 0,
|
|
24
24
|
handlers: Object.keys(c).reduce(
|
|
@@ -53,4 +53,4 @@ function u() {
|
|
|
53
53
|
export {
|
|
54
54
|
u as createEvents
|
|
55
55
|
};
|
|
56
|
-
//# sourceMappingURL=
|
|
56
|
+
//# sourceMappingURL=main7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main7.mjs","sources":["../../src/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 / window.devicePixelRatio;\n state.size.height = state.gl.domElement.height / window.devicePixelRatio;\n state.pointer.x = (event.offsetX / state.size.width) * 2 - 1;\n state.pointer.y = 1 - (event.offsetY / state.size.height) * 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":"main8.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":["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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#83af9b"></stop><stop offset="100%" stop-color="#fe4365"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),y=require("@react-three/fiber"),E=require("maplibre-gl"),l=require("react"),b=require("react-map-gl/maplibre"),d=require("three");function j(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 C=j(d),x=new d.Quaternion,R=new d.Euler,w=new d.Vector3,M=new d.Vector3,z=new d.Matrix4;function S({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)),z.compose(w,x,M).toArray()}const g={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 L(){return n=>{const{handlePointer:r}=y.createEvents(n);return{priority:1,enabled:!0,compute(t,e){e.size.width=e.gl.domElement.width/window.devicePixelRatio,e.size.height=e.gl.domElement.height/window.devicePixelRatio,e.pointer.x=t.offsetX/e.size.width*2-1,e.pointer.y=1-t.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()},connected:void 0,handlers:Object.keys(g).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,u])=>{const[i,s]=g[a];t.addEventListener(i,u,{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]=g[o];e.connected.removeEventListener(a,c)}}),t(o=>({events:{...o.events,connected:void 0}})))}}}}const p=n=>{const r=l.useRef(n);return r.current=n,l.useCallback((...t)=>r.current(...t),[])};function O(n,{frameloop:r,...t}){const[e,o]=l.useState(!1),c=p((i,s)=>{const m=i.getCanvas(),v=y.createRoot(m);v.configure({dpr:window.devicePixelRatio,events:L(),...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=p(()=>{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)}),u=p(i=>{setTimeout(()=>{n.current&&(n.current.root.unmount(),i.off("resize",a))})});return{onAdd:c,onRemove:u,mounted:e}}const T=new d.Matrix4;function A(n,r,t){return p((o,c)=>{var s;if(!((s=r.current)!=null&&s.state))return;const a=r.current.state.camera,u=r.current.state.gl,i=r.current.state.advance;a.projectionMatrix.fromArray(c).multiply(T.fromArray(n)),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),u.resetState(),i(Date.now()*.001,!0),t==="always"&&r.current.map.triggerRepaint()})}const q=({m4:n,children:r,frameloop:t,...e})=>{const o=l.useId(),c=l.useRef(),{onAdd:a,onRemove:u,mounted:i}=O(c,{frameloop:t,...e}),s=A(n,c,t);return l.useEffect(()=>{i&&c.current&&c.current.root.render(h.jsx(h.Fragment,{children:r}))},[c,i,r]),{id:o,onAdd:a,onRemove:u,render:s}};y.extend(C);const k=l.memo(({longitude:n,latitude:r,altitude:t=0,frameloop:e="always",...o})=>{const c=l.useMemo(()=>S({latitude:r,longitude:n,altitude:t,fromLngLat:E.MercatorCoordinate.fromLngLat}),[r,n,t]),{id:a,onAdd:u,onRemove:i,render:s}=q({m4:c,frameloop:e,...o});return h.jsx(b.Layer,{id:a,type:"custom",renderingMode:"3d",onAdd:u,onRemove:i,render:s})});exports.Canvas=k;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#83af9b"></stop><stop offset="100%" stop-color="#fe4365"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -4,8 +4,8 @@ import { MercatorCoordinate as c } from "maplibre-gl";
|
|
|
4
4
|
import { memo as L, useMemo as x } from "react";
|
|
5
5
|
import { Layer as M } from "react-map-gl/maplibre";
|
|
6
6
|
import * as v from "three";
|
|
7
|
-
import { coordsToMatrix as y } from "./
|
|
8
|
-
import { useCanvas as C } from "./
|
|
7
|
+
import { coordsToMatrix as y } from "./main3.mjs";
|
|
8
|
+
import { useCanvas as C } from "./main4.mjs";
|
|
9
9
|
d(v);
|
|
10
10
|
const A = L(({
|
|
11
11
|
longitude: o,
|
|
@@ -35,4 +35,4 @@ const A = L(({
|
|
|
35
35
|
export {
|
|
36
36
|
A as Canvas
|
|
37
37
|
};
|
|
38
|
-
//# sourceMappingURL=
|
|
38
|
+
//# sourceMappingURL=main2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main2.mjs","sources":["../../../src/maplibre/canvas.tsx"],"sourcesContent":["import { RenderProps, extend } from \"@react-three/fiber\";\nimport { MercatorCoordinate } from \"maplibre-gl\";\nimport { PropsWithChildren, memo, useMemo } from \"react\";\nimport { Layer } from \"react-map-gl/maplibre\";\nimport * as THREE from \"three\";\nimport { coordsToMatrix } from \"../core/coords-to-matrix\";\nimport { useCanvas } from \"../core/use-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 const { id, onAdd, onRemove, render } = useCanvas({ m4, frameloop, ...renderProps });\n\n return <Layer\n id={id}\n type=\"custom\"\n renderingMode=\"3d\"\n onAdd={onAdd}\n onRemove={onRemove}\n render={render}\n />\n})"],"names":["extend","THREE","Canvas","memo","longitude","latitude","altitude","frameloop","renderProps","m4","useMemo","coordsToMatrix","MercatorCoordinate","id","onAdd","onRemove","render","useCanvas","jsx","Layer"],"mappings":";;;;;;;;AAQAA,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,GAE7B,EAAE,IAAAO,GAAI,OAAAC,GAAO,UAAAC,GAAU,QAAAC,EAAO,IAAIC,EAAU,EAAE,IAAAR,GAAI,WAAAF,GAAW,GAAGC,EAAa,CAAA;AAE5E,SAAA,gBAAAU;AAAA,IAACC;AAAA,IAAA;AAAA,MACN,IAAAN;AAAA,MACA,MAAK;AAAA,MACL,eAAc;AAAA,MACd,OAAAC;AAAA,MACA,UAAAC;AAAA,MACA,QAAAC;AAAA,IAAA;AAAA,EAAA;AAEJ,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"main3.mjs","sources":["../../../src/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;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as c, Fragment as i } from "react/jsx-runtime";
|
|
2
2
|
import { useId as p, useRef as R, useEffect as a } from "react";
|
|
3
|
-
import { useOnAdd as v } from "./
|
|
4
|
-
import { useRender as x } from "./
|
|
3
|
+
import { useOnAdd as v } from "./main5.mjs";
|
|
4
|
+
import { useRender as x } from "./main6.mjs";
|
|
5
5
|
const E = ({
|
|
6
6
|
m4: o,
|
|
7
7
|
children: r,
|
|
@@ -16,4 +16,4 @@ const E = ({
|
|
|
16
16
|
export {
|
|
17
17
|
E as useCanvas
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=main4.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"main4.mjs","sources":["../../../src/core/use-canvas.tsx"],"sourcesContent":["import { RenderProps } from \"@react-three/fiber\";\nimport { PropsWithChildren, useEffect, useId, useRef } from \"react\";\nimport { Matrix4Tuple } from \"three\";\nimport { StateRef } from \"./state-ref\";\nimport { useOnAdd } from \"./use-on-add\";\nimport { useRender } from \"./use-render\";\n\nexport interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {\n frameloop: 'always' | 'demand',\n m4: Matrix4Tuple;\n}\n\nexport const useCanvas = (({\n m4, children, frameloop, ...renderProps\n}: useCanvasProps) => {\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 { id, onAdd, onRemove, render }\n})"],"names":["useCanvas","m4","children","frameloop","renderProps","id","useId","stateRef","useRef","onAdd","onRemove","mounted","useOnAdd","render","useRender","useEffect","jsx","Fragment"],"mappings":";;;;AAYO,MAAMA,IAAa,CAAC;AAAA,EACzB,IAAAC;AAAA,EAAI,UAAAC;AAAA,EAAU,WAAAC;AAAA,EAAW,GAAGC;AAC9B,MAAsB;AACpB,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,EAAE,IAAAG,GAAI,OAAAI,GAAO,UAAAC,GAAU,QAAAG,EAAO;AACvC;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRoot as v } from "@react-three/fiber";
|
|
2
2
|
import { useState as h } from "react";
|
|
3
|
-
import { createEvents as d } from "./
|
|
4
|
-
import { useFunction as a } from "./
|
|
3
|
+
import { createEvents as d } from "./main7.mjs";
|
|
4
|
+
import { useFunction as a } from "./main8.mjs";
|
|
5
5
|
function w(e, { frameloop: u, ...n }) {
|
|
6
6
|
const [l, r] = h(!1), g = a((t, m) => {
|
|
7
7
|
const o = t.getCanvas(), i = v(o);
|
|
@@ -57,4 +57,4 @@ function w(e, { frameloop: u, ...n }) {
|
|
|
57
57
|
export {
|
|
58
58
|
w as useOnAdd
|
|
59
59
|
};
|
|
60
|
-
//# sourceMappingURL=
|
|
60
|
+
//# sourceMappingURL=main5.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"main5.mjs","sources":["../../../src/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, createRoot } from \"@react-three/fiber\";\nimport { useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { MapInstance } from \"./generic-map\";\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: MapInstance, 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: MapInstance) => {\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,GAAkBC,MAA8B;AAEnE,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,MAAqB;AACjD,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;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Matrix4 as u } from "three";
|
|
2
|
-
import { useFunction as m } from "./
|
|
2
|
+
import { useFunction as m } from "./main8.mjs";
|
|
3
3
|
const p = new u();
|
|
4
4
|
function g(n, r, o) {
|
|
5
5
|
return m((l, a) => {
|
|
@@ -13,4 +13,4 @@ function g(n, r, o) {
|
|
|
13
13
|
export {
|
|
14
14
|
g as useRender
|
|
15
15
|
};
|
|
16
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=main6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"main6.mjs","sources":["../../../src/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;"}
|
|
@@ -18,7 +18,7 @@ function u() {
|
|
|
18
18
|
priority: 1,
|
|
19
19
|
enabled: !0,
|
|
20
20
|
compute(n, e) {
|
|
21
|
-
e.size.width = e.gl.domElement.width, e.size.height = e.gl.domElement.height, e.pointer.x = n.offsetX /
|
|
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
22
|
},
|
|
23
23
|
connected: void 0,
|
|
24
24
|
handlers: Object.keys(c).reduce(
|
|
@@ -53,4 +53,4 @@ function u() {
|
|
|
53
53
|
export {
|
|
54
54
|
u as createEvents
|
|
55
55
|
};
|
|
56
|
-
//# sourceMappingURL=
|
|
56
|
+
//# sourceMappingURL=main7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main7.mjs","sources":["../../../src/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 / window.devicePixelRatio;\n state.size.height = state.gl.domElement.height / window.devicePixelRatio;\n state.pointer.x = (event.offsetX / state.size.width) * 2 - 1;\n state.pointer.y = 1 - (event.offsetY / state.size.height) * 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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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"main8.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":["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;"}
|
|
@@ -2,7 +2,7 @@ import { useFrame, Vector3 } from "@react-three/fiber";
|
|
|
2
2
|
import { useControls } from "leva";
|
|
3
3
|
import Mapbox from "mapbox-gl";
|
|
4
4
|
import 'mapbox-gl/dist/mapbox-gl.css';
|
|
5
|
-
import { FC, useRef, useState } from "react";
|
|
5
|
+
import { FC, PropsWithChildren, useRef, useState } from "react";
|
|
6
6
|
import Map from 'react-map-gl';
|
|
7
7
|
import { Canvas } from "react-three-map";
|
|
8
8
|
import { Mesh } from "three";
|
|
@@ -38,12 +38,17 @@ const Box: FC<{ position: Vector3 }> = (props) => {
|
|
|
38
38
|
|
|
39
39
|
export function BasicExample() {
|
|
40
40
|
|
|
41
|
-
const { mapboxToken } = useControls({
|
|
41
|
+
const { mapboxToken } = useControls({
|
|
42
|
+
mapboxToken: {
|
|
43
|
+
value: import.meta.env.VITE_MAPBOX_TOKEN || '',
|
|
44
|
+
label: 'mapbox token',
|
|
45
|
+
}
|
|
46
|
+
})
|
|
42
47
|
|
|
43
48
|
Mapbox.accessToken = mapboxToken;
|
|
44
49
|
|
|
45
50
|
return <div style={{ height: '100vh' }}>
|
|
46
|
-
{!mapboxToken &&
|
|
51
|
+
{!mapboxToken && <Center>Add a mapbox token to load this component</Center>}
|
|
47
52
|
{mapboxToken && <Map
|
|
48
53
|
antialias
|
|
49
54
|
initialViewState={{
|
|
@@ -66,4 +71,14 @@ export function BasicExample() {
|
|
|
66
71
|
</Canvas>
|
|
67
72
|
</Map>}
|
|
68
73
|
</div>
|
|
69
|
-
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const Center = ({ children }: PropsWithChildren) => (
|
|
77
|
+
<div style={{
|
|
78
|
+
display: 'flex',
|
|
79
|
+
height: '100%',
|
|
80
|
+
width: '100%',
|
|
81
|
+
alignItems: 'center',
|
|
82
|
+
justifyContent: 'center',
|
|
83
|
+
}}>{children}</div>
|
|
84
|
+
)
|
|
@@ -3,22 +3,35 @@ import { Canvas as FiberCanvas } from "@react-three/fiber";
|
|
|
3
3
|
import { Canvas } from "react-three-map";
|
|
4
4
|
import { MyScene } from "./my-scene";
|
|
5
5
|
import { StoryMap } from "./story-map";
|
|
6
|
+
import { useControls } from "leva";
|
|
6
7
|
|
|
7
8
|
export function WithMap() {
|
|
9
|
+
const showCamHelper = useShowCamHelper()
|
|
8
10
|
return <div style={{ height: '100vh' }}>
|
|
9
11
|
<StoryMap latitude={51.5073218} longitude={-0.1276473} zoom={18}>
|
|
10
12
|
<Canvas latitude={51.5073218} longitude={-0.1276473} shadows="variance">
|
|
11
|
-
<MyScene />
|
|
13
|
+
<MyScene showCamHelper={showCamHelper} />
|
|
12
14
|
</Canvas>
|
|
13
15
|
</StoryMap>
|
|
14
16
|
</div>
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export const WithoutMap = () => {
|
|
20
|
+
const showCamHelper = useShowCamHelper()
|
|
18
21
|
return <div style={{ height: '100vh' }}>
|
|
19
|
-
<FiberCanvas camera={{position: [100,100,100]}} shadows="variance">
|
|
20
|
-
<MyScene />
|
|
22
|
+
<FiberCanvas camera={{ position: [100, 100, 100] }} shadows="variance">
|
|
23
|
+
<MyScene showCamHelper={showCamHelper} />
|
|
21
24
|
<MapControls makeDefault />
|
|
22
25
|
</FiberCanvas>
|
|
23
26
|
</div>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const useShowCamHelper = () => {
|
|
30
|
+
const { showCamHelper } = useControls({
|
|
31
|
+
showCamHelper: {
|
|
32
|
+
value: false,
|
|
33
|
+
label: 'show camera helper'
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return showCamHelper
|
|
24
37
|
}
|
|
@@ -10,7 +10,7 @@ export function Default() {
|
|
|
10
10
|
|
|
11
11
|
return <StoryMap latitude={51} longitude={0} zoom={13}>
|
|
12
12
|
<Canvas latitude={51} longitude={0} frameloop="demand">
|
|
13
|
-
<Html>
|
|
13
|
+
<Html center position={[0, 250, 0]} style={{ textAlign: 'center', fontSize: '2em', width: '10em', lineHeight: '1.5em' }}><i>Some</i> <b>HTML</b><br />content!</Html>
|
|
14
14
|
<Box
|
|
15
15
|
args={[500, 500, 500]}
|
|
16
16
|
position={[0, 250, 0]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Box, Plane, useHelper } from "@react-three/drei";
|
|
2
2
|
import { MeshProps, useFrame, useThree } from '@react-three/fiber';
|
|
3
|
-
import { useControls } from "leva";
|
|
4
3
|
import { useCallback, useRef, useState } from 'react';
|
|
5
4
|
import { CameraHelper, MathUtils, Mesh, OrthographicCamera } from "three";
|
|
6
5
|
|
|
7
|
-
export function MyScene() {
|
|
6
|
+
export function MyScene({ showCamHelper }: { showCamHelper?: boolean }) {
|
|
8
7
|
return <>
|
|
9
|
-
<Lights />
|
|
8
|
+
<Lights showCamHelper={showCamHelper} />
|
|
10
9
|
<Floor />
|
|
11
10
|
<MyBox position={[-8 * 3, 8 * 1.5, 0]} />
|
|
12
11
|
<MyBox position={[8 * 3, 8 * 1.5, 0]} />
|
|
@@ -52,15 +51,9 @@ function MyBox(props: MeshProps) {
|
|
|
52
51
|
</Box>
|
|
53
52
|
);
|
|
54
53
|
}
|
|
55
|
-
function Lights() {
|
|
54
|
+
function Lights({ showCamHelper }: { showCamHelper?: boolean }) {
|
|
56
55
|
const cam = useRef<OrthographicCamera>(null);
|
|
57
56
|
const noCam = useRef<OrthographicCamera>(null);
|
|
58
|
-
const { showCamHelper } = useControls({
|
|
59
|
-
showCamHelper: {
|
|
60
|
-
value: false,
|
|
61
|
-
label: 'show camera helper'
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
57
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
58
|
useHelper((showCamHelper ? cam : noCam) as any, CameraHelper)
|
|
66
59
|
const camSize = 100;
|