@dxos/react-ui-geo 0.7.5-staging.2ff1350 → 0.7.5-staging.e6154f3
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 +32 -19
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +35 -22
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +32 -19
- 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.stories.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.d.ts +4 -4
- package/dist/types/src/components/Map/Map.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/useTour.d.ts +8 -3
- package/dist/types/src/hooks/useTour.d.ts.map +1 -1
- package/package.json +11 -10
- package/src/components/Globe/Globe.stories.tsx +3 -6
- package/src/components/Map/Map.tsx +93 -96
- package/src/components/types.ts +2 -1
- package/src/hooks/useDrag.ts +1 -1
- package/src/hooks/useTour.ts +31 -19
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import 'leaflet/dist/leaflet.css';
|
|
2
|
-
import L from 'leaflet';
|
|
3
|
-
import { type ControlPosition, type LatLngExpression } from 'leaflet';
|
|
2
|
+
import L, { type ControlPosition, type LatLngExpression } from 'leaflet';
|
|
4
3
|
import React from 'react';
|
|
5
|
-
import {
|
|
4
|
+
import type { MapContainerProps } from 'react-leaflet';
|
|
6
5
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
7
6
|
import { type ControlProps } from '../Toolbar';
|
|
8
7
|
import { type MapCanvasProps } from '../types';
|
|
@@ -18,6 +17,7 @@ export declare const Map: {
|
|
|
18
17
|
Root: ({ classNames, center, zoom, ...props }: MapRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
18
|
Canvas: React.ForwardRefExoticComponent<Omit<{
|
|
20
19
|
markers?: import("../..").MapMarker[];
|
|
20
|
+
selected?: string[];
|
|
21
21
|
zoom?: number;
|
|
22
22
|
center?: L.LatLngLiteral;
|
|
23
23
|
onChange?: (ev: {
|
|
@@ -25,7 +25,7 @@ export declare const Map: {
|
|
|
25
25
|
zoom: number;
|
|
26
26
|
}) => void;
|
|
27
27
|
}, "className"> & {
|
|
28
|
-
classNames?: import("@dxos/react-ui").ClassNameValue;
|
|
28
|
+
classNames?: import("@dxos/react-ui-types").ClassNameValue;
|
|
29
29
|
} & React.RefAttributes<MapController>>;
|
|
30
30
|
Zoom: ({ onAction, position, ...props }: MapControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
31
31
|
Action: ({ onAction, position, ...props }: MapControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Map.d.ts","sourceRoot":"","sources":["../../../../../src/components/Map/Map.tsx"],"names":[],"mappings":"AAKA,OAAO,0BAA0B,CAAC;AAElC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"Map.d.ts","sourceRoot":"","sources":["../../../../../src/components/Map/Map.tsx"],"names":[],"mappings":"AAKA,OAAO,0BAA0B,CAAC;AAElC,OAAO,CAAC,EAAE,EAA4C,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACnH,OAAO,KAA6E,MAAM,OAAO,CAAC;AAElG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAKvD,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAG9E,OAAO,EAAkD,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAe/C,KAAK,YAAY,GAAG,eAAe,CAAC,iBAAiB,CAAC,CAAC;AAuBvD,KAAK,aAAa,GAAG;IACnB,SAAS,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7D,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,KAAK,IAAI,CAAC;CACjD,CAAC;AAoIF,KAAK,eAAe,GAAG;IAAE,QAAQ,CAAC,EAAE,eAAe,CAAA;CAAE,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAMvF,eAAO,MAAM,GAAG;mDAjK2E,YAAY;;;;;;;;;;;;;6CAoK7C,eAAe;+CAKZ,eAAe;CAK3E,CAAC;AAEF,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type LatLngLiteral } from 'leaflet';
|
|
2
2
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
3
3
|
import { type MapMarker } from '../types';
|
|
4
|
-
export type
|
|
4
|
+
export { type LatLngLiteral };
|
|
5
5
|
export type MapCanvasProps = ThemedClassName<{
|
|
6
6
|
markers?: MapMarker[];
|
|
7
|
+
selected?: string[];
|
|
7
8
|
zoom?: number;
|
|
8
9
|
center?: LatLngLiteral;
|
|
9
10
|
onChange?: (ev: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,KAAK,aAAa,EAAE,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC;IAC3C,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE;QAAE,MAAM,EAAE,aAAa,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAClE,CAAC,CAAC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import { type Dispatch, type SetStateAction } from 'react';
|
|
1
2
|
import type { GlobeController } from '../components';
|
|
2
|
-
import { type
|
|
3
|
+
import { type LatLng, type StyleSet } from '../util';
|
|
3
4
|
export type TourOptions = {
|
|
5
|
+
running?: boolean;
|
|
4
6
|
disabled?: boolean;
|
|
5
|
-
styles?: StyleSet;
|
|
6
7
|
duration?: number;
|
|
8
|
+
loop?: boolean;
|
|
9
|
+
tilt?: number;
|
|
10
|
+
autoRotate?: boolean;
|
|
11
|
+
styles?: StyleSet;
|
|
7
12
|
};
|
|
8
13
|
/**
|
|
9
14
|
* Iterates between points.
|
|
10
15
|
* Inspired by: https://observablehq.com/@mbostock/top-100-cities
|
|
11
16
|
*/
|
|
12
|
-
export declare const useTour: (controller?: GlobeController | null,
|
|
17
|
+
export declare const useTour: (controller?: GlobeController | null, points?: LatLng[], options?: TourOptions) => [boolean, Dispatch<SetStateAction<boolean>>];
|
|
13
18
|
//# sourceMappingURL=useTour.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTour.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTour.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTour.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTour.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAuB,MAAM,OAAO,CAAC;AAKhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAiB,KAAK,MAAM,EAAsB,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAMxF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,OAAO,gBACL,eAAe,GAAG,IAAI,WAC1B,MAAM,EAAE,YACR,WAAW,KACnB,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CA0F7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-geo",
|
|
3
|
-
"version": "0.7.5-staging.
|
|
3
|
+
"version": "0.7.5-staging.e6154f3",
|
|
4
4
|
"description": "Geo components.",
|
|
5
5
|
"homepage": "https://github.com/dxos",
|
|
6
6
|
"bugs": "https://github.com/dxos/issues",
|
|
@@ -45,10 +45,11 @@
|
|
|
45
45
|
"topojson-client": "^3.1.0",
|
|
46
46
|
"topojson-simplify": "^3.0.3",
|
|
47
47
|
"versor": "^0.2.0",
|
|
48
|
-
"@dxos/async": "0.7.5-staging.
|
|
49
|
-
"@dxos/debug": "0.7.5-staging.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/node-std": "0.7.5-staging.
|
|
48
|
+
"@dxos/async": "0.7.5-staging.e6154f3",
|
|
49
|
+
"@dxos/debug": "0.7.5-staging.e6154f3",
|
|
50
|
+
"@dxos/log": "0.7.5-staging.e6154f3",
|
|
51
|
+
"@dxos/node-std": "0.7.5-staging.e6154f3",
|
|
52
|
+
"@dxos/util": "0.7.5-staging.e6154f3"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@react-three/drei": "^9.99.0",
|
|
@@ -68,15 +69,15 @@
|
|
|
68
69
|
"react": "~18.2.0",
|
|
69
70
|
"react-dom": "~18.2.0",
|
|
70
71
|
"three": "0.165.0",
|
|
71
|
-
"@dxos/react-ui": "0.7.5-staging.
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
72
|
+
"@dxos/react-ui": "0.7.5-staging.e6154f3",
|
|
73
|
+
"@dxos/storybook-utils": "0.7.5-staging.e6154f3",
|
|
74
|
+
"@dxos/react-ui-theme": "0.7.5-staging.e6154f3"
|
|
74
75
|
},
|
|
75
76
|
"peerDependencies": {
|
|
76
77
|
"react": "~18.2.0",
|
|
77
78
|
"react-dom": "~18.2.0",
|
|
78
|
-
"@dxos/react-ui": "0.7.5-staging.
|
|
79
|
-
"@dxos/react-ui-theme": "0.7.5-staging.
|
|
79
|
+
"@dxos/react-ui": "0.7.5-staging.e6154f3",
|
|
80
|
+
"@dxos/react-ui-theme": "0.7.5-staging.e6154f3"
|
|
80
81
|
},
|
|
81
82
|
"publishConfig": {
|
|
82
83
|
"access": "public"
|
|
@@ -160,10 +160,7 @@ const Story = ({
|
|
|
160
160
|
|
|
161
161
|
// Control hooks.
|
|
162
162
|
const [startSpinner, stopSpinner] = useSpinner(controller.current, { disabled: !spin });
|
|
163
|
-
const [
|
|
164
|
-
disabled: !tour,
|
|
165
|
-
styles,
|
|
166
|
-
});
|
|
163
|
+
const [_running, setRunning] = useTour(controller.current, features?.points, { disabled: !tour, styles });
|
|
167
164
|
useDrag(controller.current, {
|
|
168
165
|
xAxis,
|
|
169
166
|
disabled: !drag,
|
|
@@ -171,7 +168,7 @@ const Story = ({
|
|
|
171
168
|
switch (event.type) {
|
|
172
169
|
case 'start': {
|
|
173
170
|
stopSpinner();
|
|
174
|
-
|
|
171
|
+
setRunning(false);
|
|
175
172
|
break;
|
|
176
173
|
}
|
|
177
174
|
}
|
|
@@ -186,7 +183,7 @@ const Story = ({
|
|
|
186
183
|
startSpinner();
|
|
187
184
|
}
|
|
188
185
|
if (tour) {
|
|
189
|
-
|
|
186
|
+
setRunning(true);
|
|
190
187
|
}
|
|
191
188
|
break;
|
|
192
189
|
}
|
|
@@ -5,16 +5,15 @@
|
|
|
5
5
|
// eslint-disable-next-line no-restricted-imports
|
|
6
6
|
import 'leaflet/dist/leaflet.css';
|
|
7
7
|
|
|
8
|
-
import L from 'leaflet';
|
|
9
|
-
import {
|
|
10
|
-
import React, { forwardRef, type PropsWithChildren, useEffect, useImperativeHandle } from 'react';
|
|
8
|
+
import L, { Control, DomEvent, DomUtil, latLngBounds, type ControlPosition, type LatLngExpression } from 'leaflet';
|
|
9
|
+
import React, { forwardRef, useEffect, useImperativeHandle, type PropsWithChildren } from 'react';
|
|
11
10
|
import { createRoot } from 'react-dom/client';
|
|
11
|
+
import type { MapContainerProps } from 'react-leaflet';
|
|
12
12
|
import { MapContainer, Marker, Popup, TileLayer, useMap } from 'react-leaflet';
|
|
13
|
-
import { type MapContainerProps } from 'react-leaflet/lib/MapContainer';
|
|
14
13
|
import { useResizeDetector } from 'react-resize-detector';
|
|
15
14
|
|
|
16
15
|
import { debounce } from '@dxos/async';
|
|
17
|
-
import {
|
|
16
|
+
import { ThemeProvider, Tooltip, type ThemedClassName } from '@dxos/react-ui';
|
|
18
17
|
import { defaultTx, mx } from '@dxos/react-ui-theme';
|
|
19
18
|
|
|
20
19
|
import { ActionControls, controlPositions, ZoomControls, type ControlProps } from '../Toolbar';
|
|
@@ -61,98 +60,96 @@ type MapController = {
|
|
|
61
60
|
setZoom: (cb: (zoom: number) => number) => void;
|
|
62
61
|
};
|
|
63
62
|
|
|
64
|
-
const MapCanvas = forwardRef<MapController, MapCanvasProps>(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
() =>
|
|
72
|
-
setCenter: (center: LatLngExpression, zoom?: number) => {
|
|
73
|
-
map.setView(center, zoom);
|
|
74
|
-
},
|
|
75
|
-
setZoom: (cb) => {
|
|
76
|
-
map.setZoom(cb(map.getZoom()));
|
|
77
|
-
},
|
|
78
|
-
}),
|
|
79
|
-
[map],
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// Resize.
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (width && height) {
|
|
85
|
-
map.invalidateSize();
|
|
86
|
-
}
|
|
87
|
-
}, [width, height]);
|
|
88
|
-
|
|
89
|
-
// Position.
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
if (center) {
|
|
63
|
+
const MapCanvas = forwardRef<MapController, MapCanvasProps>(({ markers, center, zoom, onChange }, forwardedRef) => {
|
|
64
|
+
const { ref, width, height } = useResizeDetector({ refreshRate: 200 });
|
|
65
|
+
const map = useMap();
|
|
66
|
+
|
|
67
|
+
useImperativeHandle(
|
|
68
|
+
forwardedRef,
|
|
69
|
+
() => ({
|
|
70
|
+
setCenter: (center: LatLngExpression, zoom?: number) => {
|
|
92
71
|
map.setView(center, zoom);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
map.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
)
|
|
72
|
+
},
|
|
73
|
+
setZoom: (cb) => {
|
|
74
|
+
map.setZoom(cb(map.getZoom()));
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
[map],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Resize.
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (width && height) {
|
|
83
|
+
map.invalidateSize();
|
|
84
|
+
}
|
|
85
|
+
}, [width, height]);
|
|
86
|
+
|
|
87
|
+
// Position.
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (center) {
|
|
90
|
+
map.setView(center, zoom);
|
|
91
|
+
} else if (zoom !== undefined) {
|
|
92
|
+
map.setZoom(zoom);
|
|
93
|
+
}
|
|
94
|
+
}, [center, zoom]);
|
|
95
|
+
|
|
96
|
+
// Events.
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const handler = debounce(() => {
|
|
99
|
+
onChange?.({ center: map.getCenter(), zoom: map.getZoom() });
|
|
100
|
+
}, 100);
|
|
101
|
+
map.on('move', handler);
|
|
102
|
+
map.on('zoom', handler);
|
|
103
|
+
return () => {
|
|
104
|
+
map.off('move', handler);
|
|
105
|
+
map.off('zoom', handler);
|
|
106
|
+
};
|
|
107
|
+
}, [map, onChange]);
|
|
108
|
+
|
|
109
|
+
// Set the viewport around the markers, or show the whole world map if `markers` is empty.
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (markers.length > 0) {
|
|
112
|
+
const bounds = latLngBounds(markers.map((marker) => marker.location));
|
|
113
|
+
map.fitBounds(bounds);
|
|
114
|
+
} else {
|
|
115
|
+
map.setView(defaults.center, defaults.zoom);
|
|
116
|
+
}
|
|
117
|
+
}, [markers]);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div ref={ref} className='flex w-full h-full overflow-hidden bg-baseSurface'>
|
|
121
|
+
{/* Map tiles. */}
|
|
122
|
+
<TileLayer
|
|
123
|
+
className='dark:filter dark:grayscale dark:invert'
|
|
124
|
+
url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
|
|
125
|
+
/>
|
|
126
|
+
|
|
127
|
+
{/* Markers. */}
|
|
128
|
+
{markers?.map(({ id, title, location: { lat, lng } }) => {
|
|
129
|
+
return (
|
|
130
|
+
<Marker
|
|
131
|
+
key={id}
|
|
132
|
+
position={{ lat, lng }}
|
|
133
|
+
icon={
|
|
134
|
+
// TODO(burdon): Create custom icon from bundled assets.
|
|
135
|
+
new L.Icon({
|
|
136
|
+
iconUrl: 'https://dxos.network/marker-icon.png',
|
|
137
|
+
iconRetinaUrl: 'https://dxos.network/marker-icon-2x.png',
|
|
138
|
+
shadowUrl: 'https://dxos.network/marker-shadow.png',
|
|
139
|
+
iconSize: [25, 41],
|
|
140
|
+
iconAnchor: [12, 41],
|
|
141
|
+
popupAnchor: [1, -34],
|
|
142
|
+
shadowSize: [41, 41],
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
>
|
|
146
|
+
{title && <Popup>{title}</Popup>}
|
|
147
|
+
</Marker>
|
|
148
|
+
);
|
|
149
|
+
})}
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
});
|
|
156
153
|
|
|
157
154
|
//
|
|
158
155
|
// Controls
|
package/src/components/types.ts
CHANGED
|
@@ -8,10 +8,11 @@ import { type ThemedClassName } from '@dxos/react-ui';
|
|
|
8
8
|
|
|
9
9
|
import { type MapMarker } from '../types';
|
|
10
10
|
|
|
11
|
-
export type
|
|
11
|
+
export { type LatLngLiteral };
|
|
12
12
|
|
|
13
13
|
export type MapCanvasProps = ThemedClassName<{
|
|
14
14
|
markers?: MapMarker[];
|
|
15
|
+
selected?: string[];
|
|
15
16
|
zoom?: number;
|
|
16
17
|
center?: LatLngLiteral;
|
|
17
18
|
onChange?: (ev: { center: LatLngLiteral; zoom: number }) => void;
|
package/src/hooks/useDrag.ts
CHANGED
|
@@ -49,7 +49,7 @@ export const useDrag = (controller?: GlobeController | null, options: DragOption
|
|
|
49
49
|
return () => {
|
|
50
50
|
cancelDrag(d3.select(canvas));
|
|
51
51
|
};
|
|
52
|
-
}, [controller, options]);
|
|
52
|
+
}, [controller, JSON.stringify(options)]);
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
const cancelDrag = (node) => node.on('.drag', null);
|
package/src/hooks/useTour.ts
CHANGED
|
@@ -3,29 +3,39 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import * as d3 from 'd3';
|
|
6
|
-
import { useEffect, useState } from 'react';
|
|
6
|
+
import { type Dispatch, type SetStateAction, useEffect, useState } from 'react';
|
|
7
7
|
import versor from 'versor';
|
|
8
8
|
|
|
9
|
+
import { log } from '@dxos/log';
|
|
10
|
+
|
|
9
11
|
import type { GlobeController } from '../components';
|
|
10
|
-
import {
|
|
12
|
+
import { geoToPosition, type LatLng, positionToRotation, type StyleSet } from '../util';
|
|
11
13
|
|
|
12
14
|
const TRANSITION_NAME = 'globe-tour';
|
|
13
15
|
|
|
14
16
|
const defaultDuration = 1_500;
|
|
15
17
|
|
|
16
18
|
export type TourOptions = {
|
|
19
|
+
running?: boolean;
|
|
17
20
|
disabled?: boolean;
|
|
18
|
-
styles?: StyleSet;
|
|
19
21
|
duration?: number;
|
|
22
|
+
loop?: boolean;
|
|
23
|
+
tilt?: number;
|
|
24
|
+
autoRotate?: boolean;
|
|
25
|
+
styles?: StyleSet;
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* Iterates between points.
|
|
24
30
|
* Inspired by: https://observablehq.com/@mbostock/top-100-cities
|
|
25
31
|
*/
|
|
26
|
-
export const useTour = (
|
|
32
|
+
export const useTour = (
|
|
33
|
+
controller?: GlobeController | null,
|
|
34
|
+
points?: LatLng[],
|
|
35
|
+
options: TourOptions = {},
|
|
36
|
+
): [boolean, Dispatch<SetStateAction<boolean>>] => {
|
|
27
37
|
const selection = d3.selection();
|
|
28
|
-
const [running, setRunning] = useState(false);
|
|
38
|
+
const [running, setRunning] = useState(options.running ?? false);
|
|
29
39
|
useEffect(() => {
|
|
30
40
|
if (!running) {
|
|
31
41
|
selection.interrupt(TRANSITION_NAME);
|
|
@@ -39,10 +49,15 @@ export const useTour = (controller?: GlobeController | null, features?: Features
|
|
|
39
49
|
const context = canvas.getContext('2d', { alpha: false });
|
|
40
50
|
const path = d3.geoPath(projection, context).pointRadius(2);
|
|
41
51
|
|
|
42
|
-
const tilt = 0;
|
|
52
|
+
const tilt = options.tilt ?? 0;
|
|
43
53
|
let last: LatLng;
|
|
44
54
|
try {
|
|
45
|
-
|
|
55
|
+
const p = [...points];
|
|
56
|
+
if (options.loop) {
|
|
57
|
+
p.push(p[0]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const next of p) {
|
|
46
61
|
if (!running) {
|
|
47
62
|
break;
|
|
48
63
|
}
|
|
@@ -83,8 +98,10 @@ export const useTour = (controller?: GlobeController | null, features?: Features
|
|
|
83
98
|
context.restore();
|
|
84
99
|
|
|
85
100
|
// TODO(burdon): This has to come after rendering above. Add to features to correct order?
|
|
86
|
-
|
|
87
|
-
|
|
101
|
+
if (options.autoRotate) {
|
|
102
|
+
projection.rotate(iv(t));
|
|
103
|
+
setRotation(projection.rotate());
|
|
104
|
+
}
|
|
88
105
|
});
|
|
89
106
|
|
|
90
107
|
// Throws if interrupted.
|
|
@@ -92,6 +109,8 @@ export const useTour = (controller?: GlobeController | null, features?: Features
|
|
|
92
109
|
last = next;
|
|
93
110
|
}
|
|
94
111
|
} catch (err) {
|
|
112
|
+
log.catch(err);
|
|
113
|
+
} finally {
|
|
95
114
|
setRunning(false);
|
|
96
115
|
}
|
|
97
116
|
});
|
|
@@ -101,14 +120,7 @@ export const useTour = (controller?: GlobeController | null, features?: Features
|
|
|
101
120
|
selection.interrupt(TRANSITION_NAME);
|
|
102
121
|
};
|
|
103
122
|
}
|
|
104
|
-
}, [controller, running]);
|
|
105
|
-
|
|
106
|
-
return [
|
|
107
|
-
() => {
|
|
108
|
-
if (!options.disabled) {
|
|
109
|
-
setRunning(true);
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
() => setRunning(false),
|
|
113
|
-
];
|
|
123
|
+
}, [controller, running, JSON.stringify(options)]);
|
|
124
|
+
|
|
125
|
+
return [running, setRunning];
|
|
114
126
|
};
|