@dxos/react-ui-geo 0.7.5-labs.e27f9b9 → 0.7.5-labs.f400bbc
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 +118 -53
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +115 -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 +118 -53
- 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 +5 -5
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +9 -10
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.d.ts +7 -7
- package/dist/types/src/components/Map/Map.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.stories.d.ts +6 -2
- package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Controls.d.ts +2 -3
- package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
- package/dist/types/src/components/types.d.ts +2 -1
- package/dist/types/src/components/types.d.ts.map +1 -1
- package/dist/types/src/hooks/context.d.ts +2 -2
- package/dist/types/src/hooks/context.d.ts.map +1 -1
- package/dist/types/src/hooks/useTour.d.ts +8 -3
- package/dist/types/src/hooks/useTour.d.ts.map +1 -1
- package/dist/types/src/util/debug.d.ts.map +1 -1
- package/dist/types/src/util/render.d.ts +2 -2
- package/dist/types/src/util/render.d.ts.map +1 -1
- package/package.json +12 -10
- package/src/components/Globe/Globe.stories.tsx +15 -32
- package/src/components/Globe/Globe.tsx +56 -32
- package/src/components/Map/Map.stories.tsx +28 -6
- package/src/components/Map/Map.tsx +93 -82
- package/src/components/types.ts +2 -1
- package/src/hooks/context.tsx +5 -5
- package/src/hooks/useDrag.ts +1 -1
- package/src/hooks/useTour.ts +31 -19
- package/src/util/debug.ts +1 -0
- package/src/util/render.ts +18 -4
|
@@ -6,19 +6,19 @@ import {
|
|
|
6
6
|
import * as d37 from "d3";
|
|
7
7
|
import React3, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo, useRef, useState as useState3 } from "react";
|
|
8
8
|
import { useResizeDetector } from "react-resize-detector";
|
|
9
|
-
import { useDynamicRef } from "@dxos/react-ui";
|
|
9
|
+
import { useDynamicRef, useThemeContext } from "@dxos/react-ui";
|
|
10
10
|
import { mx } from "@dxos/react-ui-theme";
|
|
11
11
|
|
|
12
12
|
// packages/ui/react-ui-geo/src/hooks/context.tsx
|
|
13
13
|
import React, { createContext, useContext } from "react";
|
|
14
14
|
import { raise } from "@dxos/debug";
|
|
15
|
-
import {
|
|
15
|
+
import { useControlledState } from "@dxos/react-ui";
|
|
16
16
|
var GlobeContext = /* @__PURE__ */ createContext(void 0);
|
|
17
17
|
var GlobeContextProvider = ({ children, size, center: _center, scale: _scale, translation: _translation, rotation: _rotation }) => {
|
|
18
|
-
const [center, setCenter] =
|
|
19
|
-
const [scale, setScale] =
|
|
20
|
-
const [translation, setTranslation] =
|
|
21
|
-
const [rotation, setRotation] =
|
|
18
|
+
const [center, setCenter] = useControlledState(_center);
|
|
19
|
+
const [scale, setScale] = useControlledState(_scale);
|
|
20
|
+
const [translation, setTranslation] = useControlledState(_translation);
|
|
21
|
+
const [rotation, setRotation] = useControlledState(_rotation);
|
|
22
22
|
return /* @__PURE__ */ React.createElement(GlobeContext.Provider, {
|
|
23
23
|
value: {
|
|
24
24
|
size,
|
|
@@ -349,17 +349,22 @@ var createLayers = (topology, features, styles) => {
|
|
|
349
349
|
}
|
|
350
350
|
return layers;
|
|
351
351
|
};
|
|
352
|
-
var renderLayers = (generator, layers = [], scale) => {
|
|
352
|
+
var renderLayers = (generator, layers = [], scale, styles) => {
|
|
353
353
|
const context = generator.context();
|
|
354
354
|
const { canvas: { width, height } } = context;
|
|
355
355
|
context.reset();
|
|
356
|
-
|
|
357
|
-
|
|
356
|
+
if (styles.background) {
|
|
357
|
+
context.fillStyle = styles.background.fillStyle;
|
|
358
|
+
context.fillRect(0, 0, width, height);
|
|
359
|
+
} else {
|
|
360
|
+
context.clearRect(0, 0, width, height);
|
|
361
|
+
}
|
|
362
|
+
layers.forEach(({ path, styles: styles2 }) => {
|
|
358
363
|
context.save();
|
|
359
364
|
let fill = false;
|
|
360
365
|
let stroke = false;
|
|
361
|
-
if (
|
|
362
|
-
Object.entries(
|
|
366
|
+
if (styles2) {
|
|
367
|
+
Object.entries(styles2).forEach(([key, value]) => {
|
|
363
368
|
if (key === "pointRadius") {
|
|
364
369
|
generator.pointRadius(value * scale);
|
|
365
370
|
} else {
|
|
@@ -408,7 +413,7 @@ var useDrag = (controller, options = {}) => {
|
|
|
408
413
|
};
|
|
409
414
|
}, [
|
|
410
415
|
controller,
|
|
411
|
-
options
|
|
416
|
+
JSON.stringify(options)
|
|
412
417
|
]);
|
|
413
418
|
};
|
|
414
419
|
var cancelDrag = (node) => node.on(".drag", null);
|
|
@@ -514,11 +519,13 @@ var useSpinner = (controller, options = {}) => {
|
|
|
514
519
|
import * as d36 from "d3";
|
|
515
520
|
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
516
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";
|
|
517
524
|
var TRANSITION_NAME = "globe-tour";
|
|
518
525
|
var defaultDuration = 1500;
|
|
519
|
-
var useTour = (controller,
|
|
526
|
+
var useTour = (controller, points, options = {}) => {
|
|
520
527
|
const selection2 = d36.selection();
|
|
521
|
-
const [running, setRunning] = useState2(false);
|
|
528
|
+
const [running, setRunning] = useState2(options.running ?? false);
|
|
522
529
|
useEffect3(() => {
|
|
523
530
|
if (!running) {
|
|
524
531
|
selection2.interrupt(TRANSITION_NAME);
|
|
@@ -532,10 +539,16 @@ var useTour = (controller, features, options = {}) => {
|
|
|
532
539
|
alpha: false
|
|
533
540
|
});
|
|
534
541
|
const path = d36.geoPath(projection, context).pointRadius(2);
|
|
535
|
-
const tilt = 0;
|
|
542
|
+
const tilt = options.tilt ?? 0;
|
|
536
543
|
let last;
|
|
537
544
|
try {
|
|
538
|
-
|
|
545
|
+
const p = [
|
|
546
|
+
...points
|
|
547
|
+
];
|
|
548
|
+
if (options.loop) {
|
|
549
|
+
p.push(p[0]);
|
|
550
|
+
}
|
|
551
|
+
for (const next of p) {
|
|
539
552
|
if (!running) {
|
|
540
553
|
break;
|
|
541
554
|
}
|
|
@@ -573,13 +586,22 @@ var useTour = (controller, features, options = {}) => {
|
|
|
573
586
|
context.fill();
|
|
574
587
|
}
|
|
575
588
|
context.restore();
|
|
576
|
-
|
|
577
|
-
|
|
589
|
+
if (options.autoRotate) {
|
|
590
|
+
projection.rotate(iv(t2));
|
|
591
|
+
setRotation(projection.rotate());
|
|
592
|
+
}
|
|
578
593
|
});
|
|
579
594
|
await transition2.end();
|
|
580
595
|
last = next;
|
|
581
596
|
}
|
|
582
597
|
} 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
|
+
} finally {
|
|
583
605
|
setRunning(false);
|
|
584
606
|
}
|
|
585
607
|
});
|
|
@@ -590,15 +612,12 @@ var useTour = (controller, features, options = {}) => {
|
|
|
590
612
|
}
|
|
591
613
|
}, [
|
|
592
614
|
controller,
|
|
593
|
-
running
|
|
615
|
+
running,
|
|
616
|
+
JSON.stringify(options)
|
|
594
617
|
]);
|
|
595
618
|
return [
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
setRunning(true);
|
|
599
|
-
}
|
|
600
|
-
},
|
|
601
|
-
() => setRunning(false)
|
|
619
|
+
running,
|
|
620
|
+
setRunning
|
|
602
621
|
];
|
|
603
622
|
};
|
|
604
623
|
|
|
@@ -662,28 +681,45 @@ var ActionControls = ({ classNames, onAction }) => {
|
|
|
662
681
|
|
|
663
682
|
// packages/ui/react-ui-geo/src/components/Globe/Globe.tsx
|
|
664
683
|
var defaultStyles = {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
684
|
+
light: {
|
|
685
|
+
background: {
|
|
686
|
+
fillStyle: "#EEE"
|
|
687
|
+
},
|
|
688
|
+
water: {
|
|
689
|
+
fillStyle: "#555"
|
|
690
|
+
},
|
|
691
|
+
land: {
|
|
692
|
+
fillStyle: "#999"
|
|
693
|
+
},
|
|
694
|
+
line: {
|
|
695
|
+
strokeStyle: "darkred"
|
|
696
|
+
},
|
|
697
|
+
point: {
|
|
698
|
+
fillStyle: "#111111",
|
|
699
|
+
strokeStyle: "#111111",
|
|
700
|
+
strokeWidth: 1,
|
|
701
|
+
pointRadius: 0.5
|
|
702
|
+
}
|
|
681
703
|
},
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
704
|
+
dark: {
|
|
705
|
+
background: {
|
|
706
|
+
fillStyle: "#111111"
|
|
707
|
+
},
|
|
708
|
+
water: {
|
|
709
|
+
fillStyle: "#123E6A"
|
|
710
|
+
},
|
|
711
|
+
land: {
|
|
712
|
+
fillStyle: "#032153"
|
|
713
|
+
},
|
|
714
|
+
line: {
|
|
715
|
+
strokeStyle: "#111111"
|
|
716
|
+
},
|
|
717
|
+
point: {
|
|
718
|
+
fillStyle: "#111111",
|
|
719
|
+
strokeStyle: "#111111",
|
|
720
|
+
strokeWidth: 1,
|
|
721
|
+
pointRadius: 0.5
|
|
722
|
+
}
|
|
687
723
|
}
|
|
688
724
|
};
|
|
689
725
|
var projectionMap = {
|
|
@@ -711,7 +747,12 @@ var GlobeRoot = ({ classNames, children, ...props }) => {
|
|
|
711
747
|
...props
|
|
712
748
|
}, children));
|
|
713
749
|
};
|
|
714
|
-
var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topology, features, styles
|
|
750
|
+
var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topology, features, styles: _styles }, forwardRef3) => {
|
|
751
|
+
const { themeMode } = useThemeContext();
|
|
752
|
+
const styles = useMemo(() => _styles ?? defaultStyles[themeMode], [
|
|
753
|
+
_styles,
|
|
754
|
+
themeMode
|
|
755
|
+
]);
|
|
715
756
|
const [canvas, setCanvas] = useState3(null);
|
|
716
757
|
const canvasRef = (canvas2) => setCanvas(canvas2);
|
|
717
758
|
const projection = useMemo(() => getProjection(_projection), [
|
|
@@ -779,7 +820,7 @@ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topolog
|
|
|
779
820
|
0,
|
|
780
821
|
0
|
|
781
822
|
]);
|
|
782
|
-
renderLayers(generator, layers, scale);
|
|
823
|
+
renderLayers(generator, layers, scale, styles);
|
|
783
824
|
});
|
|
784
825
|
}
|
|
785
826
|
}, [
|
|
@@ -843,13 +884,13 @@ var Globe = {
|
|
|
843
884
|
|
|
844
885
|
// packages/ui/react-ui-geo/src/components/Map/Map.tsx
|
|
845
886
|
import "leaflet/dist/leaflet.css";
|
|
846
|
-
import { Control, DomEvent, DomUtil, latLngBounds } from "leaflet";
|
|
887
|
+
import L, { Control, DomEvent, DomUtil, latLngBounds } from "leaflet";
|
|
847
888
|
import React4, { forwardRef as forwardRef2, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2 } from "react";
|
|
848
889
|
import { createRoot } from "react-dom/client";
|
|
849
890
|
import { MapContainer, Marker, Popup, TileLayer, useMap } from "react-leaflet";
|
|
850
891
|
import { useResizeDetector as useResizeDetector2 } from "react-resize-detector";
|
|
851
892
|
import { debounce } from "@dxos/async";
|
|
852
|
-
import {
|
|
893
|
+
import { ThemeProvider, Tooltip } from "@dxos/react-ui";
|
|
853
894
|
import { defaultTx, mx as mx2 } from "@dxos/react-ui-theme";
|
|
854
895
|
var defaults = {
|
|
855
896
|
// TODO(burdon): Guess location.
|
|
@@ -871,7 +912,7 @@ var MapRoot = ({ classNames, center = defaults.center, zoom = defaults.zoom, ...
|
|
|
871
912
|
...props
|
|
872
913
|
});
|
|
873
914
|
};
|
|
874
|
-
var MapCanvas = /* @__PURE__ */ forwardRef2(({ markers
|
|
915
|
+
var MapCanvas = /* @__PURE__ */ forwardRef2(({ markers, center, zoom, onChange }, forwardedRef) => {
|
|
875
916
|
const { ref, width, height } = useResizeDetector2({
|
|
876
917
|
refreshRate: 200
|
|
877
918
|
});
|
|
@@ -937,13 +978,37 @@ var MapCanvas = /* @__PURE__ */ forwardRef2(({ markers = [], center, zoom, onCha
|
|
|
937
978
|
}, /* @__PURE__ */ React4.createElement(TileLayer, {
|
|
938
979
|
className: "dark:filter dark:grayscale dark:invert",
|
|
939
980
|
url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
|
940
|
-
}), markers
|
|
981
|
+
}), markers?.map(({ id, title, location: { lat, lng } }) => {
|
|
941
982
|
return /* @__PURE__ */ React4.createElement(Marker, {
|
|
942
983
|
key: id,
|
|
943
984
|
position: {
|
|
944
985
|
lat,
|
|
945
986
|
lng
|
|
946
|
-
}
|
|
987
|
+
},
|
|
988
|
+
icon: (
|
|
989
|
+
// TODO(burdon): Create custom icon from bundled assets.
|
|
990
|
+
new L.Icon({
|
|
991
|
+
iconUrl: "https://dxos.network/marker-icon.png",
|
|
992
|
+
iconRetinaUrl: "https://dxos.network/marker-icon-2x.png",
|
|
993
|
+
shadowUrl: "https://dxos.network/marker-shadow.png",
|
|
994
|
+
iconSize: [
|
|
995
|
+
25,
|
|
996
|
+
41
|
|
997
|
+
],
|
|
998
|
+
iconAnchor: [
|
|
999
|
+
12,
|
|
1000
|
+
41
|
|
1001
|
+
],
|
|
1002
|
+
popupAnchor: [
|
|
1003
|
+
1,
|
|
1004
|
+
-34
|
|
1005
|
+
],
|
|
1006
|
+
shadowSize: [
|
|
1007
|
+
41,
|
|
1008
|
+
41
|
|
1009
|
+
]
|
|
1010
|
+
})
|
|
1011
|
+
)
|
|
947
1012
|
}, title && /* @__PURE__ */ React4.createElement(Popup, null, title));
|
|
948
1013
|
}));
|
|
949
1014
|
});
|