@dxos/react-ui-geo 0.8.3 → 0.8.4-main.1068cf700f
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/data/airports.ts +1 -1
- package/data/cities.ts +1 -1
- package/data/countries-110m.ts +1 -1
- package/data/countries-dots-3.ts +1 -1
- package/data/countries-dots-4.ts +1 -1
- package/dist/lib/browser/chunk-GMWLKTLN.mjs +9 -0
- package/dist/lib/browser/{countries-110m-WI4PCLDF.mjs → countries-110m-ZM3ZIEFS.mjs} +2 -2
- package/dist/lib/browser/countries-110m-ZM3ZIEFS.mjs.map +7 -0
- package/dist/lib/browser/data.mjs +1 -1
- package/dist/lib/browser/index.mjs +404 -458
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/{chunk-PIIEDZEU.mjs → chunk-JODBF4CC.mjs} +3 -3
- package/dist/lib/node-esm/{countries-110m-DQ4XRC4B.mjs → countries-110m-3SFASWVD.mjs} +2 -2
- package/dist/lib/node-esm/countries-110m-3SFASWVD.mjs.map +7 -0
- package/dist/lib/node-esm/data.mjs +1 -1
- package/dist/lib/node-esm/index.mjs +404 -458
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +25 -9
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.d.ts +28 -18
- package/dist/types/src/components/Map/Map.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.stories.d.ts +14 -8
- package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/context.d.ts +7 -7
- package/dist/types/src/hooks/context.d.ts.map +1 -1
- package/dist/types/src/hooks/useGlobeZoomHandler.d.ts +1 -1
- package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useMapZoomHandler.d.ts +1 -1
- package/dist/types/src/hooks/useMapZoomHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useSpinner.d.ts +1 -1
- package/dist/types/src/hooks/useSpinner.d.ts.map +1 -1
- package/dist/types/src/hooks/useTour.d.ts +4 -3
- package/dist/types/src/hooks/useTour.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +12 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +2 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util/path.d.ts +5 -8
- package/dist/types/src/util/path.d.ts.map +1 -1
- package/dist/types/src/util/render.d.ts +4 -4
- package/dist/types/src/util/render.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -23
- package/src/components/Globe/Globe.stories.tsx +85 -37
- package/src/components/Globe/Globe.tsx +80 -63
- package/src/components/Map/Map.stories.tsx +25 -14
- package/src/components/Map/Map.tsx +183 -96
- package/src/components/Toolbar/Controls.tsx +14 -20
- package/src/components/index.ts +0 -2
- package/src/hooks/context.tsx +22 -16
- package/src/hooks/useGlobeZoomHandler.ts +9 -3
- package/src/hooks/useMapZoomHandler.ts +1 -1
- package/src/hooks/useSpinner.ts +2 -1
- package/src/hooks/useTour.ts +10 -8
- package/src/index.ts +2 -1
- package/src/translations.ts +20 -0
- package/src/types.ts +3 -1
- package/src/util/inertia.ts +1 -1
- package/src/util/path.ts +5 -6
- package/src/util/render.ts +5 -3
- package/dist/lib/browser/chunk-ENCWOTYX.mjs +0 -9
- package/dist/lib/browser/countries-110m-WI4PCLDF.mjs.map +0 -7
- package/dist/lib/node/chunk-LAICG6L2.cjs +0 -40
- package/dist/lib/node/chunk-LAICG6L2.cjs.map +0 -7
- package/dist/lib/node/countries-110m-KQ5WAB2O.cjs +0 -37877
- package/dist/lib/node/countries-110m-KQ5WAB2O.cjs.map +0 -7
- package/dist/lib/node/data.cjs +0 -28
- package/dist/lib/node/data.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -1187
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node-esm/countries-110m-DQ4XRC4B.mjs.map +0 -7
- package/dist/types/src/components/types.d.ts +0 -15
- package/dist/types/src/components/types.d.ts.map +0 -1
- package/src/components/types.ts +0 -19
- /package/dist/lib/browser/{chunk-ENCWOTYX.mjs.map → chunk-GMWLKTLN.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-PIIEDZEU.mjs.map → chunk-JODBF4CC.mjs.map} +0 -0
package/src/hooks/useTour.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { type
|
|
5
|
+
import { selection as d3Selection, geoDistance, geoInterpolate, geoPath } from 'd3';
|
|
6
|
+
import { type Dispatch, type SetStateAction, useEffect, useMemo, useState } from 'react';
|
|
7
7
|
import versor from 'versor';
|
|
8
8
|
|
|
9
9
|
import type { GlobeController } from '../components';
|
|
10
|
-
import {
|
|
10
|
+
import { type LatLngLiteral } from '../types';
|
|
11
|
+
import { type StyleSet, geoToPosition, positionToRotation } from '../util';
|
|
11
12
|
|
|
12
13
|
const TRANSITION_NAME = 'globe-tour';
|
|
13
14
|
|
|
@@ -29,10 +30,11 @@ export type TourOptions = {
|
|
|
29
30
|
*/
|
|
30
31
|
export const useTour = (
|
|
31
32
|
controller?: GlobeController | null,
|
|
32
|
-
points?:
|
|
33
|
+
points?: LatLngLiteral[],
|
|
33
34
|
options: TourOptions = {},
|
|
34
35
|
): [boolean, Dispatch<SetStateAction<boolean>>] => {
|
|
35
36
|
const selection = useMemo(() => d3Selection(), []);
|
|
37
|
+
// TODO(burdon): Redo controlled state.
|
|
36
38
|
const [running, setRunning] = useState(options.running ?? false);
|
|
37
39
|
useEffect(() => {
|
|
38
40
|
if (!running) {
|
|
@@ -48,7 +50,7 @@ export const useTour = (
|
|
|
48
50
|
const path = geoPath(projection, context).pointRadius(2);
|
|
49
51
|
|
|
50
52
|
const tilt = options.tilt ?? 0;
|
|
51
|
-
let last:
|
|
53
|
+
let last: LatLngLiteral;
|
|
52
54
|
try {
|
|
53
55
|
const p = [...points];
|
|
54
56
|
if (options.loop) {
|
|
@@ -82,14 +84,14 @@ export const useTour = (
|
|
|
82
84
|
{
|
|
83
85
|
context.beginPath();
|
|
84
86
|
context.strokeStyle = options?.styles?.arc?.strokeStyle ?? 'yellow';
|
|
85
|
-
context.lineWidth = (options?.styles?.arc?.lineWidth ?? 1.5) * (controller?.
|
|
87
|
+
context.lineWidth = (options?.styles?.arc?.lineWidth ?? 1.5) * (controller?.zoom ?? 1);
|
|
86
88
|
context.setLineDash(options?.styles?.arc?.lineDash ?? []);
|
|
87
89
|
path({ type: 'LineString', coordinates: [ip(t1), ip(t2)] });
|
|
88
90
|
context.stroke();
|
|
89
91
|
|
|
90
92
|
context.beginPath();
|
|
91
93
|
context.fillStyle = options?.styles?.cursor?.fillStyle ?? 'orange';
|
|
92
|
-
path.pointRadius((options?.styles?.cursor?.pointRadius ?? 2) * (controller?.
|
|
94
|
+
path.pointRadius((options?.styles?.cursor?.pointRadius ?? 2) * (controller?.zoom ?? 1));
|
|
93
95
|
path({ type: 'Point', coordinates: ip(t2) });
|
|
94
96
|
context.fill();
|
|
95
97
|
}
|
|
@@ -104,7 +106,7 @@ export const useTour = (
|
|
|
104
106
|
await transition.end();
|
|
105
107
|
last = next;
|
|
106
108
|
}
|
|
107
|
-
} catch
|
|
109
|
+
} catch {
|
|
108
110
|
// Ignore.
|
|
109
111
|
} finally {
|
|
110
112
|
setRunning(false);
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Resource } from '@dxos/react-ui';
|
|
6
|
+
|
|
7
|
+
export const translationKey = '@dxos/react-ui-geo';
|
|
8
|
+
|
|
9
|
+
export const translations = [
|
|
10
|
+
{
|
|
11
|
+
'en-US': {
|
|
12
|
+
[translationKey]: {
|
|
13
|
+
'zoom in icon button': 'Zoom in',
|
|
14
|
+
'zoom out icon button': 'Zoom out',
|
|
15
|
+
'start icon button': 'Start',
|
|
16
|
+
'toggle icon button': 'Toggle',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
] as const satisfies Resource[];
|
package/src/types.ts
CHANGED
package/src/util/inertia.ts
CHANGED
package/src/util/path.ts
CHANGED
|
@@ -4,22 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
import { type GeoGeometryObjects, geoCircle as d3GeoCircle } from 'd3';
|
|
6
6
|
import { type Point, type Polygon, type Position } from 'geojson';
|
|
7
|
+
import { type LatLngLiteral } from 'leaflet';
|
|
7
8
|
|
|
8
9
|
import type { Vector } from '../hooks';
|
|
9
10
|
|
|
10
|
-
export type LatLng = { lat: number; lng: number };
|
|
11
|
-
|
|
12
11
|
export const positionToRotation = ([lng, lat]: [number, number], tilt = 0): Vector => [-lng, tilt - lat, 0];
|
|
13
12
|
|
|
14
|
-
export const geoToPosition = ({ lat, lng }:
|
|
13
|
+
export const geoToPosition = ({ lat, lng }: LatLngLiteral): [number, number] => [lng, lat];
|
|
15
14
|
|
|
16
|
-
export const geoPoint = (point:
|
|
15
|
+
export const geoPoint = (point: LatLngLiteral): Point => ({ type: 'Point', coordinates: geoToPosition(point) });
|
|
17
16
|
|
|
18
17
|
// https://github.com/d3/d3-geo#geoCircle
|
|
19
|
-
export const geoCircle = ({ lat, lng }:
|
|
18
|
+
export const geoCircle = ({ lat, lng }: LatLngLiteral, radius: number): Polygon =>
|
|
20
19
|
d3GeoCircle().radius(radius).center([lng, lat])();
|
|
21
20
|
|
|
22
|
-
export const geoLine = (p1:
|
|
21
|
+
export const geoLine = (p1: LatLngLiteral, p2: LatLngLiteral): GeoGeometryObjects => ({
|
|
23
22
|
type: 'LineString',
|
|
24
23
|
coordinates: [
|
|
25
24
|
[p1.lng, p1.lat],
|
package/src/util/render.ts
CHANGED
|
@@ -6,7 +6,9 @@ import { type GeoPath, type GeoPermissibleObjects, geoGraticule } from 'd3';
|
|
|
6
6
|
import { feature, mesh } from 'topojson-client';
|
|
7
7
|
import { type Topology } from 'topojson-specification';
|
|
8
8
|
|
|
9
|
-
import { type
|
|
9
|
+
import { type LatLngLiteral } from '../types';
|
|
10
|
+
|
|
11
|
+
import { geoLine, geoPoint } from './path';
|
|
10
12
|
|
|
11
13
|
export type Styles = Record<string, any>;
|
|
12
14
|
|
|
@@ -25,8 +27,8 @@ export type Style =
|
|
|
25
27
|
export type StyleSet = Partial<Record<Style, Styles>>;
|
|
26
28
|
|
|
27
29
|
export type Features = {
|
|
28
|
-
points?:
|
|
29
|
-
lines?: { source:
|
|
30
|
+
points?: LatLngLiteral[];
|
|
31
|
+
lines?: { source: LatLngLiteral; target: LatLngLiteral }[];
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
export type Layer = {
|