@dxos/react-ui-geo 0.8.4-main.bc674ce → 0.8.4-main.bd9b33e6c8
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 +104 -96
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +104 -96
- 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 +9 -3
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +10 -4
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.d.ts +14 -4
- package/dist/types/src/components/Map/Map.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/context.d.ts +1 -3
- package/dist/types/src/hooks/context.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -11
- package/src/components/Globe/Globe.stories.tsx +8 -8
- package/src/components/Globe/Globe.tsx +52 -26
- package/src/components/Map/Map.stories.tsx +9 -7
- package/src/components/Map/Map.tsx +70 -29
- package/src/hooks/context.tsx +5 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-geo",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.bd9b33e6c8",
|
|
4
4
|
"description": "Geo components.",
|
|
5
5
|
"homepage": "https://github.com/dxos",
|
|
6
6
|
"bugs": "https://github.com/dxos/issues",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"src"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@radix-ui/react-compose-refs": "1.1.1",
|
|
43
44
|
"@radix-ui/react-context": "1.1.1",
|
|
44
45
|
"d3": "^7.9.0",
|
|
45
46
|
"d3-geo-projection": "^4.0.0",
|
|
@@ -52,11 +53,11 @@
|
|
|
52
53
|
"topojson-client": "^3.1.0",
|
|
53
54
|
"topojson-simplify": "^3.0.3",
|
|
54
55
|
"versor": "^0.2.0",
|
|
55
|
-
"@dxos/async": "0.8.4-main.
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/node-std": "0.8.4-main.
|
|
59
|
-
"@dxos/util": "0.8.4-main.
|
|
56
|
+
"@dxos/async": "0.8.4-main.bd9b33e6c8",
|
|
57
|
+
"@dxos/debug": "0.8.4-main.bd9b33e6c8",
|
|
58
|
+
"@dxos/log": "0.8.4-main.bd9b33e6c8",
|
|
59
|
+
"@dxos/node-std": "0.8.4-main.bd9b33e6c8",
|
|
60
|
+
"@dxos/util": "0.8.4-main.bd9b33e6c8"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@react-three/drei": "^10.7.7",
|
|
@@ -76,15 +77,15 @@
|
|
|
76
77
|
"react": "~19.2.3",
|
|
77
78
|
"react-dom": "~19.2.3",
|
|
78
79
|
"three": "^0.178.0",
|
|
79
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
80
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
81
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
80
|
+
"@dxos/react-ui": "0.8.4-main.bd9b33e6c8",
|
|
81
|
+
"@dxos/storybook-utils": "0.8.4-main.bd9b33e6c8",
|
|
82
|
+
"@dxos/ui-theme": "0.8.4-main.bd9b33e6c8"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
85
|
"react": "~19.2.3",
|
|
85
86
|
"react-dom": "~19.2.3",
|
|
86
|
-
"@dxos/
|
|
87
|
-
"@dxos/ui
|
|
87
|
+
"@dxos/ui-theme": "0.8.4-main.bd9b33e6c8",
|
|
88
|
+
"@dxos/react-ui": "0.8.4-main.bd9b33e6c8"
|
|
88
89
|
},
|
|
89
90
|
"publishConfig": {
|
|
90
91
|
"access": "public"
|
|
@@ -9,7 +9,7 @@ import React, { useMemo, useRef, useState } from 'react';
|
|
|
9
9
|
import { type Topology } from 'topojson-specification';
|
|
10
10
|
|
|
11
11
|
import { useAsyncState } from '@dxos/react-ui';
|
|
12
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
12
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
13
13
|
|
|
14
14
|
import { type Vector, useDrag, useGlobeZoomHandler, useSpinner, useTour } from '../../hooks';
|
|
15
15
|
import { type LatLngLiteral } from '../../types';
|
|
@@ -128,7 +128,7 @@ const createTrip = (
|
|
|
128
128
|
);
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
type
|
|
131
|
+
type DefaultStoryProps = Pick<GlobeRootProps, 'zoom' | 'translation' | 'rotation'> &
|
|
132
132
|
Pick<GlobeCanvasProps, 'projection' | 'styles'> & {
|
|
133
133
|
drag?: boolean;
|
|
134
134
|
spin?: boolean;
|
|
@@ -137,7 +137,7 @@ type StoryProps = Pick<GlobeRootProps, 'zoom' | 'translation' | 'rotation'> &
|
|
|
137
137
|
};
|
|
138
138
|
|
|
139
139
|
const DefaultStory = ({
|
|
140
|
-
zoom:
|
|
140
|
+
zoom: zoomProp = 1,
|
|
141
141
|
translation,
|
|
142
142
|
rotation = [0, 0, 0],
|
|
143
143
|
projection,
|
|
@@ -146,7 +146,7 @@ const DefaultStory = ({
|
|
|
146
146
|
spin = false,
|
|
147
147
|
tour = false,
|
|
148
148
|
xAxis = false,
|
|
149
|
-
}:
|
|
149
|
+
}: DefaultStoryProps) => {
|
|
150
150
|
const controller = useRef<GlobeController>(null);
|
|
151
151
|
const [dots] = useAsyncState(async () => {
|
|
152
152
|
const points = (await import('../../../data/countries-dots-3.ts')).default;
|
|
@@ -203,18 +203,18 @@ const DefaultStory = ({
|
|
|
203
203
|
};
|
|
204
204
|
|
|
205
205
|
return (
|
|
206
|
-
<Globe.Root
|
|
206
|
+
<Globe.Root zoom={zoomProp} translation={translation} rotation={rotation}>
|
|
207
207
|
<Globe.Canvas
|
|
208
|
-
ref={controller}
|
|
209
208
|
topology={styles?.dots ? dots : topology}
|
|
210
209
|
projection={projection}
|
|
211
210
|
styles={styles}
|
|
212
211
|
features={tour ? { points: features?.points ?? [] } : features}
|
|
212
|
+
ref={controller}
|
|
213
213
|
/>
|
|
214
214
|
<Globe.Zoom onAction={handleAction} />
|
|
215
215
|
<Globe.Action onAction={handleAction} />
|
|
216
216
|
<Globe.Debug />
|
|
217
|
-
<Globe.Panel position='topright' classNames='
|
|
217
|
+
<Globe.Panel position='topright' classNames='w-20 h-20'>
|
|
218
218
|
<Leva />
|
|
219
219
|
</Globe.Panel>
|
|
220
220
|
</Globe.Root>
|
|
@@ -227,7 +227,7 @@ const meta = {
|
|
|
227
227
|
title: 'ui/react-ui-geo/Globe',
|
|
228
228
|
component: Globe.Root,
|
|
229
229
|
render: DefaultStory,
|
|
230
|
-
decorators: [withTheme],
|
|
230
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
231
231
|
parameters: {
|
|
232
232
|
layout: 'fullscreen',
|
|
233
233
|
},
|
|
@@ -26,15 +26,17 @@ import React, {
|
|
|
26
26
|
import { useResizeDetector } from 'react-resize-detector';
|
|
27
27
|
import { type Topology } from 'topojson-specification';
|
|
28
28
|
|
|
29
|
-
import { type ThemeMode, type ThemedClassName, useDynamicRef, useThemeContext } from '@dxos/react-ui';
|
|
30
|
-
import { mx } from '@dxos/ui-theme';
|
|
31
|
-
|
|
32
29
|
import {
|
|
33
|
-
|
|
34
|
-
type
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
type ThemeMode,
|
|
31
|
+
type ThemedClassName,
|
|
32
|
+
useComposedRefs,
|
|
33
|
+
useControlledState,
|
|
34
|
+
useDynamicRef,
|
|
35
|
+
useThemeContext,
|
|
36
|
+
} from '@dxos/react-ui';
|
|
37
|
+
import { composable, composableProps, mx } from '@dxos/ui-theme';
|
|
38
|
+
|
|
39
|
+
import { GlobeContext, type GlobeContextType, type Point, type Vector, useGlobeContext } from '../../hooks';
|
|
38
40
|
import {
|
|
39
41
|
type Features,
|
|
40
42
|
type StyleSet,
|
|
@@ -126,19 +128,43 @@ const getProjection = (type: GlobeCanvasProps['projection'] = 'orthographic'): G
|
|
|
126
128
|
// Root
|
|
127
129
|
//
|
|
128
130
|
|
|
129
|
-
type GlobeRootProps =
|
|
130
|
-
|
|
131
|
-
const GlobeRoot =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
type GlobeRootProps = Partial<Pick<GlobeContextType, 'center' | 'zoom' | 'translation' | 'rotation'>>;
|
|
132
|
+
|
|
133
|
+
const GlobeRoot = composable<HTMLDivElement, GlobeRootProps>(
|
|
134
|
+
(
|
|
135
|
+
{ children, center: centerProp, zoom: zoomProp, translation: translationProp, rotation: rotationProp, ...props },
|
|
136
|
+
forwardedRef,
|
|
137
|
+
) => {
|
|
138
|
+
const localRef = useRef<HTMLDivElement>(null);
|
|
139
|
+
const composedRef = useComposedRefs<HTMLDivElement>(localRef, forwardedRef);
|
|
140
|
+
const { width, height } = useResizeDetector<HTMLDivElement>({ targetRef: localRef });
|
|
141
|
+
|
|
142
|
+
const [center, setCenter] = useControlledState(centerProp);
|
|
143
|
+
const [zoom, setZoom] = useControlledState(zoomProp ?? 4);
|
|
144
|
+
const [translation, setTranslation] = useControlledState<Point>(translationProp);
|
|
145
|
+
const [rotation, setRotation] = useControlledState<Vector>(rotationProp);
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<GlobeContext.Provider
|
|
149
|
+
value={{
|
|
150
|
+
size: { width, height },
|
|
151
|
+
center,
|
|
152
|
+
zoom,
|
|
153
|
+
translation,
|
|
154
|
+
rotation,
|
|
155
|
+
setCenter,
|
|
156
|
+
setZoom,
|
|
157
|
+
setTranslation,
|
|
158
|
+
setRotation,
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
<div {...composableProps(props, { classNames: 'relative dx-container' })} ref={composedRef}>
|
|
162
|
+
{children}
|
|
163
|
+
</div>
|
|
164
|
+
</GlobeContext.Provider>
|
|
165
|
+
);
|
|
166
|
+
},
|
|
167
|
+
);
|
|
142
168
|
|
|
143
169
|
//
|
|
144
170
|
// Canvas
|
|
@@ -200,9 +226,9 @@ const GlobeCanvas = forwardRef<GlobeController, GlobeCanvasProps>(
|
|
|
200
226
|
translation,
|
|
201
227
|
rotation,
|
|
202
228
|
setCenter,
|
|
203
|
-
setZoom: (
|
|
204
|
-
if (typeof
|
|
205
|
-
const is = interpolateNumber(zoomRef.current,
|
|
229
|
+
setZoom: (state) => {
|
|
230
|
+
if (typeof state === 'function') {
|
|
231
|
+
const is = interpolateNumber(zoomRef.current, state(zoomRef.current));
|
|
206
232
|
// Stop easing if already zooming.
|
|
207
233
|
transition()
|
|
208
234
|
.ease(zooming.current ? easeLinear : easeSinOut)
|
|
@@ -212,7 +238,7 @@ const GlobeCanvas = forwardRef<GlobeController, GlobeCanvasProps>(
|
|
|
212
238
|
zooming.current = false;
|
|
213
239
|
});
|
|
214
240
|
} else {
|
|
215
|
-
setZoom(
|
|
241
|
+
setZoom(state);
|
|
216
242
|
}
|
|
217
243
|
},
|
|
218
244
|
setTranslation,
|
|
@@ -259,7 +285,7 @@ const GlobeDebug = ({ position = 'topleft' }: { position?: ControlPosition }) =>
|
|
|
259
285
|
return (
|
|
260
286
|
<div
|
|
261
287
|
className={mx(
|
|
262
|
-
'z-10 absolute
|
|
288
|
+
'z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded-sm',
|
|
263
289
|
controlPositions[position],
|
|
264
290
|
)}
|
|
265
291
|
>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
8
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
9
9
|
|
|
10
10
|
import { useMapZoomHandler } from '../../hooks';
|
|
11
11
|
import { type GeoMarker } from '../../types';
|
|
@@ -17,11 +17,13 @@ const DefaultStory = ({ markers = [] }: { markers?: GeoMarker[] }) => {
|
|
|
17
17
|
const handleZoomAction = useMapZoomHandler(controller);
|
|
18
18
|
|
|
19
19
|
return (
|
|
20
|
-
<Map.Root
|
|
21
|
-
<Map.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
<Map.Root>
|
|
21
|
+
<Map.Content ref={setController}>
|
|
22
|
+
<Map.Tiles />
|
|
23
|
+
<Map.Markers markers={markers} />
|
|
24
|
+
<Map.Zoom position='bottomleft' onAction={handleZoomAction} />
|
|
25
|
+
<Map.Action position='bottomright' />
|
|
26
|
+
</Map.Content>
|
|
25
27
|
</Map.Root>
|
|
26
28
|
);
|
|
27
29
|
};
|
|
@@ -30,7 +32,7 @@ const meta = {
|
|
|
30
32
|
title: 'ui/react-ui-geo/Map',
|
|
31
33
|
component: Map.Root as any,
|
|
32
34
|
render: DefaultStory,
|
|
33
|
-
decorators: [withTheme],
|
|
35
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
34
36
|
parameters: {
|
|
35
37
|
layout: 'fullscreen',
|
|
36
38
|
},
|
|
@@ -6,12 +6,12 @@ import 'leaflet/dist/leaflet.css';
|
|
|
6
6
|
|
|
7
7
|
import { createContext } from '@radix-ui/react-context';
|
|
8
8
|
import L, { Control, type ControlPosition, DomEvent, DomUtil, type LatLngLiteral, latLngBounds } from 'leaflet';
|
|
9
|
-
import React, { type PropsWithChildren, forwardRef, useEffect, useImperativeHandle, useRef
|
|
9
|
+
import React, { type PropsWithChildren, forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
10
10
|
import { createRoot } from 'react-dom/client';
|
|
11
11
|
import { MapContainer, type MapContainerProps, Marker, Popup, TileLayer, useMap, useMapEvents } from 'react-leaflet';
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
import { defaultTx, mx } from '@dxos/ui-theme';
|
|
13
|
+
import { type ThemedClassName, ThemeProvider, Tooltip } from '@dxos/react-ui';
|
|
14
|
+
import { composable, composableProps, defaultTx, mx } from '@dxos/ui-theme';
|
|
15
15
|
|
|
16
16
|
import { type GeoMarker } from '../../types';
|
|
17
17
|
import { ActionControls, type ControlProps, ZoomControls, controlPositions } from '../Toolbar';
|
|
@@ -43,23 +43,54 @@ type MapContextValue = {
|
|
|
43
43
|
onChange?: (ev: { center: LatLngLiteral; zoom: number }) => void;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const [
|
|
46
|
+
const [MapContextProvider, useMapContext] = createContext<MapContextValue>('Map');
|
|
47
47
|
|
|
48
48
|
//
|
|
49
49
|
// Root
|
|
50
50
|
//
|
|
51
51
|
|
|
52
|
-
type MapRootProps =
|
|
52
|
+
type MapRootProps = Pick<MapContextValue, 'onChange'>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Context provider for the map. Must wrap Map.Content.
|
|
56
|
+
*/
|
|
57
|
+
const MapRoot = composable<HTMLDivElement, MapRootProps>(({ children, onChange, ...props }, forwardedRef) => {
|
|
58
|
+
// TODO(burdon): Use attention: const [attention, setAttention] = useState(false);
|
|
59
|
+
const attention = false;
|
|
60
|
+
return (
|
|
61
|
+
<MapContextProvider attention={attention} onChange={onChange}>
|
|
62
|
+
<div
|
|
63
|
+
{...composableProps(props, {
|
|
64
|
+
role: 'none',
|
|
65
|
+
classNames: 'dx-container grid dx-focus-ring-inset',
|
|
66
|
+
})}
|
|
67
|
+
ref={forwardedRef}
|
|
68
|
+
>
|
|
69
|
+
{children}
|
|
70
|
+
</div>
|
|
71
|
+
</MapContextProvider>
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
MapRoot.displayName = 'Map.Root';
|
|
76
|
+
|
|
77
|
+
//
|
|
78
|
+
// Content
|
|
79
|
+
//
|
|
80
|
+
|
|
81
|
+
type MapContentProps = ThemedClassName<Omit<MapContainerProps, 'children'> & PropsWithChildren>;
|
|
53
82
|
|
|
54
83
|
/**
|
|
55
84
|
* https://react-leaflet.js.org/docs/api-map
|
|
56
85
|
*/
|
|
57
|
-
const
|
|
86
|
+
const MAP_CONTENT_NAME = 'Map.Content';
|
|
87
|
+
|
|
88
|
+
const MapContent = forwardRef<MapController, MapContentProps>(
|
|
58
89
|
(
|
|
59
|
-
{ classNames, scrollWheelZoom = true, doubleClickZoom = true, touchZoom = true, center, zoom,
|
|
90
|
+
{ classNames, scrollWheelZoom = true, doubleClickZoom = true, touchZoom = true, center, zoom, children, ...props },
|
|
60
91
|
forwardedRef,
|
|
61
92
|
) => {
|
|
62
|
-
const
|
|
93
|
+
const { attention } = useMapContext(MAP_CONTENT_NAME);
|
|
63
94
|
const mapRef = useRef<L.Map>(null);
|
|
64
95
|
const map = mapRef.current;
|
|
65
96
|
|
|
@@ -92,37 +123,39 @@ const MapRoot = forwardRef<MapController, MapRootProps>(
|
|
|
92
123
|
}, [map, attention]);
|
|
93
124
|
|
|
94
125
|
return (
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
</
|
|
126
|
+
<MapContainer
|
|
127
|
+
{...props}
|
|
128
|
+
className={mx('group relative grid bg-base-surface!', classNames)}
|
|
129
|
+
attributionControl={false}
|
|
130
|
+
zoomControl={false}
|
|
131
|
+
scrollWheelZoom={scrollWheelZoom}
|
|
132
|
+
doubleClickZoom={doubleClickZoom}
|
|
133
|
+
touchZoom={touchZoom}
|
|
134
|
+
center={center ?? defaults.center}
|
|
135
|
+
zoom={zoom ?? defaults.zoom}
|
|
136
|
+
whenReady={() => {}}
|
|
137
|
+
ref={mapRef}
|
|
138
|
+
>
|
|
139
|
+
{children}
|
|
140
|
+
</MapContainer>
|
|
110
141
|
);
|
|
111
142
|
},
|
|
112
143
|
);
|
|
113
144
|
|
|
114
|
-
|
|
145
|
+
MapContent.displayName = 'Map.Content';
|
|
115
146
|
|
|
116
147
|
//
|
|
117
148
|
// Tiles
|
|
118
149
|
// https://react-leaflet.js.org/docs/api-components/#tilelayer
|
|
119
150
|
//
|
|
120
151
|
|
|
152
|
+
const MAP_TILES_NAME = 'Map.Tiles';
|
|
153
|
+
|
|
121
154
|
type MapTilesProps = {};
|
|
122
155
|
|
|
123
156
|
const MapTiles = (_props: MapTilesProps) => {
|
|
124
157
|
const ref = useRef<L.TileLayer>(null);
|
|
125
|
-
const { onChange } = useMapContext(
|
|
158
|
+
const { onChange } = useMapContext(MAP_TILES_NAME);
|
|
126
159
|
|
|
127
160
|
useMapEvents({
|
|
128
161
|
zoomstart: (ev) => {
|
|
@@ -135,7 +168,7 @@ const MapTiles = (_props: MapTilesProps) => {
|
|
|
135
168
|
|
|
136
169
|
// NOTE: Need to dynamically update data attribute since TileLayer doesn't update, but
|
|
137
170
|
// Tailwind requires setting the property for static analysis.
|
|
138
|
-
const { attention } = useMapContext(
|
|
171
|
+
const { attention } = useMapContext(MAP_TILES_NAME);
|
|
139
172
|
useEffect(() => {
|
|
140
173
|
if (ref.current) {
|
|
141
174
|
ref.current.getContainer().dataset.attention = attention ? '1' : '0';
|
|
@@ -176,7 +209,7 @@ const MapTiles = (_props: MapTilesProps) => {
|
|
|
176
209
|
);
|
|
177
210
|
};
|
|
178
211
|
|
|
179
|
-
MapTiles.displayName =
|
|
212
|
+
MapTiles.displayName = MAP_TILES_NAME;
|
|
180
213
|
|
|
181
214
|
//
|
|
182
215
|
// Markers
|
|
@@ -247,7 +280,7 @@ const CustomControl = ({
|
|
|
247
280
|
useEffect(() => {
|
|
248
281
|
const control = new Control({ position });
|
|
249
282
|
control.onAdd = () => {
|
|
250
|
-
const container = DomUtil.create('div', mx('
|
|
283
|
+
const container = DomUtil.create('div', mx('m-0!', controlPositions[position]));
|
|
251
284
|
DomEvent.disableClickPropagation(container);
|
|
252
285
|
DomEvent.disableScrollPropagation(container);
|
|
253
286
|
|
|
@@ -290,10 +323,18 @@ const MapAction = ({ onAction, position = 'bottomright', ...props }: MapControlP
|
|
|
290
323
|
|
|
291
324
|
export const Map = {
|
|
292
325
|
Root: MapRoot,
|
|
326
|
+
Content: MapContent,
|
|
293
327
|
Tiles: MapTiles,
|
|
294
328
|
Markers: MapMarkers,
|
|
295
329
|
Zoom: MapZoom,
|
|
296
330
|
Action: MapAction,
|
|
297
331
|
};
|
|
298
332
|
|
|
299
|
-
export {
|
|
333
|
+
export {
|
|
334
|
+
type MapController,
|
|
335
|
+
type MapRootProps,
|
|
336
|
+
type MapContentProps,
|
|
337
|
+
type MapTilesProps,
|
|
338
|
+
type MapMarkersProps,
|
|
339
|
+
type MapControlProps,
|
|
340
|
+
};
|
package/src/hooks/context.tsx
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { type Dispatch, type SetStateAction, createContext, useContext } from 'react';
|
|
6
6
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
|
-
import { useControlledState } from '@dxos/react-ui';
|
|
9
8
|
|
|
10
9
|
import { type LatLngLiteral } from '../types';
|
|
11
10
|
|
|
12
11
|
// TODO(burdon): Factor out common geometry types.
|
|
13
12
|
export type Size = { width: number; height: number };
|
|
13
|
+
|
|
14
14
|
export type Point = { x: number; y: number };
|
|
15
|
+
|
|
15
16
|
export type Vector = [number, number, number];
|
|
16
17
|
|
|
17
18
|
export type GlobeContextType = {
|
|
@@ -26,39 +27,9 @@ export type GlobeContextType = {
|
|
|
26
27
|
setRotation: Dispatch<SetStateAction<Vector>>;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
center: { lat: 51, lng: 0 } as LatLngLiteral,
|
|
31
|
-
zoom: 4,
|
|
32
|
-
} as const;
|
|
33
|
-
|
|
30
|
+
/** @internal */
|
|
34
31
|
// TODO(burdon): Replace with radix.
|
|
35
|
-
const GlobeContext = createContext<GlobeContextType>(undefined);
|
|
36
|
-
|
|
37
|
-
export type GlobeContextProviderProps = PropsWithChildren<
|
|
38
|
-
Partial<Pick<GlobeContextType, 'size' | 'center' | 'zoom' | 'translation' | 'rotation'>>
|
|
39
|
-
>;
|
|
40
|
-
|
|
41
|
-
export const GlobeContextProvider = ({
|
|
42
|
-
children,
|
|
43
|
-
size,
|
|
44
|
-
center: centerProp = defaults.center,
|
|
45
|
-
zoom: zoomProp = defaults.zoom,
|
|
46
|
-
translation: translationProp,
|
|
47
|
-
rotation: rotationProp,
|
|
48
|
-
}: GlobeContextProviderProps) => {
|
|
49
|
-
const [center, setCenter] = useControlledState(centerProp);
|
|
50
|
-
const [zoom, setZoom] = useControlledState(zoomProp);
|
|
51
|
-
const [translation, setTranslation] = useControlledState<Point>(translationProp);
|
|
52
|
-
const [rotation, setRotation] = useControlledState<Vector>(rotationProp);
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<GlobeContext.Provider
|
|
56
|
-
value={{ size, center, zoom, translation, rotation, setCenter, setZoom, setTranslation, setRotation }}
|
|
57
|
-
>
|
|
58
|
-
{children}
|
|
59
|
-
</GlobeContext.Provider>
|
|
60
|
-
);
|
|
61
|
-
};
|
|
32
|
+
export const GlobeContext = createContext<GlobeContextType>(undefined);
|
|
62
33
|
|
|
63
34
|
export const useGlobeContext = () => {
|
|
64
35
|
return useContext(GlobeContext) ?? raise(new Error('Missing GlobeContext'));
|