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.
Files changed (101) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +62 -23
  3. package/dist/cjs/main.js +55 -18
  4. package/dist/es/main.mjs +6 -3
  5. package/dist/es/main.mjs.map +1 -1
  6. package/dist/es/main10.mjs +8 -33
  7. package/dist/es/main10.mjs.map +1 -1
  8. package/dist/es/main11.mjs +33 -11
  9. package/dist/es/main11.mjs.map +1 -1
  10. package/dist/es/main12.mjs +11 -22
  11. package/dist/es/main12.mjs.map +1 -1
  12. package/dist/es/main13.mjs +17 -24
  13. package/dist/es/main13.mjs.map +1 -1
  14. package/dist/es/main14.mjs +2 -23
  15. package/dist/es/main14.mjs.map +1 -1
  16. package/dist/es/main15.mjs +28 -93
  17. package/dist/es/main15.mjs.map +1 -1
  18. package/dist/es/main16.mjs +21 -61
  19. package/dist/es/main16.mjs.map +1 -1
  20. package/dist/es/main17.mjs +94 -19
  21. package/dist/es/main17.mjs.map +1 -1
  22. package/dist/es/main18.mjs +62 -23
  23. package/dist/es/main18.mjs.map +1 -1
  24. package/dist/es/main19.mjs +17 -13
  25. package/dist/es/main19.mjs.map +1 -1
  26. package/dist/es/main20.mjs +23 -68
  27. package/dist/es/main20.mjs.map +1 -1
  28. package/dist/es/main21.mjs +19 -0
  29. package/dist/es/main21.mjs.map +1 -0
  30. package/dist/es/main22.mjs +83 -0
  31. package/dist/es/main22.mjs.map +1 -0
  32. package/dist/es/main3.mjs +3 -3
  33. package/dist/es/main3.mjs.map +1 -1
  34. package/dist/es/main4.mjs +3 -3
  35. package/dist/es/main5.mjs +32 -19
  36. package/dist/es/main5.mjs.map +1 -1
  37. package/dist/es/main6.mjs +19 -15
  38. package/dist/es/main6.mjs.map +1 -1
  39. package/dist/es/main7.mjs +10 -22
  40. package/dist/es/main7.mjs.map +1 -1
  41. package/dist/es/main8.mjs +22 -26
  42. package/dist/es/main8.mjs.map +1 -1
  43. package/dist/es/main9.mjs +26 -8
  44. package/dist/es/main9.mjs.map +1 -1
  45. package/dist/maplibre/cjs/main.js +55 -18
  46. package/dist/maplibre/es/main.mjs +6 -3
  47. package/dist/maplibre/es/main.mjs.map +1 -1
  48. package/dist/maplibre/es/main10.mjs +8 -33
  49. package/dist/maplibre/es/main10.mjs.map +1 -1
  50. package/dist/maplibre/es/main11.mjs +33 -11
  51. package/dist/maplibre/es/main11.mjs.map +1 -1
  52. package/dist/maplibre/es/main12.mjs +11 -22
  53. package/dist/maplibre/es/main12.mjs.map +1 -1
  54. package/dist/maplibre/es/main13.mjs +17 -24
  55. package/dist/maplibre/es/main13.mjs.map +1 -1
  56. package/dist/maplibre/es/main14.mjs +2 -23
  57. package/dist/maplibre/es/main14.mjs.map +1 -1
  58. package/dist/maplibre/es/main15.mjs +28 -93
  59. package/dist/maplibre/es/main15.mjs.map +1 -1
  60. package/dist/maplibre/es/main16.mjs +21 -61
  61. package/dist/maplibre/es/main16.mjs.map +1 -1
  62. package/dist/maplibre/es/main17.mjs +94 -19
  63. package/dist/maplibre/es/main17.mjs.map +1 -1
  64. package/dist/maplibre/es/main18.mjs +62 -23
  65. package/dist/maplibre/es/main18.mjs.map +1 -1
  66. package/dist/maplibre/es/main19.mjs +17 -13
  67. package/dist/maplibre/es/main19.mjs.map +1 -1
  68. package/dist/maplibre/es/main20.mjs +23 -68
  69. package/dist/maplibre/es/main20.mjs.map +1 -1
  70. package/dist/maplibre/es/main21.mjs +19 -0
  71. package/dist/maplibre/es/main21.mjs.map +1 -0
  72. package/dist/maplibre/es/main22.mjs +83 -0
  73. package/dist/maplibre/es/main22.mjs.map +1 -0
  74. package/dist/maplibre/es/main3.mjs +3 -3
  75. package/dist/maplibre/es/main3.mjs.map +1 -1
  76. package/dist/maplibre/es/main4.mjs +3 -3
  77. package/dist/maplibre/es/main5.mjs +32 -19
  78. package/dist/maplibre/es/main5.mjs.map +1 -1
  79. package/dist/maplibre/es/main6.mjs +19 -15
  80. package/dist/maplibre/es/main6.mjs.map +1 -1
  81. package/dist/maplibre/es/main7.mjs +10 -22
  82. package/dist/maplibre/es/main7.mjs.map +1 -1
  83. package/dist/maplibre/es/main8.mjs +22 -26
  84. package/dist/maplibre/es/main8.mjs.map +1 -1
  85. package/dist/maplibre/es/main9.mjs +26 -8
  86. package/dist/maplibre/es/main9.mjs.map +1 -1
  87. package/dist/maplibre/types/api/coords-to-vector-3.d.ts +3 -3
  88. package/dist/maplibre/types/api/index.d.ts +2 -1
  89. package/dist/maplibre/types/api/vector-3-to-coords.d.ts +3 -0
  90. package/dist/maplibre/types/core/canvas-overlay/sync-camera-fc.d.ts +2 -1
  91. package/dist/maplibre/types/core/earth-radius.d.ts +1 -0
  92. package/dist/types/api/coords-to-vector-3.d.ts +3 -3
  93. package/dist/types/api/index.d.ts +2 -1
  94. package/dist/types/api/vector-3-to-coords.d.ts +3 -0
  95. package/dist/types/core/canvas-overlay/sync-camera-fc.d.ts +2 -1
  96. package/dist/types/core/earth-radius.d.ts +1 -0
  97. package/made-with/studio-carto-urban-project.webp +0 -0
  98. package/package.json +6 -9
  99. package/stories/package.json +5 -5
  100. package/stories/yarn.lock +1935 -1089
  101. package/vitest.config.ts +1 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # react-three-map
