react-three-map 0.8.0 → 0.8.1
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 +7 -0
- package/README.md +18 -3
- package/dist/cjs/main.js +35 -18
- package/dist/es/main.mjs +5 -3
- package/dist/es/main.mjs.map +1 -1
- package/dist/es/main10.mjs +8 -33
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +33 -11
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main12.mjs +11 -22
- package/dist/es/main12.mjs.map +1 -1
- package/dist/es/main13.mjs +17 -24
- package/dist/es/main13.mjs.map +1 -1
- package/dist/es/main14.mjs +2 -23
- package/dist/es/main14.mjs.map +1 -1
- package/dist/es/main15.mjs +28 -93
- package/dist/es/main15.mjs.map +1 -1
- package/dist/es/main16.mjs +21 -61
- package/dist/es/main16.mjs.map +1 -1
- package/dist/es/main17.mjs +94 -19
- package/dist/es/main17.mjs.map +1 -1
- package/dist/es/main18.mjs +62 -23
- package/dist/es/main18.mjs.map +1 -1
- package/dist/es/main19.mjs +17 -13
- package/dist/es/main19.mjs.map +1 -1
- package/dist/es/main20.mjs +23 -68
- package/dist/es/main20.mjs.map +1 -1
- package/dist/es/main21.mjs +19 -0
- package/dist/es/main21.mjs.map +1 -0
- package/dist/es/main22.mjs +83 -0
- package/dist/es/main22.mjs.map +1 -0
- package/dist/es/main3.mjs +3 -3
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main4.mjs +3 -3
- package/dist/es/main5.mjs +12 -19
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +19 -15
- package/dist/es/main6.mjs.map +1 -1
- package/dist/es/main7.mjs +10 -22
- package/dist/es/main7.mjs.map +1 -1
- package/dist/es/main8.mjs +22 -26
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +26 -8
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +35 -18
- package/dist/maplibre/es/main.mjs +5 -3
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main10.mjs +8 -33
- package/dist/maplibre/es/main10.mjs.map +1 -1
- package/dist/maplibre/es/main11.mjs +33 -11
- package/dist/maplibre/es/main11.mjs.map +1 -1
- package/dist/maplibre/es/main12.mjs +11 -22
- package/dist/maplibre/es/main12.mjs.map +1 -1
- package/dist/maplibre/es/main13.mjs +17 -24
- package/dist/maplibre/es/main13.mjs.map +1 -1
- package/dist/maplibre/es/main14.mjs +2 -23
- package/dist/maplibre/es/main14.mjs.map +1 -1
- package/dist/maplibre/es/main15.mjs +28 -93
- package/dist/maplibre/es/main15.mjs.map +1 -1
- package/dist/maplibre/es/main16.mjs +21 -61
- package/dist/maplibre/es/main16.mjs.map +1 -1
- package/dist/maplibre/es/main17.mjs +94 -19
- package/dist/maplibre/es/main17.mjs.map +1 -1
- package/dist/maplibre/es/main18.mjs +62 -23
- package/dist/maplibre/es/main18.mjs.map +1 -1
- package/dist/maplibre/es/main19.mjs +17 -13
- package/dist/maplibre/es/main19.mjs.map +1 -1
- package/dist/maplibre/es/main20.mjs +23 -68
- package/dist/maplibre/es/main20.mjs.map +1 -1
- package/dist/maplibre/es/main21.mjs +19 -0
- package/dist/maplibre/es/main21.mjs.map +1 -0
- package/dist/maplibre/es/main22.mjs +83 -0
- package/dist/maplibre/es/main22.mjs.map +1 -0
- package/dist/maplibre/es/main3.mjs +3 -3
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +3 -3
- package/dist/maplibre/es/main5.mjs +12 -19
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/es/main6.mjs +19 -15
- package/dist/maplibre/es/main6.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +10 -22
- package/dist/maplibre/es/main7.mjs.map +1 -1
- package/dist/maplibre/es/main8.mjs +22 -26
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/es/main9.mjs +26 -8
- package/dist/maplibre/es/main9.mjs.map +1 -1
- package/dist/maplibre/types/api/coords-to-vector-3.d.ts +2 -3
- package/dist/maplibre/types/api/index.d.ts +2 -1
- package/dist/maplibre/types/api/vector-3-to-coords.d.ts +3 -0
- package/dist/maplibre/types/core/canvas-overlay/sync-camera-fc.d.ts +2 -1
- package/dist/maplibre/types/core/earth-radius.d.ts +1 -0
- package/dist/types/api/coords-to-vector-3.d.ts +2 -3
- package/dist/types/api/index.d.ts +2 -1
- package/dist/types/api/vector-3-to-coords.d.ts +3 -0
- package/dist/types/core/canvas-overlay/sync-camera-fc.d.ts +2 -1
- package/dist/types/core/earth-radius.d.ts +1 -0
- package/package.json +6 -9
- package/stories/package.json +4 -4
- package/stories/yarn.lock +1931 -1085
- package/vitest.config.ts +1 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -211,9 +211,24 @@ This utility function converts geographic coordinates into a `Vector3Tuple`, whi
|
|
|
211
211
|
Similar to `NearCoordinates` it has a relatively good precision at city distances, but is not recommended if your distances are too big.
|
|
212
212
|
|
|
213
213
|
|
|
214
|
-
| Parameter
|
|
215
|
-
|
|
|
214
|
+
| Parameter | Description |
|
|
215
|
+
| ---------------- | --------------------------------------------------------------- |
|
|
216
216
|
| `point: Coords` | The geographic coordinates of the point to convert. |
|
|
217
217
|
| `origin: Coords` | The geographic coordinates used as the origin for calculations. |
|
|
218
218
|
|
|
219
|
-
Returns a `Vector3Tuple` representing the 3D position of the point relative to the origin.
|
|
219
|
+
Returns a `Vector3Tuple` representing the 3D position of the point relative to the origin.
|
|
220
|
+
|
|
221
|
+
### vector3ToCoords
|
|
222
|
+
|
|
223
|
+
[](https://rodrigohamuy.github.io/react-three-map/?story=pivot-controls--default)
|
|
224
|
+
|
|
225
|
+
This utility function converts a `Vector3Tuple`, which represents a 3D vector in meters, back into geographic coordinates.
|
|
226
|
+
|
|
227
|
+
It is the inverse of `coordsToVector3` and maintains the same level of precision. It is not recommended for use with very large distances.
|
|
228
|
+
|
|
229
|
+
| Parameter | Description |
|
|
230
|
+
| ------------------------ | --------------------------------------------------------------- |
|
|
231
|
+
| `position: Vector3Tuple` | The 3D vector to convert back into geographic coordinates. |
|
|
232
|
+
| `origin: Coords` | The geographic coordinates used as the origin for calculations. |
|
|
233
|
+
|
|
234
|
+
Returns a `Coords` object representing the geographic coordinates of the point relative to the origin.
|
package/dist/cjs/main.js
CHANGED
|
@@ -7,7 +7,6 @@ const react = require("react");
|
|
|
7
7
|
const reactMapGl = require("react-map-gl");
|
|
8
8
|
const THREE = require("three");
|
|
9
9
|
const reactDom = require("react-dom");
|
|
10
|
-
const turf = require("@turf/turf");
|
|
11
10
|
function _interopNamespaceDefault(e) {
|
|
12
11
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
12
|
if (e) {
|
|
@@ -148,6 +147,16 @@ function RenderAtCoords({ r3m, origin }) {
|
|
|
148
147
|
}, [set, r3m]);
|
|
149
148
|
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
150
149
|
}
|
|
150
|
+
const earthRadius = 6378137;
|
|
151
|
+
function coordsToVector3(point, origin) {
|
|
152
|
+
const latitudeDiff = (point.latitude - origin.latitude) * THREE.MathUtils.DEG2RAD;
|
|
153
|
+
const longitudeDiff = (point.longitude - origin.longitude) * THREE.MathUtils.DEG2RAD;
|
|
154
|
+
const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);
|
|
155
|
+
const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * THREE.MathUtils.DEG2RAD);
|
|
156
|
+
const y = altitudeDiff;
|
|
157
|
+
const z = -latitudeDiff * earthRadius;
|
|
158
|
+
return [x, y, z];
|
|
159
|
+
}
|
|
151
160
|
function useCoords() {
|
|
152
161
|
const coords = fiber.useThree((s) => s.coords);
|
|
153
162
|
return coords;
|
|
@@ -172,18 +181,6 @@ function useSetRootCoords(store, {
|
|
|
172
181
|
function setCoords(store, coords) {
|
|
173
182
|
store.setState({ coords });
|
|
174
183
|
}
|
|
175
|
-
function coordsToVector3(point, origin) {
|
|
176
|
-
const originCoords = [origin.longitude, origin.latitude, origin.altitude || 0];
|
|
177
|
-
const pointCoords = [point.longitude, point.latitude, point.altitude || 0];
|
|
178
|
-
const dist = turf.distance(originCoords, pointCoords, { units: "meters" });
|
|
179
|
-
const angle = turf.bearing(originCoords, pointCoords);
|
|
180
|
-
const adjustedAngle = angle - 90;
|
|
181
|
-
const x = dist * Math.cos(adjustedAngle * THREE.MathUtils.DEG2RAD);
|
|
182
|
-
const y = (point.altitude || 0) - (origin.altitude || 0);
|
|
183
|
-
const z = dist * Math.sin(adjustedAngle * THREE.MathUtils.DEG2RAD);
|
|
184
|
-
const v3 = [x, y, z];
|
|
185
|
-
return v3;
|
|
186
|
-
}
|
|
187
184
|
const NearCoordinates = react.memo(({ children, ...coords }) => {
|
|
188
185
|
const { latitude, longitude, altitude } = useCoords();
|
|
189
186
|
const pos2 = react.useMemo(() => coordsToVector3(coords, { latitude, longitude, altitude }), [
|
|
@@ -198,6 +195,14 @@ const NearCoordinates = react.memo(({ children, ...coords }) => {
|
|
|
198
195
|
return /* @__PURE__ */ jsxRuntime.jsx("object3D", { position: pos2, children });
|
|
199
196
|
});
|
|
200
197
|
NearCoordinates.displayName = "NearCoordinates";
|
|
198
|
+
function vector3ToCoords(position, origin) {
|
|
199
|
+
const [x, y, z] = position;
|
|
200
|
+
const latitude = origin.latitude + -z / earthRadius * THREE.MathUtils.RAD2DEG;
|
|
201
|
+
const longitude = origin.longitude + x / earthRadius * THREE.MathUtils.RAD2DEG / Math.cos(origin.latitude * THREE.MathUtils.DEG2RAD);
|
|
202
|
+
const altitude = (origin.altitude || 0) + y;
|
|
203
|
+
const coords = { latitude, longitude, altitude };
|
|
204
|
+
return coords;
|
|
205
|
+
}
|
|
201
206
|
const useFunction = (callback) => {
|
|
202
207
|
const callbackRef = react.useRef(callback);
|
|
203
208
|
callbackRef.current = callback;
|
|
@@ -370,8 +375,9 @@ const SyncCameraFC = react.memo(({
|
|
|
370
375
|
setOnRender,
|
|
371
376
|
manualRender,
|
|
372
377
|
onReady,
|
|
373
|
-
|
|
378
|
+
map
|
|
374
379
|
}) => {
|
|
380
|
+
const mapCanvas = map.getCanvas();
|
|
375
381
|
const r3m = useR3M();
|
|
376
382
|
const camRef = react.useRef(null);
|
|
377
383
|
const camera = fiber.useThree((s) => s.camera);
|
|
@@ -383,13 +389,23 @@ const SyncCameraFC = react.memo(({
|
|
|
383
389
|
const set = fiber.useThree((s) => s.set);
|
|
384
390
|
const origin = useCoordsToMatrix({ latitude, longitude, altitude, fromLngLat: r3m.fromLngLat });
|
|
385
391
|
const ready = react.useRef(false);
|
|
392
|
+
const triggerRepaint = react.useMemo(() => map.triggerRepaint, [map]);
|
|
393
|
+
const mapPaintRequests = react.useRef(0);
|
|
394
|
+
const triggerRepaintOff = useFunction(() => {
|
|
395
|
+
mapPaintRequests.current++;
|
|
396
|
+
});
|
|
386
397
|
fiber.useFrame(() => {
|
|
387
398
|
syncCamera(camera, origin, r3m.viewProjMx);
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
|
|
399
|
+
if (manualRender)
|
|
400
|
+
gl.render(scene, camera);
|
|
401
|
+
map.triggerRepaint = triggerRepaint;
|
|
402
|
+
if (mapPaintRequests.current > 0) {
|
|
403
|
+
mapPaintRequests.current = 0;
|
|
404
|
+
map.triggerRepaint();
|
|
405
|
+
}
|
|
391
406
|
}, -Infinity);
|
|
392
407
|
const onRender = useFunction((viewProjMx) => {
|
|
408
|
+
map.triggerRepaint = triggerRepaintOff;
|
|
393
409
|
if (threeCanvas.width !== mapCanvas.width || threeCanvas.height !== mapCanvas.height) {
|
|
394
410
|
setSize(
|
|
395
411
|
mapCanvas.clientWidth,
|
|
@@ -470,7 +486,7 @@ const CanvasPortal = react.memo(({
|
|
|
470
486
|
altitude,
|
|
471
487
|
setOnRender,
|
|
472
488
|
onReady,
|
|
473
|
-
|
|
489
|
+
map
|
|
474
490
|
}
|
|
475
491
|
),
|
|
476
492
|
ready && children
|
|
@@ -543,3 +559,4 @@ exports.Coordinates = Coordinates;
|
|
|
543
559
|
exports.NearCoordinates = NearCoordinates;
|
|
544
560
|
exports.coordsToVector3 = coordsToVector3;
|
|
545
561
|
exports.useMap = useMap;
|
|
562
|
+
exports.vector3ToCoords = vector3ToCoords;
|
package/dist/es/main.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useMap as useMap$1 } from "./main2.mjs";
|
|
2
2
|
import { Canvas } from "./main3.mjs";
|
|
3
3
|
import { Coordinates } from "./main4.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { coordsToVector3 } from "./main5.mjs";
|
|
5
|
+
import { NearCoordinates } from "./main6.mjs";
|
|
6
|
+
import { vector3ToCoords } from "./main7.mjs";
|
|
6
7
|
const useMap = useMap$1;
|
|
7
8
|
export {
|
|
8
9
|
Canvas,
|
|
9
10
|
Coordinates,
|
|
10
11
|
NearCoordinates,
|
|
11
12
|
coordsToVector3,
|
|
12
|
-
useMap
|
|
13
|
+
useMap,
|
|
14
|
+
vector3ToCoords
|
|
13
15
|
};
|
|
14
16
|
//# sourceMappingURL=main.mjs.map
|
package/dist/es/main.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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';\nexport * from './mapbox/canvas';\n\nexport const useMap = useMapGeneric<Map>;\n"],"names":["useMapGeneric"],"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';\nexport * from './mapbox/canvas';\n\nexport const useMap = useMapGeneric<Map>;\n"],"names":["useMapGeneric"],"mappings":";;;;;;AAMO,MAAM,SAASA;"}
|
package/dist/es/main10.mjs
CHANGED
|
@@ -1,37 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
projByViewInv.copy(projByView).invert();
|
|
9
|
-
updateCamera(camera, projByViewInv);
|
|
10
|
-
camera.updateMatrix();
|
|
11
|
-
camera.updateMatrixWorld(true);
|
|
12
|
-
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
13
|
-
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
14
|
-
camera.far = calculateFar(
|
|
15
|
-
camera.matrix.elements[10],
|
|
16
|
-
camera.matrix.elements[14],
|
|
17
|
-
camera.near
|
|
18
|
-
);
|
|
19
|
-
camera.userData.projByView = projByView.toArray();
|
|
20
|
-
camera.userData.projByViewInv = projByViewInv.toArray();
|
|
21
|
-
}
|
|
22
|
-
const updateCamera = (target, projByViewInv2) => {
|
|
23
|
-
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
24
|
-
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
25
|
-
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
26
|
-
target.lookAt(fwd);
|
|
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
|
+
}, []);
|
|
27
8
|
};
|
|
28
|
-
function calculateFar(c, d, near) {
|
|
29
|
-
const numerator = d * (c - 1);
|
|
30
|
-
const denominator = c * near + near;
|
|
31
|
-
const far = numerator / denominator;
|
|
32
|
-
return far;
|
|
33
|
-
}
|
|
34
9
|
export {
|
|
35
|
-
|
|
10
|
+
useFunction
|
|
36
11
|
};
|
|
37
12
|
//# sourceMappingURL=main10.mjs.map
|
package/dist/es/main10.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main10.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main10.mjs","sources":["../../src/core/use-function.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const useFunction = <T extends (...args: any[]) => any>(callback: T): T => {\n const callbackRef = useRef(callback);\n callbackRef.current = callback;\n return useCallback((...args: any[]) => {\n return callbackRef.current(...args);\n }, []) as T;\n};\n"],"names":[],"mappings":";AAGa,MAAA,cAAc,CAAoC,aAAmB;AAC1E,QAAA,cAAc,OAAO,QAAQ;AACnC,cAAY,UAAU;AACf,SAAA,YAAY,IAAI,SAAgB;AAC9B,WAAA,YAAY,QAAQ,GAAG,IAAI;AAAA,EACpC,GAAG,CAAE,CAAA;AACP;"}
|
package/dist/es/main11.mjs
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Matrix4, Vector3 } from "three";
|
|
2
|
+
const originMx = new Matrix4();
|
|
3
|
+
const projByView = new Matrix4();
|
|
4
|
+
const projByViewInv = new Matrix4();
|
|
5
|
+
const fwd = new Vector3();
|
|
6
|
+
function syncCamera(camera, origin, mapCamMx) {
|
|
7
|
+
projByView.fromArray(mapCamMx).multiply(originMx.fromArray(origin));
|
|
8
|
+
projByViewInv.copy(projByView).invert();
|
|
9
|
+
updateCamera(camera, projByViewInv);
|
|
10
|
+
camera.updateMatrix();
|
|
11
|
+
camera.updateMatrixWorld(true);
|
|
12
|
+
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
13
|
+
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
14
|
+
camera.far = calculateFar(
|
|
15
|
+
camera.matrix.elements[10],
|
|
16
|
+
camera.matrix.elements[14],
|
|
17
|
+
camera.near
|
|
18
|
+
);
|
|
19
|
+
camera.userData.projByView = projByView.toArray();
|
|
20
|
+
camera.userData.projByViewInv = projByViewInv.toArray();
|
|
21
|
+
}
|
|
22
|
+
const updateCamera = (target, projByViewInv2) => {
|
|
23
|
+
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
24
|
+
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
25
|
+
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
26
|
+
target.lookAt(fwd);
|
|
27
|
+
};
|
|
28
|
+
function calculateFar(c, d, near) {
|
|
29
|
+
const numerator = d * (c - 1);
|
|
30
|
+
const denominator = c * near + near;
|
|
31
|
+
const far = numerator / denominator;
|
|
32
|
+
return far;
|
|
11
33
|
}
|
|
12
34
|
export {
|
|
13
|
-
|
|
35
|
+
syncCamera
|
|
14
36
|
};
|
|
15
37
|
//# sourceMappingURL=main11.mjs.map
|
package/dist/es/main11.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main11.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main11.mjs","sources":["../../src/core/sync-camera.ts"],"sourcesContent":["import { Matrix4, Matrix4Tuple, Object3D, PerspectiveCamera, Vector3 } from \"three\";\n\nconst originMx = new Matrix4();\n\n/** projection * view matrix */\nconst projByView = new Matrix4();\n/** projection * view matrix inverted */\nconst projByViewInv = new Matrix4();\n\n/** forward */\nconst fwd = new Vector3();\n\n\nexport function syncCamera(camera: PerspectiveCamera, origin: Matrix4Tuple, mapCamMx: Matrix4Tuple) {\n\n projByView\n .fromArray(mapCamMx)\n .multiply(originMx.fromArray(origin));\n projByViewInv\n .copy(projByView)\n .invert();\n\n updateCamera(camera, projByViewInv);\n camera.updateMatrix();\n camera.updateMatrixWorld(true); \n\n camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n\n camera.far = calculateFar(\n camera.matrix.elements[10], camera.matrix.elements[14], camera.near\n )\n\n camera.userData.projByView = projByView.toArray();\n camera.userData.projByViewInv = projByViewInv.toArray();\n\n}\n\nconst updateCamera = (target: Object3D, projByViewInv: Matrix4) => {\n\n target.position\n .setScalar(0)\n .applyMatrix4(projByViewInv)\n\n target.up\n .set(0, -1, 0)\n .applyMatrix4(projByViewInv)\n .negate()\n .add(target.position)\n .normalize()\n\n fwd\n .set(0, 0, 1)\n .applyMatrix4(projByViewInv)\n\n target.lookAt(fwd);\n\n}\n\nfunction calculateFar(c: number, d: number, near: number): number {\n const numerator = d * (c - 1);\n const denominator = c * near + near;\n const far = numerator / denominator;\n return far;\n}"],"names":["projByViewInv"],"mappings":";AAEA,MAAM,WAAW,IAAI;AAGrB,MAAM,aAAa,IAAI;AAEvB,MAAM,gBAAgB,IAAI;AAG1B,MAAM,MAAM,IAAI;AAGA,SAAA,WAAW,QAA2B,QAAsB,UAAwB;AAElG,aACG,UAAU,QAAQ,EAClB,SAAS,SAAS,UAAU,MAAM,CAAC;AAEnC,gBAAA,KAAK,UAAU,EACf,OAAO;AAEV,eAAa,QAAQ,aAAa;AAClC,SAAO,aAAa;AACpB,SAAO,kBAAkB,IAAI;AAE7B,SAAO,iBAAiB,KAAK,OAAO,MAAM,EAAE,YAAY,UAAU;AAClE,SAAO,wBAAwB,KAAK,OAAO,gBAAgB,EAAE;AAE7D,SAAO,MAAM;AAAA,IACX,OAAO,OAAO,SAAS,EAAE;AAAA,IAAG,OAAO,OAAO,SAAS,EAAE;AAAA,IAAG,OAAO;AAAA,EAAA;AAG1D,SAAA,SAAS,aAAa,WAAW,QAAQ;AACzC,SAAA,SAAS,gBAAgB,cAAc,QAAQ;AAExD;AAEA,MAAM,eAAe,CAAC,QAAkBA,mBAA2B;AAEjE,SAAO,SACJ,UAAU,CAAC,EACX,aAAaA,cAAa;AAE7B,SAAO,GACJ,IAAI,GAAG,IAAI,CAAC,EACZ,aAAaA,cAAa,EAC1B,SACA,IAAI,OAAO,QAAQ,EACnB;AAEH,MACG,IAAI,GAAG,GAAG,CAAC,EACX,aAAaA,cAAa;AAE7B,SAAO,OAAO,GAAG;AAEnB;AAEA,SAAS,aAAa,GAAW,GAAW,MAAsB;AAC1D,QAAA,YAAY,KAAK,IAAI;AACrB,QAAA,cAAc,IAAI,OAAO;AAC/B,QAAM,MAAM,YAAY;AACjB,SAAA;AACT;"}
|
package/dist/es/main12.mjs
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const store = _roots.get(canvas).store;
|
|
12
|
-
initR3M({ ...props, store });
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
function initR3M({ store, ...props }) {
|
|
16
|
-
const viewProjMx = new Matrix4().identity().toArray();
|
|
17
|
-
const r3m = { ...props, viewProjMx };
|
|
18
|
-
store.setState({ r3m });
|
|
19
|
-
return r3m;
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { coordsToMatrix } from "./main19.mjs";
|
|
3
|
+
function useCoordsToMatrix({ latitude, longitude, altitude, fromLngLat }) {
|
|
4
|
+
const m4 = useMemo(() => coordsToMatrix({
|
|
5
|
+
latitude,
|
|
6
|
+
longitude,
|
|
7
|
+
altitude,
|
|
8
|
+
fromLngLat
|
|
9
|
+
}), [latitude, longitude, altitude, fromLngLat]);
|
|
10
|
+
return m4;
|
|
20
11
|
}
|
|
21
12
|
export {
|
|
22
|
-
|
|
23
|
-
useInitR3M,
|
|
24
|
-
useR3M
|
|
13
|
+
useCoordsToMatrix
|
|
25
14
|
};
|
|
26
15
|
//# 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-coords-to-matrix.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { coordsToMatrix } from \"./coords-to-matrix\";\n\ntype Props = Parameters<typeof coordsToMatrix>[0];\n\n/** calculate matrix from coordinates */\nexport function useCoordsToMatrix({latitude, longitude, altitude, fromLngLat}: Props) {\n const m4 = useMemo(() => coordsToMatrix({\n latitude, longitude, altitude, fromLngLat,\n }), [latitude, longitude, altitude, fromLngLat]);\n\n return m4;\n}"],"names":[],"mappings":";;AAMO,SAAS,kBAAkB,EAAC,UAAU,WAAW,UAAU,cAAoB;AAC9E,QAAA,KAAK,QAAQ,MAAM,eAAe;AAAA,IACtC;AAAA,IAAU;AAAA,IAAW;AAAA,IAAU;AAAA,EAAA,CAChC,GAAG,CAAC,UAAU,WAAW,UAAU,UAAU,CAAC;AAExC,SAAA;AACT;"}
|
package/dist/es/main13.mjs
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
import { useThree, _roots } from "@react-three/fiber";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Matrix4 } from "three";
|
|
4
|
+
function useR3M() {
|
|
5
|
+
const r3m = useThree((s) => s.r3m);
|
|
6
|
+
return r3m;
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
+
function useInitR3M(props) {
|
|
8
9
|
const canvas = useThree((s) => s.gl.domElement);
|
|
9
|
-
|
|
10
|
+
useState(() => {
|
|
10
11
|
const store = _roots.get(canvas).store;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}, [longitude, latitude, altitude]);
|
|
12
|
+
initR3M({ ...props, store });
|
|
13
|
+
});
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
useMemo(() => {
|
|
21
|
-
setCoords(store, { longitude, latitude, altitude });
|
|
22
|
-
}, [longitude, latitude, altitude]);
|
|
23
|
-
}
|
|
24
|
-
function setCoords(store, coords) {
|
|
25
|
-
store.setState({ coords });
|
|
15
|
+
function initR3M({ store, ...props }) {
|
|
16
|
+
const viewProjMx = new Matrix4().identity().toArray();
|
|
17
|
+
const r3m = { ...props, viewProjMx };
|
|
18
|
+
store.setState({ r3m });
|
|
19
|
+
return r3m;
|
|
26
20
|
}
|
|
27
21
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
useSetRootCoords
|
|
22
|
+
initR3M,
|
|
23
|
+
useInitR3M,
|
|
24
|
+
useR3M
|
|
32
25
|
};
|
|
33
26
|
//# sourceMappingURL=main13.mjs.map
|
package/dist/es/main13.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main13.mjs","sources":["../../src/core/use-
|
|
1
|
+
{"version":3,"file":"main13.mjs","sources":["../../src/core/use-r3m.ts"],"sourcesContent":["import { RootState, _roots, useThree } from \"@react-three/fiber\";\nimport { useState } from \"react\";\nimport { Matrix4, Matrix4Tuple } from \"three\";\nimport { UseBoundStore } from 'zustand';\nimport { FromLngLat, MapInstance } from \"./generic-map\";\n\nexport interface R3M<T extends MapInstance = MapInstance> {\n /** Map provider */\n map: T,\n /** view projection matrix coming from the map provider */\n viewProjMx: Matrix4Tuple,\n fromLngLat: FromLngLat,\n}\n\nexport function useR3M<T extends MapInstance> () {\n const r3m = useThree(s=>(s as any).r3m) as R3M<T>; // eslint-disable-line @typescript-eslint/no-explicit-any\n return r3m;\n}\n\n/** init `useR3M` hook */\nexport function useInitR3M<T extends MapInstance>(props: {\n map: T; fromLngLat: FromLngLat;\n}) {\n const canvas = useThree(s => s.gl.domElement);\n // to run only once\n useState(()=>{\n const store = _roots.get(canvas)!.store; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n initR3M({...props, store})\n })\n}\n\nexport function initR3M<T extends MapInstance>({store, ...props}: {\n map: T;\n fromLngLat: FromLngLat;\n store: UseBoundStore<RootState>;\n}) {\n const viewProjMx = new Matrix4().identity().toArray();\n const r3m : R3M<T> = { ...props, viewProjMx };\n store.setState({r3m} as any); // eslint-disable-line @typescript-eslint/no-explicit-any\n return r3m;\n}"],"names":[],"mappings":";;;AAcO,SAAS,SAAiC;AAC/C,QAAM,MAAM,SAAS,CAAI,MAAA,EAAU,GAAG;AAC/B,SAAA;AACT;AAGO,SAAS,WAAkC,OAE/C;AACD,QAAM,SAAS,SAAS,CAAK,MAAA,EAAE,GAAG,UAAU;AAE5C,WAAS,MAAI;AACX,UAAM,QAAQ,OAAO,IAAI,MAAM,EAAG;AAClC,YAAQ,EAAC,GAAG,OAAO,MAAM,CAAA;AAAA,EAAA,CAC1B;AACH;AAEO,SAAS,QAA+B,EAAC,OAAO,GAAG,SAIvD;AACD,QAAM,aAAa,IAAI,QAAA,EAAU,WAAW,QAAQ;AACpD,QAAM,MAAe,EAAE,GAAG,OAAO,WAAW;AACtC,QAAA,SAAS,EAAC,IAAA,CAAW;AACpB,SAAA;AACT;"}
|
package/dist/es/main14.mjs
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { useFunction } from "./main9.mjs";
|
|
3
|
-
function useRender({
|
|
4
|
-
map,
|
|
5
|
-
origin,
|
|
6
|
-
useThree,
|
|
7
|
-
frameloop,
|
|
8
|
-
r3m
|
|
9
|
-
}) {
|
|
10
|
-
const render = useFunction((_gl, projViewMx) => {
|
|
11
|
-
r3m.viewProjMx.splice(0, 16, ...projViewMx);
|
|
12
|
-
const state = useThree.getState();
|
|
13
|
-
const camera = state.camera;
|
|
14
|
-
const { gl, advance } = state;
|
|
15
|
-
syncCamera(camera, origin, projViewMx);
|
|
16
|
-
gl.resetState();
|
|
17
|
-
advance(Date.now() * 1e-3, true);
|
|
18
|
-
if (!frameloop || frameloop === "always")
|
|
19
|
-
map.triggerRepaint();
|
|
20
|
-
});
|
|
21
|
-
return render;
|
|
22
|
-
}
|
|
1
|
+
const earthRadius = 6378137;
|
|
23
2
|
export {
|
|
24
|
-
|
|
3
|
+
earthRadius
|
|
25
4
|
};
|
|
26
5
|
//# sourceMappingURL=main14.mjs.map
|
package/dist/es/main14.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main14.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main14.mjs","sources":["../../src/core/earth-radius.ts"],"sourcesContent":["export const earthRadius = 6378137;\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}
|
package/dist/es/main15.mjs
CHANGED
|
@@ -1,98 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
antialias: true,
|
|
22
|
-
...props == null ? void 0 : props.gl
|
|
23
|
-
},
|
|
24
|
-
onCreated: (state) => {
|
|
25
|
-
state.gl.forceContextLoss = () => {
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
camera: {
|
|
29
|
-
matrixAutoUpdate: false,
|
|
30
|
-
near: 0
|
|
31
|
-
},
|
|
32
|
-
size: {
|
|
33
|
-
width: canvas2.clientWidth,
|
|
34
|
-
height: canvas2.clientHeight,
|
|
35
|
-
top: canvas2.offsetTop,
|
|
36
|
-
left: canvas2.offsetLeft,
|
|
37
|
-
updateStyle: false,
|
|
38
|
-
...props == null ? void 0 : props.size
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const store = _roots.get(canvas2).store;
|
|
42
|
-
const r3m2 = initR3M({ map, fromLngLat, store });
|
|
1
|
+
import { useThree, _roots } from "@react-three/fiber";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
function useCoords() {
|
|
4
|
+
const coords = useThree((s) => s.coords);
|
|
5
|
+
return coords;
|
|
6
|
+
}
|
|
7
|
+
function useSetCoords({ longitude, latitude, altitude }) {
|
|
8
|
+
const canvas = useThree((s) => s.gl.domElement);
|
|
9
|
+
useMemo(() => {
|
|
10
|
+
const store = _roots.get(canvas).store;
|
|
11
|
+
const coords = { longitude, latitude, altitude };
|
|
12
|
+
setCoords(store, coords);
|
|
13
|
+
}, [longitude, latitude, altitude]);
|
|
14
|
+
}
|
|
15
|
+
function useSetRootCoords(store, {
|
|
16
|
+
longitude,
|
|
17
|
+
latitude,
|
|
18
|
+
altitude
|
|
19
|
+
}) {
|
|
20
|
+
useMemo(() => {
|
|
43
21
|
setCoords(store, { longitude, latitude, altitude });
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
map.triggerRepaint();
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return { root: root2, useThree: store, map, canvas: canvas2, r3m: r3m2 };
|
|
53
|
-
});
|
|
54
|
-
const onResize = useFunction(() => {
|
|
55
|
-
const { setDpr, setSize } = useThree.getState();
|
|
56
|
-
setDpr(window.devicePixelRatio);
|
|
57
|
-
setSize(
|
|
58
|
-
canvas.clientWidth,
|
|
59
|
-
canvas.clientHeight,
|
|
60
|
-
false,
|
|
61
|
-
canvas.offsetTop,
|
|
62
|
-
canvas.offsetLeft
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
const onRemove = useFunction(() => {
|
|
66
|
-
root.unmount();
|
|
67
|
-
});
|
|
68
|
-
useSetRootCoords(useThree, { longitude, latitude, altitude });
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (frameloop !== "demand")
|
|
71
|
-
return;
|
|
72
|
-
const setState = useThree.setState;
|
|
73
|
-
const { invalidate } = useThree.getState();
|
|
74
|
-
setState({
|
|
75
|
-
frameloop,
|
|
76
|
-
invalidate: () => {
|
|
77
|
-
map.triggerRepaint();
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return () => {
|
|
81
|
-
setState({ frameloop: "never", invalidate });
|
|
82
|
-
};
|
|
83
|
-
}, [frameloop]);
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
map.on("resize", onResize);
|
|
86
|
-
return () => {
|
|
87
|
-
map.off("resize", onResize);
|
|
88
|
-
};
|
|
89
|
-
}, []);
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
root.render(/* @__PURE__ */ jsx(Fragment, { children: props.children }));
|
|
92
|
-
}, [props.children]);
|
|
93
|
-
return { onRemove, useThree, r3m };
|
|
22
|
+
}, [longitude, latitude, altitude]);
|
|
23
|
+
}
|
|
24
|
+
function setCoords(store, coords) {
|
|
25
|
+
store.setState({ coords });
|
|
94
26
|
}
|
|
95
27
|
export {
|
|
96
|
-
|
|
28
|
+
setCoords,
|
|
29
|
+
useCoords,
|
|
30
|
+
useSetCoords,
|
|
31
|
+
useSetRootCoords
|
|
97
32
|
};
|
|
98
33
|
//# sourceMappingURL=main15.mjs.map
|
package/dist/es/main15.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main15.mjs","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"main15.mjs","sources":["../../src/core/use-coords.tsx"],"sourcesContent":["import { RootState, _roots, useThree } from \"@react-three/fiber\";\nimport { useMemo } from \"react\";\nimport { UseBoundStore } from 'zustand';\nimport { Coords } from \"../api/coords\";\n\nexport function useCoords() {\n const coords = useThree(s=>(s as any).coords) as Coords; // eslint-disable-line @typescript-eslint/no-explicit-any\n return coords;\n}\n\nexport function useSetCoords({longitude, latitude, altitude}: Coords) {\n \n const canvas = useThree(s => s.gl.domElement);\n useMemo(()=>{\n const store = _roots.get(canvas)!.store; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n const coords : Coords = { longitude, latitude, altitude };\n setCoords(store, coords);\n }, [longitude, latitude, altitude]) // eslint-disable-line react-hooks/exhaustive-deps\n}\n\nexport function useSetRootCoords(store:UseBoundStore<RootState>, {\n longitude, latitude, altitude\n}: Coords) {\n useMemo(()=>{\n setCoords(store, {longitude, latitude, altitude});\n }, [longitude, latitude, altitude]) // eslint-disable-line react-hooks/exhaustive-deps\n}\n\nexport function setCoords(store:UseBoundStore<RootState>, coords: Coords) {\n store.setState({coords} as any) // eslint-disable-line @typescript-eslint/no-explicit-any\n}"],"names":[],"mappings":";;AAKO,SAAS,YAAY;AAC1B,QAAM,SAAS,SAAS,CAAI,MAAA,EAAU,MAAM;AACrC,SAAA;AACT;AAEO,SAAS,aAAa,EAAC,WAAW,UAAU,YAAmB;AAEpE,QAAM,SAAS,SAAS,CAAK,MAAA,EAAE,GAAG,UAAU;AAC5C,UAAQ,MAAI;AACV,UAAM,QAAQ,OAAO,IAAI,MAAM,EAAG;AAClC,UAAM,SAAkB,EAAE,WAAW,UAAU,SAAS;AACxD,cAAU,OAAO,MAAM;AAAA,EACtB,GAAA,CAAC,WAAW,UAAU,QAAQ,CAAC;AACpC;AAEO,SAAS,iBAAiB,OAAgC;AAAA,EAC/D;AAAA,EAAW;AAAA,EAAU;AACvB,GAAW;AACT,UAAQ,MAAI;AACV,cAAU,OAAO,EAAC,WAAW,UAAU,SAAS,CAAA;AAAA,EAC/C,GAAA,CAAC,WAAW,UAAU,QAAQ,CAAC;AACpC;AAEgB,SAAA,UAAU,OAAgC,QAAgB;AAClE,QAAA,SAAS,EAAC,OAAA,CAAc;AAChC;"}
|