@dxos/react-ui-geo 0.7.5-main.e9bb01b → 0.7.5-staging.2ff1350
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 +87 -35
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +91 -39
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +87 -35
- 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 +4 -4
- 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/hooks/context.d.ts +2 -2
- package/dist/types/src/hooks/context.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 +15 -14
- package/src/components/Globe/Globe.stories.tsx +12 -22
- package/src/components/Globe/Globe.tsx +56 -32
- package/src/components/Map/Map.stories.tsx +28 -6
- package/src/components/Map/Map.tsx +17 -3
- package/src/hooks/context.tsx +5 -5
- package/src/util/debug.ts +1 -0
- package/src/util/render.ts +18 -4
|
@@ -11,29 +11,51 @@ import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
|
11
11
|
|
|
12
12
|
import { Map, type MapController } from './Map';
|
|
13
13
|
import { useMapZoomHandler } from '../../hooks';
|
|
14
|
+
import { type MapMarker } from '../../types';
|
|
14
15
|
|
|
15
|
-
const Render = () => {
|
|
16
|
+
const Render = ({ markers }) => {
|
|
16
17
|
const [controller, setController] = useState<MapController>();
|
|
17
18
|
const handleZoomAction = useMapZoomHandler(controller);
|
|
18
19
|
|
|
19
20
|
return (
|
|
20
21
|
<Map.Root>
|
|
21
|
-
<Map.Canvas ref={setController} />
|
|
22
|
+
<Map.Canvas ref={setController} markers={markers} />
|
|
22
23
|
<Map.Zoom position='bottomleft' onAction={handleZoomAction} />
|
|
23
24
|
<Map.Action position='bottomright' />
|
|
24
25
|
</Map.Root>
|
|
25
26
|
);
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
const meta: Meta = {
|
|
29
|
+
const meta: Meta<typeof Render> = {
|
|
29
30
|
title: 'ui/react-ui-geo/Map',
|
|
30
|
-
component:
|
|
31
|
-
render: Render,
|
|
31
|
+
component: Render,
|
|
32
32
|
decorators: [withTheme, withLayout({ fullscreen: true, tooltips: true })],
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export default meta;
|
|
36
36
|
|
|
37
|
-
type Story = StoryObj
|
|
37
|
+
type Story = StoryObj<typeof Render>;
|
|
38
38
|
|
|
39
39
|
export const Default: Story = {};
|
|
40
|
+
|
|
41
|
+
export const WithMarkers: Story = {
|
|
42
|
+
args: {
|
|
43
|
+
markers: [
|
|
44
|
+
{ id: 'tokyo', title: 'Tokyo', location: { lat: 35.6762, lng: 139.6503 } },
|
|
45
|
+
{ id: 'sydney', title: 'Sydney', location: { lat: -33.8688, lng: 151.2093 } },
|
|
46
|
+
{ id: 'auckland', title: 'Auckland', location: { lat: -36.8509, lng: 174.7645 } },
|
|
47
|
+
{ id: 'new-delhi', title: 'New Delhi', location: { lat: 28.6139, lng: 77.209 } },
|
|
48
|
+
{ id: 'manila', title: 'Manila', location: { lat: 14.5995, lng: 120.9842 } },
|
|
49
|
+
{ id: 'beijing', title: 'Beijing', location: { lat: 39.9042, lng: 116.4074 } },
|
|
50
|
+
{ id: 'seoul', title: 'Seoul', location: { lat: 37.5665, lng: 126.978 } },
|
|
51
|
+
{ id: 'bangkok', title: 'Bangkok', location: { lat: 13.7563, lng: 100.5018 } },
|
|
52
|
+
{ id: 'singapore', title: 'Singapore', location: { lat: 1.3521, lng: 103.8198 } },
|
|
53
|
+
{ id: 'kuala-lumpur', title: 'Kuala Lumpur', location: { lat: 3.139, lng: 101.6869 } },
|
|
54
|
+
{ id: 'jakarta', title: 'Jakarta', location: { lat: -6.2088, lng: 106.8456 } },
|
|
55
|
+
{ id: 'hanoi', title: 'Hanoi', location: { lat: 21.0285, lng: 105.8542 } },
|
|
56
|
+
{ id: 'phnom-penh', title: 'Phnom Penh', location: { lat: 11.5564, lng: 104.9282 } },
|
|
57
|
+
{ id: 'vientiane', title: 'Vientiane', location: { lat: 17.9757, lng: 102.6331 } },
|
|
58
|
+
{ id: 'yangon', title: 'Yangon', location: { lat: 16.8661, lng: 96.1951 } },
|
|
59
|
+
] as MapMarker[],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// eslint-disable-next-line no-restricted-imports
|
|
6
6
|
import 'leaflet/dist/leaflet.css';
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import L from 'leaflet';
|
|
9
9
|
import { type ControlPosition, Control, DomEvent, DomUtil, type LatLngExpression, latLngBounds } from 'leaflet';
|
|
10
10
|
import React, { forwardRef, type PropsWithChildren, useEffect, useImperativeHandle } from 'react';
|
|
11
11
|
import { createRoot } from 'react-dom/client';
|
|
@@ -127,10 +127,24 @@ const MapCanvas = forwardRef<MapController, MapCanvasProps>(
|
|
|
127
127
|
/>
|
|
128
128
|
|
|
129
129
|
{/* Markers. */}
|
|
130
|
-
{/* TODO(burdon): Marker icon doesn't load on mobile? */}
|
|
131
130
|
{markers.map(({ id, title, location: { lat, lng } }) => {
|
|
132
131
|
return (
|
|
133
|
-
<Marker
|
|
132
|
+
<Marker
|
|
133
|
+
key={id}
|
|
134
|
+
position={{ lat, lng }}
|
|
135
|
+
icon={
|
|
136
|
+
// TODO(burdon): Create custom icon from bundled assets.
|
|
137
|
+
new L.Icon({
|
|
138
|
+
iconUrl: 'https://dxos.network/marker-icon.png',
|
|
139
|
+
iconRetinaUrl: 'https://dxos.network/marker-icon-2x.png',
|
|
140
|
+
shadowUrl: 'https://dxos.network/marker-shadow.png',
|
|
141
|
+
iconSize: [25, 41],
|
|
142
|
+
iconAnchor: [12, 41],
|
|
143
|
+
popupAnchor: [1, -34],
|
|
144
|
+
shadowSize: [41, 41],
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
>
|
|
134
148
|
{title && <Popup>{title}</Popup>}
|
|
135
149
|
</Marker>
|
|
136
150
|
);
|
package/src/hooks/context.tsx
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React, { createContext, type Dispatch, type PropsWithChildren, type SetStateAction, useContext } from 'react';
|
|
6
6
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
|
-
import {
|
|
8
|
+
import { useControlledState } from '@dxos/react-ui';
|
|
9
9
|
|
|
10
10
|
import { type LatLng } from '../util';
|
|
11
11
|
|
|
@@ -40,10 +40,10 @@ export const GlobeContextProvider = ({
|
|
|
40
40
|
translation: _translation,
|
|
41
41
|
rotation: _rotation,
|
|
42
42
|
}: GlobeContextProviderProps) => {
|
|
43
|
-
const [center, setCenter] =
|
|
44
|
-
const [scale, setScale] =
|
|
45
|
-
const [translation, setTranslation] =
|
|
46
|
-
const [rotation, setRotation] =
|
|
43
|
+
const [center, setCenter] = useControlledState(_center);
|
|
44
|
+
const [scale, setScale] = useControlledState(_scale);
|
|
45
|
+
const [translation, setTranslation] = useControlledState<Point>(_translation);
|
|
46
|
+
const [rotation, setRotation] = useControlledState<Vector>(_rotation);
|
|
47
47
|
|
|
48
48
|
return (
|
|
49
49
|
<GlobeContext.Provider
|
package/src/util/debug.ts
CHANGED
package/src/util/render.ts
CHANGED
|
@@ -11,7 +11,17 @@ import { type LatLng, geoLine, geoPoint } from './path';
|
|
|
11
11
|
|
|
12
12
|
export type Styles = Record<string, any>;
|
|
13
13
|
|
|
14
|
-
export type Style =
|
|
14
|
+
export type Style =
|
|
15
|
+
| 'background'
|
|
16
|
+
| 'water'
|
|
17
|
+
| 'graticule'
|
|
18
|
+
| 'land'
|
|
19
|
+
| 'border'
|
|
20
|
+
| 'dots'
|
|
21
|
+
| 'point'
|
|
22
|
+
| 'line'
|
|
23
|
+
| 'cursor'
|
|
24
|
+
| 'arc';
|
|
15
25
|
|
|
16
26
|
export type StyleSet = Partial<Record<Style, Styles>>;
|
|
17
27
|
|
|
@@ -108,16 +118,20 @@ export const createLayers = (topology: Topology, features: Features, styles: Sty
|
|
|
108
118
|
/**
|
|
109
119
|
* Render layers created above.
|
|
110
120
|
*/
|
|
111
|
-
export const renderLayers = (generator: GeoPath, layers: Layer[] = [], scale: number) => {
|
|
121
|
+
export const renderLayers = (generator: GeoPath, layers: Layer[] = [], scale: number, styles: StyleSet) => {
|
|
112
122
|
const context: CanvasRenderingContext2D = generator.context();
|
|
113
123
|
const {
|
|
114
124
|
canvas: { width, height },
|
|
115
125
|
} = context;
|
|
116
126
|
context.reset();
|
|
117
127
|
|
|
118
|
-
// TODO(burdon): Option.
|
|
119
128
|
// Clear background.
|
|
120
|
-
|
|
129
|
+
if (styles.background) {
|
|
130
|
+
context.fillStyle = styles.background.fillStyle;
|
|
131
|
+
context.fillRect(0, 0, width, height);
|
|
132
|
+
} else {
|
|
133
|
+
context.clearRect(0, 0, width, height);
|
|
134
|
+
}
|
|
121
135
|
|
|
122
136
|
// Render features.
|
|
123
137
|
// https://github.com/d3/d3-geo#_path
|