2
2
 
3
+ ## 0.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 58c42d9: - Improve accuracy at long distances for `coordsToVector3`.
8
+ - Improve translation accuracy for `NearCoordinates`, but scale is still ignored.
9
+ - Update `earthRadius` from `6378137` to `6371008.8` to match [Mapbox](https://github.com/maplibre/maplibre-gl-js/blob/8ea76118210dd18fa52fdb83f2cbdd1229807346/src/geo/lng_lat.ts#L8) and [Maplibre](https://github.com/maplibre/maplibre-gl-js/blob/main/src/geo/lng_lat.ts#L8).
10
+
11
+ ## 0.8.1
12
+
13
+ ### Patch Changes
14
+
15
+ - 9dfe4f6: Remove `turf` dependency.
16
+ - 9dfe4f6: Map to wait for r3f to finish rendering before the next render in overlay mode.
17
+
3
18
  ## 0.8.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -11,10 +11,10 @@
11
11
 
12
12
  Until now you had:
13
13
 
14
- | imperative | declarative (react) |
15
- | --------------- | ----------------- |
16
- | Maplibre/Mapbox | react-map-gl |
17
- | THREE.js | react-three-fiber |
14
+ | imperative | declarative (react) |
15
+ | --------------- | ------------------- |
16
+ | Maplibre/Mapbox | react-map-gl |
17
+ | THREE.js | react-three-fiber |
18
18
 
19
19
  Now with `react-three-map`, you can use them together :fist_right::star::fist_left:.
20
20
 
@@ -22,6 +22,22 @@ Now with `react-three-map`, you can use them together :fist_right::star::fist_le
22
22
  npm install react-three-map
23
23
  ```
24
24
 
25
+ - [React Three Map](#react-three-map)
26
+ - [:book: Examples](#book-examples)
27
+ - [:mag: What does it look like?](#mag-what-does-it-look-like)
28
+ - [:thinking: Why we build this?](#thinking-why-we-build-this)
29
+ - [:gear: API](#gear-api)
30
+ - [Canvas](#canvas)
31
+ - [Render Props](#render-props)
32
+ - [Render Props removed from `@react-three/fiber`](#render-props-removed-from-react-threefiber)
33
+ - [Coordinates](#coordinates)
34
+ - [NearCoordinates](#nearcoordinates)
35
+ - [useMap](#usemap)
36
+ - [coordsToVector3](#coordstovector3)
37
+ - [vector3ToCoords](#vector3tocoords)
38
+ - [:tada: Made with `react-three-map`](#tada-made-with-react-three-map)
39
+
40
+
25
41
  ## :book: Examples
26
42
 
27
43
  Check out our examples [here](https://rodrigohamuy.github.io/react-three-map) (powered by [Ladle](https://ladle.dev/)).
@@ -120,13 +136,13 @@ It shares most of the props from R3F `<Canvas>`, so you can check them directly
120
136
 
121
137
  #### Render Props
122
138
 
123
- | Prop | Description | Default |
124
- | --------- | ------------------------------------------------ | ---------- |
125
- | latitude | The latitude coordinate where to add the scene. | |
126
- | longitude | The longitude coordinate where to add the scene. | |
127
- | altitude | The altitude coordinate where to add the scene. | `0` |
128
- | frameloop | Render mode: `"always"`, `"demand"`. | `"always"` |
129
- | overlay | Render on a separated canvas. | `false` |
139
+ | Prop | Description | Default |
140
+ | --------- | ------------------------------------------------ | ---------- |
141
+ | latitude | The latitude coordinate where to add the scene. | |
142
+ | longitude | The longitude coordinate where to add the scene. | |
143
+ | altitude | The altitude coordinate where to add the scene. | `0` |
144
+ | frameloop | Render mode: `"always"`, `"demand"`. | `"always"` |
145
+ | overlay | Render on a separated canvas. | `false` |
130
146
 
131
147
  **About `overlay`**
132
148
 
@@ -172,21 +188,21 @@ import { Canvas, Coordinates } from 'react-three-map'
172
188
  </Canvas>
173
189
  ```
174
190
 
175
- | Props | Description | Default |
176
- | --------- | ------------------------------------------------ | ---------- |
177
- | latitude | The latitude coordinate where to add the scene. | |
178
- | longitude | The longitude coordinate where to add the scene. | |
179
- | altitude | The altitude coordinate where to add the scene. | `0` |
191
+ | Props | Description | Default |
192
+ | --------- | ------------------------------------------------ | ------- |
193
+ | latitude | The latitude coordinate where to add the scene. | |
194
+ | longitude | The longitude coordinate where to add the scene. | |
195
+ | altitude | The altitude coordinate where to add the scene. | `0` |
180
196
 
181
197
  ### NearCoordinates
182
198
 
183
199
  [![](https://img.shields.io/badge/-demo-%23ff69b4)](https://rodrigohamuy.github.io/react-three-map/?story=multi-coordinates--default)
184
200
 
185
- Same as `Coordinates`, but with an error margin that increases the further you are from the origin.
201
+ Same as `Coordinates`, but scale is ignored in exchange of being able to be rendered under the same scene.
186
202
 
187
- Recommended to use at city level distances, but margin errors will be noticeable at country level distances.
203
+ Works well at city level distances, but since scale remains unchanged, is not recommended at country level distances.
188
204
 
189
- Check the story to see the difference between the two.
205
+ Check the story to see the difference between the two or check #102 for more info.
190
206
 
191
207
  ### useMap
192
208
 
@@ -208,12 +224,35 @@ const Component = () => {
208
224
 
209
225
  This utility function converts geographic coordinates into a `Vector3Tuple`, which represents a 3D vector in meters.
210
226
 
211
- Similar to `NearCoordinates` it has a relatively good precision at city distances, but is not recommended if your distances are too big.
227
+ Similar to `NearCoordinates`, remember that this only updates positions (translation) but that scale is not taken into account, which has an important factor at very long distances (country level).
212
228
 
213
229
 
214
- | Parameter | Description |
215
- | -------------- | ----------------------------------------------------------------- |
230
+ | Parameter | Description |
231
+ | ---------------- | --------------------------------------------------------------- |
216
232
  | `point: Coords` | The geographic coordinates of the point to convert. |
217
233
  | `origin: Coords` | The geographic coordinates used as the origin for calculations. |
218
234
 
219
- Returns a `Vector3Tuple` representing the 3D position of the point relative to the origin.
235
+ Returns a `Vector3Tuple` representing the 3D position of the point relative to the origin.
236
+
237
+ ### vector3ToCoords
238
+
239
+ [![](https://img.shields.io/badge/-demo-%23ff69b4)](https://rodrigohamuy.github.io/react-three-map/?story=pivot-controls--default)
240
+
241
+ This utility function converts a `Vector3Tuple`, which represents a 3D vector in meters, back into geographic coordinates.
242
+
243
+ It is the inverse of `coordsToVector3` but it does not have a good level of precision at long distances since we haven't reverse engineered #102 fix yet.
244
+
245
+ Recommended to use at city level distances, but margin errors will be noticeable at country level distances.
246
+
247
+ | Parameter | Description |
248
+ | ------------------------ | --------------------------------------------------------------- |
249
+ | `position: Vector3Tuple` | The 3D vector to convert back into geographic coordinates. |
250
+ | `origin: Coords` | The geographic coordinates used as the origin for calculations. |
251
+
252
+ Returns a `Coords` object representing the geographic coordinates of the point relative to the origin.
253
+
254
+ ## :tada: Made with `react-three-map`
255
+
256
+ [![studio carto](./made-with/studio-carto-urban-project.webp)](https://x.com/lonjon_thomas/status/1767151007983685979?s=20)
257
+
258
+ [![post](https://img.shields.io/badge/post-black?style=for-the-badge&logo=x)](https://x.com/lonjon_thomas/status/1767151007983685979?s=20) [![page](https://img.shields.io/badge/page-black?style=for-the-badge)](https://studio-carto-urban-project.netlify.app/)
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,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
- mapCanvas
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 (!manualRender)
389
- return;
390
- gl.render(scene, camera);
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
- mapCanvas
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;
package/dist/es/main.mjs CHANGED
@@ -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 { NearCoordinates } from "./main5.mjs";
5
- import { coordsToVector3 } from "./main6.mjs";
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/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;"}
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;"}
@@ -1,37 +1,12 @@
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);
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
- syncCamera
10
+ useFunction
36
11
  };
37
12
  //# sourceMappingURL=main10.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"main10.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
+ {"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 { useMemo } from "react";
2
- import { coordsToMatrix } from "./main17.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;
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
- useCoordsToMatrix
35
+ syncCamera
14
36
  };
15
37
  //# sourceMappingURL=main11.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"main11.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
+ {"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 { useThree, _roots } from "@react-three/fiber";
2
- import { useState } from "react";
3
- import { Matrix4 } from "three";
4
- function useR3M() {
5
- const r3m = useThree((s) => s.r3m);
6
- return r3m;
7
- }
8
- function useInitR3M(props) {
9
- const canvas = useThree((s) => s.gl.domElement);
10
- useState(() => {
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
- initR3M,
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-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
+ {"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 { useMemo } from "react";
3
- function useCoords() {
4
- const coords = useThree((s) => s.coords);
5
- return coords;
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 useSetCoords({ longitude, latitude, altitude }) {
8
+ function useInitR3M(props) {
8
9
  const canvas = useThree((s) => s.gl.domElement);
9
- useMemo(() => {
10
+ useState(() => {
10
11
  const store = _roots.get(canvas).store;
11
- const coords = { longitude, latitude, altitude };
12
- setCoords(store, coords);
13
- }, [longitude, latitude, altitude]);
12
+ initR3M({ ...props, store });
13
+ });
14
14
  }
15
- function useSetRootCoords(store, {
16
- longitude,
17
- latitude,
18
- altitude
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
- setCoords,
29
- useCoords,
30
- useSetCoords,
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-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;"}
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
- import { syncCamera } from "./main10.mjs";
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
- useRender
3
+ earthRadius
25
4
  };
26
5
  //# sourceMappingURL=main14.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"main14.mjs","sources":["../../src/core/canvas-in-layer/use-render.ts"],"sourcesContent":["import { RootState } from \"@react-three/fiber\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { UseBoundStore } from \"zustand\";\nimport { MapInstance } from \"../generic-map\";\nimport { syncCamera } from \"../sync-camera\";\nimport { useFunction } from \"../use-function\";\nimport { R3M } from \"../use-r3m\";\n\nexport function useRender({\n map, origin, useThree, frameloop, r3m,\n} :{\n map: MapInstance,\n origin: Matrix4Tuple,\n useThree: UseBoundStore<RootState>,\n frameloop?: 'always' | 'demand',\n r3m: R3M\n}) {\n const render = useFunction((_gl: WebGL2RenderingContext, projViewMx: number[]) => {\n r3m.viewProjMx.splice(0, 16, ...projViewMx)\n const state = useThree.getState();\n const camera = state.camera as PerspectiveCamera;\n const {gl, advance} = state;\n syncCamera(camera as PerspectiveCamera, origin, projViewMx as Matrix4Tuple);\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (!frameloop || frameloop === 'always') map.triggerRepaint();\n })\n return render;\n}"],"names":[],"mappings":";;AAQO,SAAS,UAAU;AAAA,EACxB;AAAA,EAAK;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAW;AACpC,GAMG;AACD,QAAM,SAAS,YAAY,CAAC,KAA6B,eAAyB;AAChF,QAAI,WAAW,OAAO,GAAG,IAAI,GAAG,UAAU;AACpC,UAAA,QAAQ,SAAS;AACvB,UAAM,SAAS,MAAM;AACf,UAAA,EAAC,IAAI,QAAW,IAAA;AACX,eAAA,QAA6B,QAAQ,UAA0B;AAC1E,OAAG,WAAW;AACd,YAAQ,KAAK,IAAQ,IAAA,MAAO,IAAI;AAC5B,QAAA,CAAC,aAAa,cAAc;AAAU,UAAI,eAAe;AAAA,EAAA,CAC9D;AACM,SAAA;AACT;"}
1
+ {"version":3,"file":"main14.mjs","sources":["../../src/core/earth-radius.ts"],"sourcesContent":["export const earthRadius = 6371008.8;\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}