react-three-map 0.4.3 → 0.6.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 +16 -0
- package/README.md +14 -0
- package/dist/cjs/main.js +91 -85
- package/dist/es/main.mjs +5 -2
- package/dist/es/main.mjs.map +1 -1
- package/dist/es/main10.mjs +20 -19
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +17 -72
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main12.mjs +75 -9
- package/dist/es/main12.mjs.map +1 -1
- package/dist/es/main13.mjs +8 -67
- package/dist/es/main13.mjs.map +1 -1
- package/dist/es/main14.mjs +71 -0
- package/dist/es/main14.mjs.map +1 -0
- package/dist/es/main2.mjs +5 -23
- package/dist/es/main2.mjs.map +1 -1
- package/dist/es/main4.mjs +24 -22
- package/dist/es/main4.mjs.map +1 -1
- package/dist/es/main7.mjs +1 -1
- package/dist/es/main8.mjs +21 -14
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +15 -21
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +91 -85
- package/dist/maplibre/es/main.mjs +5 -2
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main10.mjs +21 -15
- package/dist/maplibre/es/main10.mjs.map +1 -1
- package/dist/maplibre/es/main11.mjs +17 -72
- package/dist/maplibre/es/main11.mjs.map +1 -1
- package/dist/maplibre/es/main12.mjs +75 -9
- package/dist/maplibre/es/main12.mjs.map +1 -1
- package/dist/maplibre/es/main13.mjs +8 -67
- package/dist/maplibre/es/main13.mjs.map +1 -1
- package/dist/maplibre/es/main14.mjs +71 -0
- package/dist/maplibre/es/main14.mjs.map +1 -0
- package/dist/maplibre/es/main2.mjs +5 -23
- package/dist/maplibre/es/main2.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +24 -22
- package/dist/maplibre/es/main4.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +1 -1
- package/dist/maplibre/es/main8.mjs +20 -19
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/es/main9.mjs +14 -19
- package/dist/maplibre/es/main9.mjs.map +1 -1
- package/dist/maplibre/types/api/use-map.d.ts +2 -0
- package/dist/maplibre/types/maplibre.index.d.ts +3 -1
- package/dist/types/api/use-map.d.ts +2 -0
- package/dist/types/mapbox.index.d.ts +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# react-three-map
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3a9a852: Add `useMap` hook to access the map from react-three-map.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 3a9a852: Better type for `useMap`.
|
|
12
|
+
|
|
13
|
+
## 0.5.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 7921f43: Add `useMap` hook to access the map from react-three-map.
|
|
18
|
+
|
|
3
19
|
## 0.4.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -163,3 +163,17 @@ import { Canvas, Coordinates } from 'react-three-map'
|
|
|
163
163
|
| latitude | The latitude coordinate where to add the scene. | |
|
|
164
164
|
| longitude | The longitude coordinate where to add the scene. | |
|
|
165
165
|
| altitude | The altitude coordinate where to add the scene. | `0` |
|
|
166
|
+
|
|
167
|
+
### useMap
|
|
168
|
+
|
|
169
|
+
Access the map from inside `react-three-map`.
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import { useMap } from "react-three-map";
|
|
173
|
+
// import { useMap } from "react-three-map/maplibre"; if you use maplibre
|
|
174
|
+
const Component = () => {
|
|
175
|
+
const map = useMap();
|
|
176
|
+
return <>...</>
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
```
|
package/dist/cjs/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
3
|
const fiber = require("@react-three/fiber");
|
|
5
|
-
const
|
|
4
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
6
5
|
const react = require("react");
|
|
7
|
-
const reactMapGl = require("react-map-gl");
|
|
8
6
|
const THREE = require("three");
|
|
7
|
+
const mapboxGl = require("mapbox-gl");
|
|
8
|
+
const reactMapGl = require("react-map-gl");
|
|
9
9
|
function _interopNamespaceDefault(e) {
|
|
10
10
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
11
|
if (e) {
|
|
@@ -23,6 +23,43 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
return Object.freeze(n);
|
|
24
24
|
}
|
|
25
25
|
const THREE__namespace = /* @__PURE__ */ _interopNamespaceDefault(THREE);
|
|
26
|
+
const useMap$1 = () => fiber.useThree((s) => {
|
|
27
|
+
var _a;
|
|
28
|
+
return (_a = s.r3m) == null ? void 0 : _a.map;
|
|
29
|
+
});
|
|
30
|
+
const useR3M = () => fiber.useThree((s) => s.r3m);
|
|
31
|
+
const originMx = new THREE.Matrix4();
|
|
32
|
+
const projByView = new THREE.Matrix4();
|
|
33
|
+
const projByViewInv$1 = new THREE.Matrix4();
|
|
34
|
+
const fwd = new THREE.Vector3();
|
|
35
|
+
function syncCamera(camera, origin, mapCamMx) {
|
|
36
|
+
projByView.fromArray(mapCamMx).multiply(originMx.fromArray(origin));
|
|
37
|
+
projByViewInv$1.copy(projByView).invert();
|
|
38
|
+
updateCamera(camera, projByViewInv$1);
|
|
39
|
+
camera.updateMatrix();
|
|
40
|
+
camera.updateMatrixWorld(true);
|
|
41
|
+
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
42
|
+
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
43
|
+
camera.far = calculateFar(
|
|
44
|
+
camera.matrix.elements[10],
|
|
45
|
+
camera.matrix.elements[14],
|
|
46
|
+
camera.near
|
|
47
|
+
);
|
|
48
|
+
camera.userData.projByView = projByView.toArray();
|
|
49
|
+
camera.userData.projByViewInv = projByViewInv$1.toArray();
|
|
50
|
+
}
|
|
51
|
+
const updateCamera = (target, projByViewInv2) => {
|
|
52
|
+
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
53
|
+
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
54
|
+
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
55
|
+
target.lookAt(fwd);
|
|
56
|
+
};
|
|
57
|
+
function calculateFar(c, d, near) {
|
|
58
|
+
const numerator = d * (c - 1);
|
|
59
|
+
const denominator = c * near + near;
|
|
60
|
+
const far = numerator / denominator;
|
|
61
|
+
return far;
|
|
62
|
+
}
|
|
26
63
|
const quat = new THREE.Quaternion();
|
|
27
64
|
const euler = new THREE.Euler();
|
|
28
65
|
const pos = new THREE.Vector3();
|
|
@@ -45,6 +82,51 @@ function useCoords({ latitude, longitude, altitude, fromLngLat: fromLngLat2 }) {
|
|
|
45
82
|
}), [latitude, longitude, altitude, fromLngLat2]);
|
|
46
83
|
return m42;
|
|
47
84
|
}
|
|
85
|
+
const Coordinates = react.memo(({
|
|
86
|
+
latitude,
|
|
87
|
+
longitude,
|
|
88
|
+
altitude = 0,
|
|
89
|
+
children
|
|
90
|
+
}) => {
|
|
91
|
+
const [scene] = react.useState(() => new THREE.Scene());
|
|
92
|
+
const r3m = useR3M();
|
|
93
|
+
const origin = useCoords({
|
|
94
|
+
latitude,
|
|
95
|
+
longitude,
|
|
96
|
+
altitude,
|
|
97
|
+
fromLngLat: r3m.fromLngLat
|
|
98
|
+
});
|
|
99
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fiber.createPortal(/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
100
|
+
/* @__PURE__ */ jsxRuntime.jsx(RenderAtCoords, { r3m, origin }),
|
|
101
|
+
children
|
|
102
|
+
] }), scene, { events: { priority: 2 } }) });
|
|
103
|
+
});
|
|
104
|
+
Coordinates.displayName = "Coordinates";
|
|
105
|
+
function RenderAtCoords({ r3m, origin }) {
|
|
106
|
+
const { gl, scene, set } = fiber.useThree();
|
|
107
|
+
const cameraRef = react.useRef(null);
|
|
108
|
+
fiber.useFrame(() => {
|
|
109
|
+
if (!r3m.mapCamMx)
|
|
110
|
+
return;
|
|
111
|
+
if (!cameraRef.current)
|
|
112
|
+
return;
|
|
113
|
+
syncCamera(cameraRef.current, origin, r3m.mapCamMx);
|
|
114
|
+
gl.render(scene, cameraRef.current);
|
|
115
|
+
});
|
|
116
|
+
react.useLayoutEffect(() => {
|
|
117
|
+
if (!cameraRef.current)
|
|
118
|
+
return;
|
|
119
|
+
set({
|
|
120
|
+
invalidate: () => {
|
|
121
|
+
if (!r3m.map)
|
|
122
|
+
return;
|
|
123
|
+
r3m.map.triggerRepaint();
|
|
124
|
+
},
|
|
125
|
+
camera: cameraRef.current
|
|
126
|
+
});
|
|
127
|
+
}, [set, r3m]);
|
|
128
|
+
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
129
|
+
}
|
|
48
130
|
const DOM_EVENTS = {
|
|
49
131
|
onClick: ["click", false],
|
|
50
132
|
onContextMenu: ["contextmenu", false],
|
|
@@ -57,7 +139,7 @@ const DOM_EVENTS = {
|
|
|
57
139
|
onPointerCancel: ["pointercancel", true],
|
|
58
140
|
onLostPointerCapture: ["lostpointercapture", true]
|
|
59
141
|
};
|
|
60
|
-
const projByViewInv
|
|
142
|
+
const projByViewInv = new THREE.Matrix4();
|
|
61
143
|
function createEvents() {
|
|
62
144
|
return (store) => {
|
|
63
145
|
const { handlePointer } = fiber.createEvents(store);
|
|
@@ -68,10 +150,10 @@ function createEvents() {
|
|
|
68
150
|
state.pointer.x = event.offsetX / state.size.width * 2 - 1;
|
|
69
151
|
state.pointer.y = 1 - event.offsetY / state.size.height * 2;
|
|
70
152
|
if (state.camera.userData.projByViewInv)
|
|
71
|
-
projByViewInv
|
|
153
|
+
projByViewInv.fromArray(state.camera.userData.projByViewInv);
|
|
72
154
|
state.raycaster.camera = state.camera;
|
|
73
|
-
state.raycaster.ray.origin.setScalar(0).applyMatrix4(projByViewInv
|
|
74
|
-
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(projByViewInv
|
|
155
|
+
state.raycaster.ray.origin.setScalar(0).applyMatrix4(projByViewInv);
|
|
156
|
+
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(projByViewInv).sub(state.raycaster.ray.origin).normalize();
|
|
75
157
|
},
|
|
76
158
|
connected: void 0,
|
|
77
159
|
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
@@ -204,38 +286,6 @@ const useCreateRoot = ({
|
|
|
204
286
|
}, [r3mRef, mounted, children]);
|
|
205
287
|
return { id, onAdd, onRemove, r3mRef };
|
|
206
288
|
};
|
|
207
|
-
const originMx = new THREE.Matrix4();
|
|
208
|
-
const projByView = new THREE.Matrix4();
|
|
209
|
-
const projByViewInv = new THREE.Matrix4();
|
|
210
|
-
const fwd = new THREE.Vector3();
|
|
211
|
-
function syncCamera(camera, origin, mapCamMx) {
|
|
212
|
-
projByView.fromArray(mapCamMx).multiply(originMx.fromArray(origin));
|
|
213
|
-
projByViewInv.copy(projByView).invert();
|
|
214
|
-
updateCamera(camera, projByViewInv);
|
|
215
|
-
camera.updateMatrix();
|
|
216
|
-
camera.updateMatrixWorld(true);
|
|
217
|
-
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
218
|
-
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
219
|
-
camera.far = calculateFar(
|
|
220
|
-
camera.matrix.elements[10],
|
|
221
|
-
camera.matrix.elements[14],
|
|
222
|
-
camera.near
|
|
223
|
-
);
|
|
224
|
-
camera.userData.projByView = projByView.toArray();
|
|
225
|
-
camera.userData.projByViewInv = projByViewInv.toArray();
|
|
226
|
-
}
|
|
227
|
-
const updateCamera = (target, projByViewInv2) => {
|
|
228
|
-
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
229
|
-
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
230
|
-
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
231
|
-
target.lookAt(fwd);
|
|
232
|
-
};
|
|
233
|
-
function calculateFar(c, d, near) {
|
|
234
|
-
const numerator = d * (c - 1);
|
|
235
|
-
const denominator = c * near + near;
|
|
236
|
-
const far = numerator / denominator;
|
|
237
|
-
return far;
|
|
238
|
-
}
|
|
239
289
|
function useRender(origin, r3mRef, frameloop) {
|
|
240
290
|
const render = useFunction((_gl, mapCamMx) => {
|
|
241
291
|
const r3m = r3mRef.current;
|
|
@@ -287,51 +337,7 @@ const Canvas = react.memo((props) => {
|
|
|
287
337
|
}
|
|
288
338
|
);
|
|
289
339
|
});
|
|
290
|
-
const
|
|
291
|
-
const Coordinates = react.memo(({
|
|
292
|
-
latitude,
|
|
293
|
-
longitude,
|
|
294
|
-
altitude = 0,
|
|
295
|
-
children
|
|
296
|
-
}) => {
|
|
297
|
-
const [scene] = react.useState(() => new THREE.Scene());
|
|
298
|
-
const r3m = useR3M();
|
|
299
|
-
const origin = useCoords({
|
|
300
|
-
latitude,
|
|
301
|
-
longitude,
|
|
302
|
-
altitude,
|
|
303
|
-
fromLngLat: r3m.fromLngLat
|
|
304
|
-
});
|
|
305
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fiber.createPortal(/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
306
|
-
/* @__PURE__ */ jsxRuntime.jsx(RenderAtCoords, { r3m, origin }),
|
|
307
|
-
children
|
|
308
|
-
] }), scene, { events: { priority: 2 } }) });
|
|
309
|
-
});
|
|
310
|
-
Coordinates.displayName = "Coordinates";
|
|
311
|
-
function RenderAtCoords({ r3m, origin }) {
|
|
312
|
-
const { gl, scene, set } = fiber.useThree();
|
|
313
|
-
const cameraRef = react.useRef(null);
|
|
314
|
-
fiber.useFrame(() => {
|
|
315
|
-
if (!r3m.mapCamMx)
|
|
316
|
-
return;
|
|
317
|
-
if (!cameraRef.current)
|
|
318
|
-
return;
|
|
319
|
-
syncCamera(cameraRef.current, origin, r3m.mapCamMx);
|
|
320
|
-
gl.render(scene, cameraRef.current);
|
|
321
|
-
});
|
|
322
|
-
react.useLayoutEffect(() => {
|
|
323
|
-
if (!cameraRef.current)
|
|
324
|
-
return;
|
|
325
|
-
set({
|
|
326
|
-
invalidate: () => {
|
|
327
|
-
if (!r3m.map)
|
|
328
|
-
return;
|
|
329
|
-
r3m.map.triggerRepaint();
|
|
330
|
-
},
|
|
331
|
-
camera: cameraRef.current
|
|
332
|
-
});
|
|
333
|
-
}, [set, r3m]);
|
|
334
|
-
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
335
|
-
}
|
|
340
|
+
const useMap = useMap$1;
|
|
336
341
|
exports.Canvas = Canvas;
|
|
337
342
|
exports.Coordinates = Coordinates;
|
|
343
|
+
exports.useMap = useMap;
|
package/dist/es/main.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMap as useMap$1 } from "./main2.mjs";
|
|
2
2
|
import { Coordinates } from "./main3.mjs";
|
|
3
|
+
import { Canvas } from "./main4.mjs";
|
|
4
|
+
const useMap = useMap$1;
|
|
3
5
|
export {
|
|
4
6
|
Canvas,
|
|
5
|
-
Coordinates
|
|
7
|
+
Coordinates,
|
|
8
|
+
useMap
|
|
6
9
|
};
|
|
7
10
|
//# sourceMappingURL=main.mjs.map
|
package/dist/es/main.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":["../../src/mapbox.index.ts"],"sourcesContent":["import type { Map } from 'mapbox-gl';\nimport { useMap as useMapGeneric } from './api/use-map';\n\nexport * from './api/canvas-props';\nexport * from './api/coordinates';\nexport * from './mapbox/canvas';\n\nexport const useMap = useMapGeneric<Map>;\n"],"names":["useMapGeneric"],"mappings":";;;AAOO,MAAM,SAASA;"}
|
package/dist/es/main10.mjs
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useEffect } from "react";
|
|
3
|
+
import { useOnAdd } from "./main12.mjs";
|
|
4
|
+
const useCreateRoot = ({
|
|
5
|
+
children,
|
|
6
|
+
frameloop,
|
|
7
|
+
fromLngLat,
|
|
8
|
+
...renderProps
|
|
9
|
+
}) => {
|
|
10
|
+
const id = useId();
|
|
11
|
+
const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat, { frameloop, ...renderProps });
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!mounted)
|
|
7
14
|
return;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
advance(Date.now() * 1e-3, true);
|
|
15
|
-
if (frameloop === "always")
|
|
16
|
-
r3m.map.triggerRepaint();
|
|
17
|
-
});
|
|
18
|
-
return render;
|
|
19
|
-
}
|
|
15
|
+
if (!r3mRef.current.root)
|
|
16
|
+
return;
|
|
17
|
+
r3mRef.current.root.render(/* @__PURE__ */ jsx(Fragment, { children }));
|
|
18
|
+
}, [r3mRef, mounted, children]);
|
|
19
|
+
return { id, onAdd, onRemove, r3mRef };
|
|
20
|
+
};
|
|
20
21
|
export {
|
|
21
|
-
|
|
22
|
+
useCreateRoot
|
|
22
23
|
};
|
|
23
24
|
//# sourceMappingURL=main10.mjs.map
|
package/dist/es/main10.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main10.mjs","sources":["../../src/core/use-
|
|
1
|
+
{"version":3,"file":"main10.mjs","sources":["../../src/core/use-create-root.tsx"],"sourcesContent":["import { RenderProps } from \"@react-three/fiber\";\nimport { PropsWithChildren, useEffect, useId } from \"react\";\nimport { FromLngLat } from \"./generic-map\";\nimport { useOnAdd } from \"./use-on-add\";\n\nexport interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {\n frameloop: 'always' | 'demand',\n fromLngLat: FromLngLat\n}\n\nexport const useCreateRoot = (({\n children, frameloop, fromLngLat, ...renderProps\n}: useCanvasProps) => {\n\n const id = useId();\n\n const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat, { frameloop, ...renderProps });\n\n useEffect(() => {\n if (!mounted) return;\n if (!r3mRef.current.root) return;\n r3mRef.current.root.render(<>\n {children}\n </>);\n }, [r3mRef, mounted, children])\n\n return { id, onAdd, onRemove, r3mRef }\n})"],"names":[],"mappings":";;;AAUO,MAAM,gBAAiB,CAAC;AAAA,EAC7B;AAAA,EAAU;AAAA,EAAW;AAAA,EAAY,GAAG;AACtC,MAAsB;AAEpB,QAAM,KAAK;AAEX,QAAM,EAAE,OAAO,UAAU,SAAS,OAAO,IAAI,SAAS,YAAY,EAAE,WAAW,GAAG,YAAa,CAAA;AAE/F,YAAU,MAAM;AACd,QAAI,CAAC;AAAS;AACV,QAAA,CAAC,OAAO,QAAQ;AAAM;AAC1B,WAAO,QAAQ,KAAK,OAAO,oBAAA,UAAA,EACxB,SACH,CAAA,CAAG;AAAA,EACF,GAAA,CAAC,QAAQ,SAAS,QAAQ,CAAC;AAE9B,SAAO,EAAE,IAAI,OAAO,UAAU,OAAO;AACvC;"}
|
package/dist/es/main11.mjs
CHANGED
|
@@ -1,78 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const r3mRef = useRef({ fromLngLat });
|
|
8
|
-
const onAdd = useFunction((map, gl) => {
|
|
9
|
-
const canvas = map.getCanvas();
|
|
10
|
-
const root = createRoot(canvas);
|
|
11
|
-
root.configure({
|
|
12
|
-
dpr: window.devicePixelRatio,
|
|
13
|
-
events: createEvents(),
|
|
14
|
-
...renderProps,
|
|
15
|
-
frameloop: "never",
|
|
16
|
-
gl: {
|
|
17
|
-
context: gl,
|
|
18
|
-
depth: true,
|
|
19
|
-
autoClear: false,
|
|
20
|
-
antialias: true,
|
|
21
|
-
...renderProps == null ? void 0 : renderProps.gl
|
|
22
|
-
},
|
|
23
|
-
onCreated: (state) => {
|
|
24
|
-
state.gl.forceContextLoss = () => {
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
camera: {
|
|
28
|
-
matrixAutoUpdate: false,
|
|
29
|
-
near: 0
|
|
30
|
-
},
|
|
31
|
-
size: {
|
|
32
|
-
width: canvas.clientWidth,
|
|
33
|
-
height: canvas.clientHeight,
|
|
34
|
-
top: 0,
|
|
35
|
-
left: 0,
|
|
36
|
-
...renderProps == null ? void 0 : renderProps.size
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
const store = _roots.get(canvas).store;
|
|
40
|
-
r3mRef.current.map = map;
|
|
41
|
-
r3mRef.current.root = root;
|
|
42
|
-
r3mRef.current.state = store.getState();
|
|
43
|
-
store.setState({ r3m: r3mRef.current });
|
|
44
|
-
if (frameloop === "demand") {
|
|
45
|
-
store.setState({
|
|
46
|
-
frameloop,
|
|
47
|
-
invalidate: () => {
|
|
48
|
-
map.triggerRepaint();
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
map.on("resize", onResize);
|
|
53
|
-
setTimeout(() => setMounted(true));
|
|
54
|
-
});
|
|
55
|
-
const onResize = useFunction(() => {
|
|
56
|
-
if (!r3mRef.current.map)
|
|
57
|
-
return;
|
|
58
|
-
if (!r3mRef.current.state)
|
|
59
|
-
return;
|
|
60
|
-
const canvas = r3mRef.current.map.getCanvas();
|
|
61
|
-
r3mRef.current.state.setSize(canvas.width, canvas.height);
|
|
62
|
-
});
|
|
63
|
-
const onRemove = useFunction(() => {
|
|
64
|
-
if (!r3mRef.current.root)
|
|
65
|
-
return;
|
|
66
|
-
r3mRef.current.root.unmount();
|
|
67
|
-
r3mRef.current.root = void 0;
|
|
68
|
-
if (!r3mRef.current.map)
|
|
1
|
+
import { syncCamera } from "./main6.mjs";
|
|
2
|
+
import { useFunction } from "./main13.mjs";
|
|
3
|
+
function useRender(origin, r3mRef, frameloop) {
|
|
4
|
+
const render = useFunction((_gl, mapCamMx) => {
|
|
5
|
+
const r3m = r3mRef.current;
|
|
6
|
+
if (!r3m.state || !r3m.map)
|
|
69
7
|
return;
|
|
70
|
-
|
|
8
|
+
const camera = r3m.state.camera;
|
|
9
|
+
const gl = r3m.state.gl;
|
|
10
|
+
const advance = r3m.state.advance;
|
|
11
|
+
r3m.mapCamMx = mapCamMx;
|
|
12
|
+
syncCamera(camera, origin, mapCamMx);
|
|
13
|
+
gl.resetState();
|
|
14
|
+
advance(Date.now() * 1e-3, true);
|
|
15
|
+
if (frameloop === "always")
|
|
16
|
+
r3m.map.triggerRepaint();
|
|
71
17
|
});
|
|
72
|
-
|
|
73
|
-
return { onAdd, onRemove, mounted, r3mRef };
|
|
18
|
+
return render;
|
|
74
19
|
}
|
|
75
20
|
export {
|
|
76
|
-
|
|
21
|
+
useRender
|
|
77
22
|
};
|
|
78
23
|
//# sourceMappingURL=main11.mjs.map
|
package/dist/es/main11.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main11.mjs","sources":["../../src/core/use-
|
|
1
|
+
{"version":3,"file":"main11.mjs","sources":["../../src/core/use-render.ts"],"sourcesContent":["import { MutableRefObject } from \"react\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { R3mStore } from \"./store\";\nimport { syncCamera } from \"./sync-camera\";\nimport { useFunction } from \"./use-function\";\n\nexport function useRender(\n origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'\n) {\n\n const render = useFunction((_gl: WebGL2RenderingContext, mapCamMx: number[]) => {\n const r3m = r3mRef.current;\n if (!r3m.state || !r3m.map) return;\n const camera = r3m.state.camera;\n const gl = r3m.state.gl;\n const advance = r3m.state.advance;\n r3m.mapCamMx = mapCamMx as Matrix4Tuple;\n syncCamera(camera as PerspectiveCamera, origin, mapCamMx as Matrix4Tuple);\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (frameloop === 'always') r3m.map.triggerRepaint();\n })\n\n return render;\n\n}"],"names":[],"mappings":";;AAMgB,SAAA,UACd,QAAsB,QAAoC,WAC1D;AAEA,QAAM,SAAS,YAAY,CAAC,KAA6B,aAAuB;AAC9E,UAAM,MAAM,OAAO;AACnB,QAAI,CAAC,IAAI,SAAS,CAAC,IAAI;AAAK;AACtB,UAAA,SAAS,IAAI,MAAM;AACnB,UAAA,KAAK,IAAI,MAAM;AACf,UAAA,UAAU,IAAI,MAAM;AAC1B,QAAI,WAAW;AACJ,eAAA,QAA6B,QAAQ,QAAwB;AACxE,OAAG,WAAW;AACd,YAAQ,KAAK,IAAQ,IAAA,MAAO,IAAI;AAChC,QAAI,cAAc;AAAU,UAAI,IAAI;EAAe,CACpD;AAEM,SAAA;AAET;"}
|
package/dist/es/main12.mjs
CHANGED
|
@@ -1,12 +1,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
1
|
+
import { createRoot, _roots } from "@react-three/fiber";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import { createEvents } from "./main14.mjs";
|
|
4
|
+
import { useFunction } from "./main13.mjs";
|
|
5
|
+
function useOnAdd(fromLngLat, { frameloop, ...renderProps }) {
|
|
6
|
+
const [mounted, setMounted] = useState(false);
|
|
7
|
+
const r3mRef = useRef({ fromLngLat });
|
|
8
|
+
const onAdd = useFunction((map, gl) => {
|
|
9
|
+
const canvas = map.getCanvas();
|
|
10
|
+
const root = createRoot(canvas);
|
|
11
|
+
root.configure({
|
|
12
|
+
dpr: window.devicePixelRatio,
|
|
13
|
+
events: createEvents(),
|
|
14
|
+
...renderProps,
|
|
15
|
+
frameloop: "never",
|
|
16
|
+
gl: {
|
|
17
|
+
context: gl,
|
|
18
|
+
depth: true,
|
|
19
|
+
autoClear: false,
|
|
20
|
+
antialias: true,
|
|
21
|
+
...renderProps == null ? void 0 : renderProps.gl
|
|
22
|
+
},
|
|
23
|
+
onCreated: (state) => {
|
|
24
|
+
state.gl.forceContextLoss = () => {
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
camera: {
|
|
28
|
+
matrixAutoUpdate: false,
|
|
29
|
+
near: 0
|
|
30
|
+
},
|
|
31
|
+
size: {
|
|
32
|
+
width: canvas.clientWidth,
|
|
33
|
+
height: canvas.clientHeight,
|
|
34
|
+
top: 0,
|
|
35
|
+
left: 0,
|
|
36
|
+
...renderProps == null ? void 0 : renderProps.size
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const store = _roots.get(canvas).store;
|
|
40
|
+
r3mRef.current.map = map;
|
|
41
|
+
r3mRef.current.root = root;
|
|
42
|
+
r3mRef.current.state = store.getState();
|
|
43
|
+
store.setState({ r3m: r3mRef.current });
|
|
44
|
+
if (frameloop === "demand") {
|
|
45
|
+
store.setState({
|
|
46
|
+
frameloop,
|
|
47
|
+
invalidate: () => {
|
|
48
|
+
map.triggerRepaint();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
map.on("resize", onResize);
|
|
53
|
+
setTimeout(() => setMounted(true));
|
|
54
|
+
});
|
|
55
|
+
const onResize = useFunction(() => {
|
|
56
|
+
if (!r3mRef.current.map)
|
|
57
|
+
return;
|
|
58
|
+
if (!r3mRef.current.state)
|
|
59
|
+
return;
|
|
60
|
+
const canvas = r3mRef.current.map.getCanvas();
|
|
61
|
+
r3mRef.current.state.setSize(canvas.width, canvas.height);
|
|
62
|
+
});
|
|
63
|
+
const onRemove = useFunction(() => {
|
|
64
|
+
if (!r3mRef.current.root)
|
|
65
|
+
return;
|
|
66
|
+
r3mRef.current.root.unmount();
|
|
67
|
+
r3mRef.current.root = void 0;
|
|
68
|
+
if (!r3mRef.current.map)
|
|
69
|
+
return;
|
|
70
|
+
r3mRef.current.map.off("resize", onResize);
|
|
71
|
+
});
|
|
72
|
+
useEffect(() => () => onRemove(), [onRemove]);
|
|
73
|
+
return { onAdd, onRemove, mounted, r3mRef };
|
|
74
|
+
}
|
|
9
75
|
export {
|
|
10
|
-
|
|
76
|
+
useOnAdd
|
|
11
77
|
};
|
|
12
78
|
//# sourceMappingURL=main12.mjs.map
|
package/dist/es/main12.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main12.mjs","sources":["../../src/core/use-
|
|
1
|
+
{"version":3,"file":"main12.mjs","sources":["../../src/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, _roots, createRoot } from \"@react-three/fiber\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { FromLngLat, MapInstance } from \"./generic-map\";\nimport { R3mStore } from \"./store\";\nimport { useFunction } from \"./use-function\";\n\nexport function useOnAdd(\n fromLngLat: FromLngLat,\n { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>\n) {\n\n const [mounted, setMounted] = useState(false);\n\n const r3mRef = useRef<R3mStore>({ fromLngLat });\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 // eslint-disable-next-line @typescript-eslint/no-empty-function\n state.gl.forceContextLoss = () => { };\n },\n camera: {\n matrixAutoUpdate: false,\n near: 0,\n },\n size: {\n width: canvas.clientWidth,\n height: canvas.clientHeight,\n top: 0,\n left: 0,\n ...renderProps?.size,\n },\n });\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const store = _roots.get(canvas)!.store;\n\n r3mRef.current.map = map;\n r3mRef.current.root = root;\n r3mRef.current.state = store.getState();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n store.setState({ r3m: r3mRef.current } as any);\n\n if (frameloop === 'demand') {\n store.setState({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n },\n })\n }\n\n map.on('resize', onResize)\n\n setTimeout(() => setMounted(true));\n\n })\n\n const onResize = useFunction(() => {\n if (!r3mRef.current.map) return;\n if (!r3mRef.current.state) return;\n const canvas = r3mRef.current.map.getCanvas();\n r3mRef.current.state.setSize(canvas.width, canvas.height);\n })\n\n const onRemove = useFunction(() => {\n if (!r3mRef.current.root) return;\n r3mRef.current.root.unmount();\n r3mRef.current.root = undefined;\n if (!r3mRef.current.map) return;\n r3mRef.current.map.off('resize', onResize)\n })\n\n // on unmount\n useEffect(() => () => onRemove(), [onRemove])\n\n return { onAdd, onRemove, mounted, r3mRef };\n}"],"names":[],"mappings":";;;;AAOO,SAAS,SACd,YACA,EAAE,WAAW,GAAG,eAChB;AAEA,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAE5C,QAAM,SAAS,OAAiB,EAAE,WAAY,CAAA;AAE9C,QAAM,QAAQ,YAAY,CAAC,KAAkB,OAA8B;AAEnE,UAAA,SAAS,IAAI;AACb,UAAA,OAAO,WAAW,MAAM;AAC9B,SAAK,UAAU;AAAA,MACb,KAAK,OAAO;AAAA,MACZ,QAAQ,aAAa;AAAA,MACrB,GAAG;AAAA,MACH,WAAW;AAAA,MACX,IAAI;AAAA,QACF,SAAS;AAAA,QACT,OAAO;AAAA,QACP,WAAW;AAAA,QACX,WAAW;AAAA,QACX,GAAG,2CAAa;AAAA,MAClB;AAAA,MACA,WAAW,CAAC,UAAU;AAEd,cAAA,GAAG,mBAAmB,MAAM;AAAA,QAAA;AAAA,MACpC;AAAA,MACA,QAAQ;AAAA,QACN,kBAAkB;AAAA,QAClB,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,QACJ,OAAO,OAAO;AAAA,QACd,QAAQ,OAAO;AAAA,QACf,KAAK;AAAA,QACL,MAAM;AAAA,QACN,GAAG,2CAAa;AAAA,MAClB;AAAA,IAAA,CACD;AAGD,UAAM,QAAQ,OAAO,IAAI,MAAM,EAAG;AAElC,WAAO,QAAQ,MAAM;AACrB,WAAO,QAAQ,OAAO;AACf,WAAA,QAAQ,QAAQ,MAAM,SAAS;AAGtC,UAAM,SAAS,EAAE,KAAK,OAAO,QAAgB,CAAA;AAE7C,QAAI,cAAc,UAAU;AAC1B,YAAM,SAAS;AAAA,QACb;AAAA,QACA,YAAY,MAAM;AAChB,cAAI,eAAe;AAAA,QACrB;AAAA,MAAA,CACD;AAAA,IACH;AAEI,QAAA,GAAG,UAAU,QAAQ;AAEd,eAAA,MAAM,WAAW,IAAI,CAAC;AAAA,EAAA,CAElC;AAEK,QAAA,WAAW,YAAY,MAAM;AAC7B,QAAA,CAAC,OAAO,QAAQ;AAAK;AACrB,QAAA,CAAC,OAAO,QAAQ;AAAO;AAC3B,UAAM,SAAS,OAAO,QAAQ,IAAI,UAAU;AAC5C,WAAO,QAAQ,MAAM,QAAQ,OAAO,OAAO,OAAO,MAAM;AAAA,EAAA,CACzD;AAEK,QAAA,WAAW,YAAY,MAAM;AAC7B,QAAA,CAAC,OAAO,QAAQ;AAAM;AACnB,WAAA,QAAQ,KAAK;AACpB,WAAO,QAAQ,OAAO;AAClB,QAAA,CAAC,OAAO,QAAQ;AAAK;AACzB,WAAO,QAAQ,IAAI,IAAI,UAAU,QAAQ;AAAA,EAAA,CAC1C;AAGD,YAAU,MAAM,MAAM,SAAY,GAAA,CAAC,QAAQ,CAAC;AAE5C,SAAO,EAAE,OAAO,UAAU,SAAS,OAAO;AAC5C;"}
|
package/dist/es/main13.mjs
CHANGED
|
@@ -1,71 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
onPointerDown: ["pointerdown", true],
|
|
9
|
-
onPointerUp: ["pointerup", true],
|
|
10
|
-
onPointerLeave: ["pointerleave", true],
|
|
11
|
-
onPointerMove: ["pointermove", true],
|
|
12
|
-
onPointerCancel: ["pointercancel", true],
|
|
13
|
-
onLostPointerCapture: ["lostpointercapture", true]
|
|
1
|
+
import { useRef, useCallback } from "react";
|
|
2
|
+
const useFunction = (callback) => {
|
|
3
|
+
const callbackRef = useRef(callback);
|
|
4
|
+
callbackRef.current = callback;
|
|
5
|
+
return useCallback((...args) => {
|
|
6
|
+
return callbackRef.current(...args);
|
|
7
|
+
}, []);
|
|
14
8
|
};
|
|
15
|
-
const projByViewInv = new Matrix4();
|
|
16
|
-
function createEvents() {
|
|
17
|
-
return (store) => {
|
|
18
|
-
const { handlePointer } = createEvents$1(store);
|
|
19
|
-
return {
|
|
20
|
-
priority: 1,
|
|
21
|
-
enabled: true,
|
|
22
|
-
compute(event, state) {
|
|
23
|
-
state.pointer.x = event.offsetX / state.size.width * 2 - 1;
|
|
24
|
-
state.pointer.y = 1 - event.offsetY / state.size.height * 2;
|
|
25
|
-
if (state.camera.userData.projByViewInv)
|
|
26
|
-
projByViewInv.fromArray(state.camera.userData.projByViewInv);
|
|
27
|
-
state.raycaster.camera = state.camera;
|
|
28
|
-
state.raycaster.ray.origin.setScalar(0).applyMatrix4(projByViewInv);
|
|
29
|
-
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(projByViewInv).sub(state.raycaster.ray.origin).normalize();
|
|
30
|
-
},
|
|
31
|
-
connected: void 0,
|
|
32
|
-
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
33
|
-
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
34
|
-
{}
|
|
35
|
-
),
|
|
36
|
-
update: () => {
|
|
37
|
-
var _a;
|
|
38
|
-
const { events, internal } = store.getState();
|
|
39
|
-
if (((_a = internal.lastEvent) == null ? void 0 : _a.current) && events.handlers) {
|
|
40
|
-
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
connect: (target) => {
|
|
44
|
-
var _a;
|
|
45
|
-
const { set, events } = store.getState();
|
|
46
|
-
(_a = events.disconnect) == null ? void 0 : _a.call(events);
|
|
47
|
-
set((state) => ({ events: { ...state.events, connected: target.parentNode } }));
|
|
48
|
-
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
49
|
-
const [eventName, passive] = DOM_EVENTS[name];
|
|
50
|
-
target.addEventListener(eventName, event, { passive });
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
disconnect: () => {
|
|
54
|
-
const { set, events } = store.getState();
|
|
55
|
-
if (events.connected) {
|
|
56
|
-
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
57
|
-
if (events && events.connected instanceof HTMLElement) {
|
|
58
|
-
const [eventName] = DOM_EVENTS[name];
|
|
59
|
-
events.connected.removeEventListener(eventName, event);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
9
|
export {
|
|
69
|
-
|
|
10
|
+
useFunction
|
|
70
11
|
};
|
|
71
12
|
//# sourceMappingURL=main13.mjs.map
|