react-three-map 0.8.0 → 0.8.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 +15 -0
- package/README.md +62 -23
- package/dist/cjs/main.js +55 -18
- package/dist/es/main.mjs +6 -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 +32 -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 +55 -18
- package/dist/maplibre/es/main.mjs +6 -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 +32 -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 +3 -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 +3 -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/made-with/studio-carto-urban-project.webp +0 -0
- package/package.json +6 -9
- package/stories/package.json +5 -5
- package/stories/yarn.lock +1935 -1089
- package/vitest.config.ts +1 -5
|
@@ -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,35 @@ function RenderAtCoords({ r3m, origin }) {
|
|
|
148
147
|
}, [set, r3m]);
|
|
149
148
|
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
150
149
|
}
|
|
150
|
+
const earthRadius = 63710088e-1;
|
|
151
|
+
const mercatorScaleLookup = {};
|
|
152
|
+
function getMercatorScale(lat) {
|
|
153
|
+
const index = Math.round(lat * 1e3);
|
|
154
|
+
if (mercatorScaleLookup[index] === void 0) {
|
|
155
|
+
mercatorScaleLookup[index] = 1 / Math.cos(lat * THREE.MathUtils.DEG2RAD);
|
|
156
|
+
}
|
|
157
|
+
return mercatorScaleLookup[index];
|
|
158
|
+
}
|
|
159
|
+
function averageMercatorScale(originLat, pointLat, steps = 10) {
|
|
160
|
+
let totalScale = 0;
|
|
161
|
+
const latStep = (pointLat - originLat) / steps;
|
|
162
|
+
for (let i = 0; i <= steps; i++) {
|
|
163
|
+
const lat = originLat + latStep * i;
|
|
164
|
+
totalScale += getMercatorScale(lat);
|
|
165
|
+
}
|
|
166
|
+
return totalScale / (steps + 1);
|
|
167
|
+
}
|
|
168
|
+
function coordsToVector3(point, origin) {
|
|
169
|
+
const latitudeDiff = (point.latitude - origin.latitude) * THREE.MathUtils.DEG2RAD;
|
|
170
|
+
const longitudeDiff = (point.longitude - origin.longitude) * THREE.MathUtils.DEG2RAD;
|
|
171
|
+
const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);
|
|
172
|
+
const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * THREE.MathUtils.DEG2RAD);
|
|
173
|
+
const y = altitudeDiff;
|
|
174
|
+
const steps = Math.ceil(Math.abs(point.latitude - origin.latitude)) * 100 + 1;
|
|
175
|
+
const avgScale = averageMercatorScale(origin.latitude, point.latitude, steps);
|
|
176
|
+
const z = -latitudeDiff * earthRadius / getMercatorScale(origin.latitude) * avgScale;
|
|
177
|
+
return [x, y, z];
|
|
178
|
+
}
|
|
151
179
|
function useCoords() {
|
|
152
180
|
const coords = fiber.useThree((s) => s.coords);
|
|
153
181
|
return coords;
|
|
@@ -172,18 +200,6 @@ function useSetRootCoords(store, {
|
|
|
172
200
|
function setCoords(store, coords) {
|
|
173
201
|
store.setState({ coords });
|
|
174
202
|
}
|
|
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
203
|
const NearCoordinates = react.memo(({ children, ...coords }) => {
|
|
188
204
|
const { latitude, longitude, altitude } = useCoords();
|
|
189
205
|
const pos2 = react.useMemo(() => coordsToVector3(coords, { latitude, longitude, altitude }), [
|
|
@@ -198,6 +214,14 @@ const NearCoordinates = react.memo(({ children, ...coords }) => {
|
|
|
198
214
|
return /* @__PURE__ */ jsxRuntime.jsx("object3D", { position: pos2, children });
|
|
199
215
|
});
|
|
200
216
|
NearCoordinates.displayName = "NearCoordinates";
|
|
217
|
+
function vector3ToCoords(position, origin) {
|
|
218
|
+
const [x, y, z] = position;
|
|
219
|
+
const latitude = origin.latitude + -z / earthRadius * THREE.MathUtils.RAD2DEG;
|
|
220
|
+
const longitude = origin.longitude + x / earthRadius * THREE.MathUtils.RAD2DEG / Math.cos(origin.latitude * THREE.MathUtils.DEG2RAD);
|
|
221
|
+
const altitude = (origin.altitude || 0) + y;
|
|
222
|
+
const coords = { latitude, longitude, altitude };
|
|
223
|
+
return coords;
|
|
224
|
+
}
|
|
201
225
|
const useFunction = (callback) => {
|
|
202
226
|
const callbackRef = react.useRef(callback);
|
|
203
227
|
callbackRef.current = callback;
|
|
@@ -370,8 +394,9 @@ const SyncCameraFC = react.memo(({
|
|
|
370
394
|
setOnRender,
|
|
371
395
|
manualRender,
|
|
372
396
|
onReady,
|
|
373
|
-
|
|
397
|
+
map
|
|
374
398
|
}) => {
|
|
399
|
+
const mapCanvas = map.getCanvas();
|
|
375
400
|
const r3m = useR3M();
|
|
376
401
|
const camRef = react.useRef(null);
|
|
377
402
|
const camera = fiber.useThree((s) => s.camera);
|
|
@@ -383,13 +408,23 @@ const SyncCameraFC = react.memo(({
|
|
|
383
408
|
const set = fiber.useThree((s) => s.set);
|
|
384
409
|
const origin = useCoordsToMatrix({ latitude, longitude, altitude, fromLngLat: r3m.fromLngLat });
|
|
385
410
|
const ready = react.useRef(false);
|
|
411
|
+
const triggerRepaint = react.useMemo(() => map.triggerRepaint, [map]);
|
|
412
|
+
const mapPaintRequests = react.useRef(0);
|
|
413
|
+
const triggerRepaintOff = useFunction(() => {
|
|
414
|
+
mapPaintRequests.current++;
|
|
415
|
+
});
|
|
386
416
|
fiber.useFrame(() => {
|
|
387
417
|
syncCamera(camera, origin, r3m.viewProjMx);
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
|
|
418
|
+
if (manualRender)
|
|
419
|
+
gl.render(scene, camera);
|
|
420
|
+
map.triggerRepaint = triggerRepaint;
|
|
421
|
+
if (mapPaintRequests.current > 0) {
|
|
422
|
+
mapPaintRequests.current = 0;
|
|
423
|
+
map.triggerRepaint();
|
|
424
|
+
}
|
|
391
425
|
}, -Infinity);
|
|
392
426
|
const onRender = useFunction((viewProjMx) => {
|
|
427
|
+
map.triggerRepaint = triggerRepaintOff;
|
|
393
428
|
if (threeCanvas.width !== mapCanvas.width || threeCanvas.height !== mapCanvas.height) {
|
|
394
429
|
setSize(
|
|
395
430
|
mapCanvas.clientWidth,
|
|
@@ -470,7 +505,7 @@ const CanvasPortal = react.memo(({
|
|
|
470
505
|
altitude,
|
|
471
506
|
setOnRender,
|
|
472
507
|
onReady,
|
|
473
|
-
|
|
508
|
+
map
|
|
474
509
|
}
|
|
475
510
|
),
|
|
476
511
|
ready && children
|
|
@@ -541,5 +576,7 @@ const useMap = useMap$1;
|
|
|
541
576
|
exports.Canvas = Canvas;
|
|
542
577
|
exports.Coordinates = Coordinates;
|
|
543
578
|
exports.NearCoordinates = NearCoordinates;
|
|
579
|
+
exports.averageMercatorScale = averageMercatorScale;
|
|
544
580
|
exports.coordsToVector3 = coordsToVector3;
|
|
545
581
|
exports.useMap = useMap;
|
|
582
|
+
exports.vector3ToCoords = vector3ToCoords;
|
|
@@ -1,14 +1,17 @@
|
|
|
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 { averageMercatorScale, 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,
|
|
12
|
+
averageMercatorScale,
|
|
11
13
|
coordsToVector3,
|
|
12
|
-
useMap
|
|
14
|
+
useMap,
|
|
15
|
+
vector3ToCoords
|
|
13
16
|
};
|
|
14
17
|
//# sourceMappingURL=main.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":["../../../src/maplibre.index.ts"],"sourcesContent":["import type { Map } from 'maplibre-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/maplibre.index.ts"],"sourcesContent":["import type { Map } from 'maplibre-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;"}
|
|
@@ -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
|
|
@@ -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;"}
|
|
@@ -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
|
|
@@ -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;"}
|
|
@@ -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
|
|
@@ -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;"}
|
|
@@ -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
|
|
@@ -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;"}
|
|
@@ -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 = 63710088e-1;
|
|
23
2
|
export {
|
|
24
|
-
|
|
3
|
+
earthRadius
|
|
25
4
|
};
|
|
26
5
|
//# sourceMappingURL=main14.mjs.map
|
|
@@ -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 = 6371008.8;\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}
|
|
@@ -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
|
|
@@ -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;"}
|