@dxos/react-ui-geo 0.8.2-main.12df754 → 0.8.2-main.36232bc
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/dist/lib/browser/index.mjs +45 -55
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +40 -50
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +45 -55
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.stories.d.ts +5 -4
- package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/useTour.d.ts +1 -1
- package/dist/types/src/hooks/useTour.d.ts.map +1 -1
- package/dist/types/src/util/inertia.d.ts +1 -2
- package/dist/types/src/util/inertia.d.ts.map +1 -1
- package/dist/types/src/util/path.d.ts.map +1 -1
- package/dist/types/src/util/render.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/components/Globe/Globe.tsx +20 -11
- package/src/components/Map/Map.stories.tsx +4 -4
- package/src/hooks/useDrag.ts +3 -3
- package/src/hooks/useSpinner.ts +2 -2
- package/src/hooks/useTour.ts +9 -13
- package/src/util/inertia.ts +4 -5
- package/src/util/path.ts +2 -5
- package/src/util/render.ts +5 -6
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
} from "./chunk-ENCWOTYX.mjs";
|
|
4
4
|
|
|
5
5
|
// packages/ui/react-ui-geo/src/components/Globe/Globe.tsx
|
|
6
|
-
import
|
|
7
|
-
import React3, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo, useRef, useState as useState3 } from "react";
|
|
6
|
+
import { geoMercator, geoOrthographic, geoPath as geoPath2, geoTransverseMercator, interpolateNumber, transition, easeLinear, easeSinOut } from "d3";
|
|
7
|
+
import React3, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo as useMemo2, useRef, useState as useState3 } from "react";
|
|
8
8
|
import { useResizeDetector } from "react-resize-detector";
|
|
9
9
|
import { useDynamicRef, useThemeContext } from "@dxos/react-ui";
|
|
10
10
|
import { mx } from "@dxos/react-ui-theme";
|
|
@@ -38,7 +38,7 @@ var useGlobeContext = () => {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
// packages/ui/react-ui-geo/src/hooks/useDrag.ts
|
|
41
|
-
import
|
|
41
|
+
import { select as select2 } from "d3";
|
|
42
42
|
import { useEffect } from "react";
|
|
43
43
|
|
|
44
44
|
// packages/ui/react-ui-geo/src/util/debug.ts
|
|
@@ -57,7 +57,7 @@ var timer = (cb) => {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// packages/ui/react-ui-geo/src/util/inertia.ts
|
|
60
|
-
import
|
|
60
|
+
import { select, drag, timer as timer2 } from "d3";
|
|
61
61
|
import versor from "versor";
|
|
62
62
|
var restrictAxis = (axis) => (original, current) => current.map((d, i) => axis[i] ? d : original[i]);
|
|
63
63
|
var geoInertiaDrag = (target, render, projection, options) => {
|
|
@@ -67,7 +67,7 @@ var geoInertiaDrag = (target, render, projection, options) => {
|
|
|
67
67
|
if (target.node) {
|
|
68
68
|
target = target.node();
|
|
69
69
|
}
|
|
70
|
-
target =
|
|
70
|
+
target = select(target);
|
|
71
71
|
const inertia = geoInertiaDragHelper({
|
|
72
72
|
projection,
|
|
73
73
|
render: (rotation) => {
|
|
@@ -91,7 +91,7 @@ var geoInertiaDrag = (target, render, projection, options) => {
|
|
|
91
91
|
time: options.time,
|
|
92
92
|
hold: options.hold
|
|
93
93
|
});
|
|
94
|
-
target.call(
|
|
94
|
+
target.call(drag().on("start", inertia.start).on("drag", inertia.move).on("end", inertia.end));
|
|
95
95
|
return inertia;
|
|
96
96
|
};
|
|
97
97
|
var geoInertiaDragHelper = (opt) => {
|
|
@@ -152,7 +152,7 @@ function inertiaHelper(opt) {
|
|
|
152
152
|
0,
|
|
153
153
|
0
|
|
154
154
|
],
|
|
155
|
-
timer:
|
|
155
|
+
timer: timer2(() => {
|
|
156
156
|
}),
|
|
157
157
|
time: 0,
|
|
158
158
|
t: 0,
|
|
@@ -232,7 +232,7 @@ function inertiaHelper(opt) {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
// packages/ui/react-ui-geo/src/util/path.ts
|
|
235
|
-
import
|
|
235
|
+
import { geoCircle as d3GeoCircle } from "d3";
|
|
236
236
|
var positionToRotation = ([lng, lat], tilt = 0) => [
|
|
237
237
|
-lng,
|
|
238
238
|
tilt - lat,
|
|
@@ -246,7 +246,7 @@ var geoPoint = (point) => ({
|
|
|
246
246
|
type: "Point",
|
|
247
247
|
coordinates: geoToPosition(point)
|
|
248
248
|
});
|
|
249
|
-
var
|
|
249
|
+
var geoCircle = ({ lat, lng }, radius) => d3GeoCircle().radius(radius).center([
|
|
250
250
|
lng,
|
|
251
251
|
lat
|
|
252
252
|
])();
|
|
@@ -285,8 +285,8 @@ var getDistance = (point1, point2) => {
|
|
|
285
285
|
};
|
|
286
286
|
|
|
287
287
|
// packages/ui/react-ui-geo/src/util/render.ts
|
|
288
|
-
import
|
|
289
|
-
import
|
|
288
|
+
import { geoGraticule } from "d3";
|
|
289
|
+
import { feature, mesh } from "topojson-client";
|
|
290
290
|
var createLayers = (topology, features, styles) => {
|
|
291
291
|
const layers = [];
|
|
292
292
|
if (styles.water) {
|
|
@@ -300,7 +300,7 @@ var createLayers = (topology, features, styles) => {
|
|
|
300
300
|
if (styles.graticule) {
|
|
301
301
|
layers.push({
|
|
302
302
|
styles: styles.graticule,
|
|
303
|
-
path:
|
|
303
|
+
path: geoGraticule().step([
|
|
304
304
|
6,
|
|
305
305
|
6
|
|
306
306
|
])()
|
|
@@ -310,13 +310,13 @@ var createLayers = (topology, features, styles) => {
|
|
|
310
310
|
if (topology.objects.land && styles.land) {
|
|
311
311
|
layers.push({
|
|
312
312
|
styles: styles.land,
|
|
313
|
-
path:
|
|
313
|
+
path: feature(topology, topology.objects.land)
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
316
|
if (topology.objects.countries && styles.border) {
|
|
317
317
|
layers.push({
|
|
318
318
|
styles: styles.border,
|
|
319
|
-
path:
|
|
319
|
+
path: mesh(topology, topology.objects.countries, (a, b) => a !== b)
|
|
320
320
|
});
|
|
321
321
|
}
|
|
322
322
|
if (topology.objects.dots && styles.dots) {
|
|
@@ -390,7 +390,7 @@ var useDrag = (controller, options = {}) => {
|
|
|
390
390
|
if (!canvas || options.disabled) {
|
|
391
391
|
return;
|
|
392
392
|
}
|
|
393
|
-
geoInertiaDrag(
|
|
393
|
+
geoInertiaDrag(select2(canvas), () => {
|
|
394
394
|
controller.setRotation(controller.projection.rotate());
|
|
395
395
|
options.onUpdate?.({
|
|
396
396
|
type: "move",
|
|
@@ -409,7 +409,7 @@ var useDrag = (controller, options = {}) => {
|
|
|
409
409
|
})
|
|
410
410
|
});
|
|
411
411
|
return () => {
|
|
412
|
-
cancelDrag(
|
|
412
|
+
cancelDrag(select2(canvas));
|
|
413
413
|
};
|
|
414
414
|
}, [
|
|
415
415
|
controller,
|
|
@@ -463,12 +463,12 @@ var useMapZoomHandler = (controller) => {
|
|
|
463
463
|
};
|
|
464
464
|
|
|
465
465
|
// packages/ui/react-ui-geo/src/hooks/useSpinner.ts
|
|
466
|
-
import
|
|
466
|
+
import { timer as d3Timer } from "d3";
|
|
467
467
|
import { useEffect as useEffect2, useState } from "react";
|
|
468
468
|
var useSpinner = (controller, options = {}) => {
|
|
469
469
|
const [running, setRunning] = useState(false);
|
|
470
470
|
useEffect2(() => {
|
|
471
|
-
let
|
|
471
|
+
let timer3;
|
|
472
472
|
const start = () => {
|
|
473
473
|
const delta = options.delta ?? [
|
|
474
474
|
1e-3,
|
|
@@ -477,7 +477,7 @@ var useSpinner = (controller, options = {}) => {
|
|
|
477
477
|
];
|
|
478
478
|
let t = 0;
|
|
479
479
|
let lastRotation = controller.projection.rotate();
|
|
480
|
-
|
|
480
|
+
timer3 = d3Timer((elapsed) => {
|
|
481
481
|
const dt = elapsed - t;
|
|
482
482
|
t = elapsed;
|
|
483
483
|
const rotation = [
|
|
@@ -490,9 +490,9 @@ var useSpinner = (controller, options = {}) => {
|
|
|
490
490
|
});
|
|
491
491
|
};
|
|
492
492
|
const stop = () => {
|
|
493
|
-
if (
|
|
494
|
-
|
|
495
|
-
|
|
493
|
+
if (timer3) {
|
|
494
|
+
timer3.stop();
|
|
495
|
+
timer3 = void 0;
|
|
496
496
|
}
|
|
497
497
|
};
|
|
498
498
|
if (controller && running) {
|
|
@@ -516,19 +516,17 @@ var useSpinner = (controller, options = {}) => {
|
|
|
516
516
|
};
|
|
517
517
|
|
|
518
518
|
// packages/ui/react-ui-geo/src/hooks/useTour.ts
|
|
519
|
-
import
|
|
520
|
-
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
519
|
+
import { geoPath, geoInterpolate, geoDistance, selection as d3Selection } from "d3";
|
|
520
|
+
import { useEffect as useEffect3, useState as useState2, useMemo } from "react";
|
|
521
521
|
import versor2 from "versor";
|
|
522
|
-
import { log } from "@dxos/log";
|
|
523
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-geo/src/hooks/useTour.ts";
|
|
524
522
|
var TRANSITION_NAME = "globe-tour";
|
|
525
523
|
var defaultDuration = 1500;
|
|
526
524
|
var useTour = (controller, points, options = {}) => {
|
|
527
|
-
const
|
|
525
|
+
const selection = useMemo(() => d3Selection(), []);
|
|
528
526
|
const [running, setRunning] = useState2(options.running ?? false);
|
|
529
527
|
useEffect3(() => {
|
|
530
528
|
if (!running) {
|
|
531
|
-
|
|
529
|
+
selection.interrupt(TRANSITION_NAME);
|
|
532
530
|
return;
|
|
533
531
|
}
|
|
534
532
|
let t;
|
|
@@ -538,7 +536,7 @@ var useTour = (controller, points, options = {}) => {
|
|
|
538
536
|
const context = canvas.getContext("2d", {
|
|
539
537
|
alpha: false
|
|
540
538
|
});
|
|
541
|
-
const path =
|
|
539
|
+
const path = geoPath(projection, context).pointRadius(2);
|
|
542
540
|
const tilt = options.tilt ?? 0;
|
|
543
541
|
let last;
|
|
544
542
|
try {
|
|
@@ -554,12 +552,12 @@ var useTour = (controller, points, options = {}) => {
|
|
|
554
552
|
}
|
|
555
553
|
const p1 = last ? geoToPosition(last) : void 0;
|
|
556
554
|
const p2 = geoToPosition(next);
|
|
557
|
-
const ip =
|
|
558
|
-
const distance =
|
|
555
|
+
const ip = geoInterpolate(p1 || p2, p2);
|
|
556
|
+
const distance = geoDistance(p1 || p2, p2);
|
|
559
557
|
const r1 = p1 ? positionToRotation(p1, tilt) : controller.projection.rotate();
|
|
560
558
|
const r2 = positionToRotation(p2, tilt);
|
|
561
559
|
const iv = versor2.interpolate(r1, r2);
|
|
562
|
-
const transition2 =
|
|
560
|
+
const transition2 = selection.transition(TRANSITION_NAME).duration(Math.max(options.duration ?? defaultDuration, distance * 2e3)).tween("render", () => (t2) => {
|
|
563
561
|
const t1 = Math.max(0, Math.min(1, t2 * 2 - 1));
|
|
564
562
|
const t22 = Math.min(1, t2 * 2);
|
|
565
563
|
context.save();
|
|
@@ -586,28 +584,20 @@ var useTour = (controller, points, options = {}) => {
|
|
|
586
584
|
context.fill();
|
|
587
585
|
}
|
|
588
586
|
context.restore();
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
setRotation(projection.rotate());
|
|
592
|
-
}
|
|
587
|
+
projection.rotate(iv(t2));
|
|
588
|
+
setRotation(projection.rotate());
|
|
593
589
|
});
|
|
594
590
|
await transition2.end();
|
|
595
591
|
last = next;
|
|
596
592
|
}
|
|
597
593
|
} catch (err) {
|
|
598
|
-
log.catch(err, void 0, {
|
|
599
|
-
F: __dxlog_file,
|
|
600
|
-
L: 112,
|
|
601
|
-
S: void 0,
|
|
602
|
-
C: (f, a) => f(...a)
|
|
603
|
-
});
|
|
604
594
|
} finally {
|
|
605
595
|
setRunning(false);
|
|
606
596
|
}
|
|
607
597
|
});
|
|
608
598
|
return () => {
|
|
609
599
|
clearTimeout(t);
|
|
610
|
-
|
|
600
|
+
selection.interrupt(TRANSITION_NAME);
|
|
611
601
|
};
|
|
612
602
|
}
|
|
613
603
|
}, [
|
|
@@ -723,16 +713,16 @@ var defaultStyles = {
|
|
|
723
713
|
}
|
|
724
714
|
};
|
|
725
715
|
var projectionMap = {
|
|
726
|
-
orthographic:
|
|
727
|
-
mercator:
|
|
728
|
-
"transverse-mercator":
|
|
716
|
+
orthographic: geoOrthographic,
|
|
717
|
+
mercator: geoMercator,
|
|
718
|
+
"transverse-mercator": geoTransverseMercator
|
|
729
719
|
};
|
|
730
720
|
var getProjection = (type = "orthographic") => {
|
|
731
721
|
if (typeof type === "string") {
|
|
732
|
-
const constructor = projectionMap[type] ??
|
|
722
|
+
const constructor = projectionMap[type] ?? geoOrthographic;
|
|
733
723
|
return constructor();
|
|
734
724
|
}
|
|
735
|
-
return type ??
|
|
725
|
+
return type ?? geoOrthographic();
|
|
736
726
|
};
|
|
737
727
|
var GlobeRoot = ({ classNames, children, ...props }) => {
|
|
738
728
|
const { ref, width, height } = useResizeDetector();
|
|
@@ -749,16 +739,16 @@ var GlobeRoot = ({ classNames, children, ...props }) => {
|
|
|
749
739
|
};
|
|
750
740
|
var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topology, features, styles: _styles }, forwardRef3) => {
|
|
751
741
|
const { themeMode } = useThemeContext();
|
|
752
|
-
const styles =
|
|
742
|
+
const styles = useMemo2(() => _styles ?? defaultStyles[themeMode], [
|
|
753
743
|
_styles,
|
|
754
744
|
themeMode
|
|
755
745
|
]);
|
|
756
746
|
const [canvas, setCanvas] = useState3(null);
|
|
757
747
|
const canvasRef = (canvas2) => setCanvas(canvas2);
|
|
758
|
-
const projection =
|
|
748
|
+
const projection = useMemo2(() => getProjection(_projection), [
|
|
759
749
|
_projection
|
|
760
750
|
]);
|
|
761
|
-
const layers =
|
|
751
|
+
const layers = useMemo2(() => {
|
|
762
752
|
return timer(() => createLayers(topology, features, styles));
|
|
763
753
|
}, [
|
|
764
754
|
topology,
|
|
@@ -789,8 +779,8 @@ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topolog
|
|
|
789
779
|
setCenter,
|
|
790
780
|
setScale: (s) => {
|
|
791
781
|
if (typeof s === "function") {
|
|
792
|
-
const is =
|
|
793
|
-
|
|
782
|
+
const is = interpolateNumber(scaleRef.current, s(scaleRef.current));
|
|
783
|
+
transition().ease(zooming.current ? easeLinear : easeSinOut).duration(200).tween("scale", () => (t) => setScale(is(t))).on("end", () => {
|
|
794
784
|
zooming.current = false;
|
|
795
785
|
});
|
|
796
786
|
} else {
|
|
@@ -803,7 +793,7 @@ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topolog
|
|
|
803
793
|
}, [
|
|
804
794
|
canvas
|
|
805
795
|
]);
|
|
806
|
-
const generator =
|
|
796
|
+
const generator = useMemo2(() => canvas && projection && geoPath2(projection, canvas.getContext("2d", {
|
|
807
797
|
alpha: false
|
|
808
798
|
})), [
|
|
809
799
|
canvas,
|
|
@@ -1064,7 +1054,7 @@ export {
|
|
|
1064
1054
|
closestPoint,
|
|
1065
1055
|
controlPositions,
|
|
1066
1056
|
createLayers,
|
|
1067
|
-
|
|
1057
|
+
geoCircle,
|
|
1068
1058
|
geoInertiaDrag,
|
|
1069
1059
|
geoLine,
|
|
1070
1060
|
geoPoint,
|