@dxos/react-ui-geo 0.7.5-labs.35b4b42

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.
Files changed (126) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +3 -0
  3. package/data/airports.ts +52524 -0
  4. package/data/cities.ts +1211 -0
  5. package/data/countries-110m.ts +10587 -0
  6. package/data/countries-dots-3.ts +42989 -0
  7. package/data/countries-dots-4.ts +300941 -0
  8. package/data/raw/airports.json +39386 -0
  9. package/data/raw/countries-10m.json +1 -0
  10. package/data/raw/countries-110m.json +1 -0
  11. package/data/raw/countries-50m.json +1 -0
  12. package/data/raw/countries.json +1 -0
  13. package/dist/lib/browser/chunk-ENCWOTYX.mjs +9 -0
  14. package/dist/lib/browser/chunk-ENCWOTYX.mjs.map +7 -0
  15. package/dist/lib/browser/countries-110m-WI4PCLDF.mjs +37859 -0
  16. package/dist/lib/browser/countries-110m-WI4PCLDF.mjs.map +7 -0
  17. package/dist/lib/browser/data.mjs +7 -0
  18. package/dist/lib/browser/data.mjs.map +7 -0
  19. package/dist/lib/browser/index.mjs +1020 -0
  20. package/dist/lib/browser/index.mjs.map +7 -0
  21. package/dist/lib/browser/meta.json +1 -0
  22. package/dist/lib/node/chunk-LAICG6L2.cjs +40 -0
  23. package/dist/lib/node/chunk-LAICG6L2.cjs.map +7 -0
  24. package/dist/lib/node/countries-110m-KQ5WAB2O.cjs +37877 -0
  25. package/dist/lib/node/countries-110m-KQ5WAB2O.cjs.map +7 -0
  26. package/dist/lib/node/data.cjs +28 -0
  27. package/dist/lib/node/data.cjs.map +7 -0
  28. package/dist/lib/node/index.cjs +1045 -0
  29. package/dist/lib/node/index.cjs.map +7 -0
  30. package/dist/lib/node/meta.json +1 -0
  31. package/dist/lib/node-esm/chunk-PIIEDZEU.mjs +11 -0
  32. package/dist/lib/node-esm/chunk-PIIEDZEU.mjs.map +7 -0
  33. package/dist/lib/node-esm/countries-110m-DQ4XRC4B.mjs +37861 -0
  34. package/dist/lib/node-esm/countries-110m-DQ4XRC4B.mjs.map +7 -0
  35. package/dist/lib/node-esm/data.mjs +8 -0
  36. package/dist/lib/node-esm/data.mjs.map +7 -0
  37. package/dist/lib/node-esm/index.mjs +1021 -0
  38. package/dist/lib/node-esm/index.mjs.map +7 -0
  39. package/dist/lib/node-esm/meta.json +1 -0
  40. package/dist/types/data/airports.d.ts +18 -0
  41. package/dist/types/data/airports.d.ts.map +1 -0
  42. package/dist/types/data/cities.d.ts +17 -0
  43. package/dist/types/data/cities.d.ts.map +1 -0
  44. package/dist/types/data/countries-110m.d.ts +36 -0
  45. package/dist/types/data/countries-110m.d.ts.map +1 -0
  46. package/dist/types/data/countries-dots-3.d.ts +9 -0
  47. package/dist/types/data/countries-dots-3.d.ts.map +1 -0
  48. package/dist/types/data/countries-dots-4.d.ts +9 -0
  49. package/dist/types/data/countries-dots-4.d.ts.map +1 -0
  50. package/dist/types/src/components/Globe/Globe.d.ts +37 -0
  51. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -0
  52. package/dist/types/src/components/Globe/Globe.stories.d.ts +15 -0
  53. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -0
  54. package/dist/types/src/components/Globe/index.d.ts +2 -0
  55. package/dist/types/src/components/Globe/index.d.ts.map +1 -0
  56. package/dist/types/src/components/Map/Map.d.ts +34 -0
  57. package/dist/types/src/components/Map/Map.d.ts.map +1 -0
  58. package/dist/types/src/components/Map/Map.stories.d.ts +7 -0
  59. package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -0
  60. package/dist/types/src/components/Map/index.d.ts +2 -0
  61. package/dist/types/src/components/Map/index.d.ts.map +1 -0
  62. package/dist/types/src/components/Toolbar/Controls.d.ts +11 -0
  63. package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -0
  64. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  65. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  66. package/dist/types/src/components/index.d.ts +5 -0
  67. package/dist/types/src/components/index.d.ts.map +1 -0
  68. package/dist/types/src/components/types.d.ts +14 -0
  69. package/dist/types/src/components/types.d.ts.map +1 -0
  70. package/dist/types/src/data.d.ts +3 -0
  71. package/dist/types/src/data.d.ts.map +1 -0
  72. package/dist/types/src/hooks/context.d.ts +26 -0
  73. package/dist/types/src/hooks/context.d.ts.map +1 -0
  74. package/dist/types/src/hooks/index.d.ts +7 -0
  75. package/dist/types/src/hooks/index.d.ts.map +1 -0
  76. package/dist/types/src/hooks/useDrag.d.ts +16 -0
  77. package/dist/types/src/hooks/useDrag.d.ts.map +1 -0
  78. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts +3 -0
  79. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -0
  80. package/dist/types/src/hooks/useMapZoomHandler.d.ts +3 -0
  81. package/dist/types/src/hooks/useMapZoomHandler.d.ts.map +1 -0
  82. package/dist/types/src/hooks/useSpinner.d.ts +11 -0
  83. package/dist/types/src/hooks/useSpinner.d.ts.map +1 -0
  84. package/dist/types/src/hooks/useTour.d.ts +13 -0
  85. package/dist/types/src/hooks/useTour.d.ts.map +1 -0
  86. package/dist/types/src/index.d.ts +6 -0
  87. package/dist/types/src/index.d.ts.map +1 -0
  88. package/dist/types/src/types.d.ts +7 -0
  89. package/dist/types/src/types.d.ts.map +1 -0
  90. package/dist/types/src/util/debug.d.ts +2 -0
  91. package/dist/types/src/util/debug.d.ts.map +1 -0
  92. package/dist/types/src/util/index.d.ts +5 -0
  93. package/dist/types/src/util/index.d.ts.map +1 -0
  94. package/dist/types/src/util/inertia.d.ts +16 -0
  95. package/dist/types/src/util/inertia.d.ts.map +1 -0
  96. package/dist/types/src/util/path.d.ts +15 -0
  97. package/dist/types/src/util/path.d.ts.map +1 -0
  98. package/dist/types/src/util/render.d.ts +26 -0
  99. package/dist/types/src/util/render.d.ts.map +1 -0
  100. package/dist/types/tsconfig.tsbuildinfo +1 -0
  101. package/package.json +83 -0
  102. package/src/components/Globe/Globe.stories.tsx +332 -0
  103. package/src/components/Globe/Globe.tsx +270 -0
  104. package/src/components/Globe/index.ts +5 -0
  105. package/src/components/Map/Map.stories.tsx +39 -0
  106. package/src/components/Map/Map.tsx +203 -0
  107. package/src/components/Map/index.ts +5 -0
  108. package/src/components/Toolbar/Controls.tsx +71 -0
  109. package/src/components/Toolbar/index.ts +5 -0
  110. package/src/components/index.ts +9 -0
  111. package/src/components/types.ts +18 -0
  112. package/src/data.ts +9 -0
  113. package/src/hooks/context.tsx +59 -0
  114. package/src/hooks/index.ts +10 -0
  115. package/src/hooks/useDrag.ts +55 -0
  116. package/src/hooks/useGlobeZoomHandler.ts +29 -0
  117. package/src/hooks/useMapZoomHandler.ts +29 -0
  118. package/src/hooks/useSpinner.ts +69 -0
  119. package/src/hooks/useTour.ts +114 -0
  120. package/src/index.ts +9 -0
  121. package/src/types.ts +11 -0
  122. package/src/util/debug.ts +16 -0
  123. package/src/util/index.ts +8 -0
  124. package/src/util/inertia.ts +197 -0
  125. package/src/util/path.ts +56 -0
  126. package/src/util/render.ts +149 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDrag.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDrag.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAGrD,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IAC/B,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CAC5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,gBAAiB,eAAe,GAAG,IAAI,YAAW,WAAW,SA2BhF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type GlobeController, type ControlProps } from '../components';
2
+ export declare const useGlobeZoomHandler: (controller: GlobeController | null | undefined) => ControlProps["onAction"];
3
+ //# sourceMappingURL=useGlobeZoomHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGlobeZoomHandler.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useGlobeZoomHandler.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,eAAO,MAAM,mBAAmB,eAAgB,eAAe,GAAG,IAAI,GAAG,SAAS,KAAG,YAAY,CAAC,UAAU,CAoB3G,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type MapController, type ControlProps } from '../components';
2
+ export declare const useMapZoomHandler: (controller: MapController | null | undefined) => ControlProps["onAction"];
3
+ //# sourceMappingURL=useMapZoomHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMapZoomHandler.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useMapZoomHandler.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAEtE,eAAO,MAAM,iBAAiB,eAAgB,aAAa,GAAG,IAAI,GAAG,SAAS,KAAG,YAAY,CAAC,UAAU,CAoBvG,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type Vector } from './context';
2
+ import { type GlobeController } from '../components';
3
+ export type SpinnerOptions = {
4
+ disabled?: boolean;
5
+ delta?: Vector;
6
+ };
7
+ /**
8
+ * Rotates globe.
9
+ */
10
+ export declare const useSpinner: (controller?: GlobeController | null, options?: SpinnerOptions) => (() => void)[];
11
+ //# sourceMappingURL=useSpinner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSpinner.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useSpinner.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,gBAAiB,eAAe,GAAG,IAAI,YAAW,cAAc,mBAiDtF,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { GlobeController } from '../components';
2
+ import { type Features, type StyleSet } from '../util';
3
+ export type TourOptions = {
4
+ disabled?: boolean;
5
+ styles?: StyleSet;
6
+ duration?: number;
7
+ };
8
+ /**
9
+ * Iterates between points.
10
+ * Inspired by: https://observablehq.com/@mbostock/top-100-cities
11
+ */
12
+ export declare const useTour: (controller?: GlobeController | null, features?: Features, options?: TourOptions) => (() => void)[];
13
+ //# sourceMappingURL=useTour.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTour.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTour.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,QAAQ,EAAkD,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAMvG,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,OAAO,gBAAiB,eAAe,GAAG,IAAI,aAAa,QAAQ,YAAW,WAAW,mBAwFrG,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './components';
2
+ export * from './data';
3
+ export * from './hooks';
4
+ export * from './types';
5
+ export * from './util';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type LatLngLiteral } from 'leaflet';
2
+ export type MapMarker = {
3
+ id: string;
4
+ title?: string;
5
+ location: LatLngLiteral;
6
+ };
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,aAAa,CAAC;CACzB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const timer: <T = void>(cb: () => T) => T;
2
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../../src/util/debug.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,KAAK,GAAI,CAAC,aAAa,MAAM,CAAC,KAAG,CAS7C,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './debug';
2
+ export * from './inertia';
3
+ export * from './path';
4
+ export * from './render';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/util/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,16 @@
1
+ import * as d3 from 'd3';
2
+ export declare const restrictAxis: (axis: boolean[]) => (original: number[], current: number[]) => number[];
3
+ /**
4
+ * Applies a drag handler to the specified target element.
5
+ */
6
+ export declare const geoInertiaDrag: (target: any, render: any, projection: any, options: any) => {
7
+ position: number[];
8
+ velocity: number[];
9
+ timer: d3.Timer;
10
+ time: number;
11
+ t: number;
12
+ start: (ev: any) => void;
13
+ move: (ev: any) => void;
14
+ end: (ev: any) => any;
15
+ };
16
+ //# sourceMappingURL=inertia.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inertia.d.ts","sourceRoot":"","sources":["../../../../src/util/inertia.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB,eAAO,MAAM,YAAY,SAChB,OAAO,EAAE,gBACL,MAAM,EAAE,WAAW,MAAM,EAAE,KAAG,MAAM,EACK,CAAC;AAEvD;;GAEG;AAEH,eAAO,MAAM,cAAc;;;;;;;;;CA+B1B,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type GeoGeometryObjects } from 'd3';
2
+ import { type Point, type Polygon, type Position } from 'geojson';
3
+ import type { Vector } from '../hooks';
4
+ export type LatLng = {
5
+ lat: number;
6
+ lng: number;
7
+ };
8
+ export declare const positionToRotation: ([lng, lat]: [number, number], tilt?: number) => Vector;
9
+ export declare const geoToPosition: ({ lat, lng }: LatLng) => [number, number];
10
+ export declare const geoPoint: (point: LatLng) => Point;
11
+ export declare const geoCircle: ({ lat, lng }: LatLng, radius: number) => Polygon;
12
+ export declare const geoLine: (p1: LatLng, p2: LatLng) => GeoGeometryObjects;
13
+ export declare const closestPoint: (points: Position[], target: Position) => Position | null;
14
+ export declare const getDistance: (point1: Position, point2: Position) => number;
15
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../../src/util/path.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,IAAI,CAAC;AAC7C,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAElE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAIlD,eAAO,MAAM,kBAAkB,eAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,oBAAa,MAA+B,CAAC;AAE5G,eAAO,MAAM,aAAa,iBAAkB,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAAe,CAAC;AAEpF,eAAO,MAAM,QAAQ,UAAW,MAAM,KAAG,KAA+D,CAAC;AAGzG,eAAO,MAAM,SAAS,iBAAkB,MAAM,UAAU,MAAM,KAAG,OACb,CAAC;AAErD,eAAO,MAAM,OAAO,OAAQ,MAAM,MAAM,MAAM,KAAG,kBAM/C,CAAC;AAEH,eAAO,MAAM,YAAY,WAAY,QAAQ,EAAE,UAAU,QAAQ,KAAG,QAAQ,GAAG,IAiB9E,CAAC;AAEF,eAAO,MAAM,WAAW,WAAY,QAAQ,UAAU,QAAQ,KAAG,MAIhE,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type GeoPath, type GeoPermissibleObjects } from 'd3';
2
+ import { type Topology } from 'topojson-specification';
3
+ import { type LatLng } from './path';
4
+ export type Styles = Record<string, any>;
5
+ export type Style = 'water' | 'graticule' | 'land' | 'border' | 'dots' | 'point' | 'line' | 'cursor' | 'arc';
6
+ export type StyleSet = Partial<Record<Style, Styles>>;
7
+ export type Features = {
8
+ points?: LatLng[];
9
+ lines?: {
10
+ source: LatLng;
11
+ target: LatLng;
12
+ }[];
13
+ };
14
+ export type Layer = {
15
+ styles: Styles;
16
+ path: GeoPermissibleObjects;
17
+ };
18
+ /**
19
+ * Create rendering layers.
20
+ */
21
+ export declare const createLayers: (topology: Topology, features: Features, styles: StyleSet) => Layer[];
22
+ /**
23
+ * Render layers created above.
24
+ */
25
+ export declare const renderLayers: (generator: GeoPath, layers: Layer[], scale: number) => CanvasRenderingContext2D;
26
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../../src/util/render.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,IAAI,CAAC;AAE9D,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,KAAK,MAAM,EAAqB,MAAM,QAAQ,CAAC;AAExD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEzC,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE7G,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtD,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,qBAAqB,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,aAAc,QAAQ,YAAY,QAAQ,UAAU,QAAQ,KAAG,KAAK,EA2E5F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,cAAe,OAAO,UAAU,KAAK,EAAE,SAAc,MAAM,6BAsCnF,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":"5.7.3"}
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "@dxos/react-ui-geo",
3
+ "version": "0.7.5-labs.35b4b42",
4
+ "description": "Geo components.",
5
+ "homepage": "https://github.com/dxos",
6
+ "bugs": "https://github.com/dxos/issues",
7
+ "license": "MIT",
8
+ "author": "DXOS.org",
9
+ "sideEffects": true,
10
+ "exports": {
11
+ "./data": {
12
+ "types": "./dist/types/src/data.d.ts",
13
+ "browser": "./dist/lib/browser/data.mjs",
14
+ "node": "./dist/lib/node-esm/data.mjs"
15
+ },
16
+ ".": {
17
+ "types": "./dist/types/src/index.d.ts",
18
+ "browser": "./dist/lib/browser/index.mjs",
19
+ "node": "./dist/lib/node-esm/index.mjs"
20
+ }
21
+ },
22
+ "types": "dist/types/src/index.d.ts",
23
+ "typesVersions": {
24
+ "*": {
25
+ "data": [
26
+ "dist/types/src/data.d.ts"
27
+ ]
28
+ }
29
+ },
30
+ "files": [
31
+ "data",
32
+ "dist",
33
+ "src"
34
+ ],
35
+ "dependencies": {
36
+ "d3": "^7.9.0",
37
+ "d3-geo-projection": "^4.0.0",
38
+ "d3-hexbin": "^0.2.2",
39
+ "geojson": "^0.5.0",
40
+ "leaflet": "^1.9.4",
41
+ "lodash.defaultsdeep": "^4.6.1",
42
+ "react-leaflet": "^4.2.1",
43
+ "react-resize-detector": "^11.0.1",
44
+ "topojson-client": "^3.1.0",
45
+ "topojson-simplify": "^3.0.3",
46
+ "versor": "^0.2.0",
47
+ "@dxos/async": "0.7.5-labs.35b4b42",
48
+ "@dxos/node-std": "0.7.5-labs.35b4b42",
49
+ "@dxos/debug": "0.7.5-labs.35b4b42",
50
+ "@dxos/util": "0.7.5-labs.35b4b42"
51
+ },
52
+ "devDependencies": {
53
+ "@react-three/drei": "^9.99.0",
54
+ "@react-three/fiber": "^8.15.0",
55
+ "@types/d3": "^7.4.3",
56
+ "@types/geojson": "^7946.0.14",
57
+ "@types/leaflet": "^1.9.16",
58
+ "@types/react": "~18.2.0",
59
+ "@types/react-dom": "~18.2.0",
60
+ "@types/three": "0.165.0",
61
+ "@types/topojson-client": "^3.1.4",
62
+ "@types/topojson-simplify": "^3.0.3",
63
+ "@types/topojson-specification": "^1.0.5",
64
+ "JSONStream": "^1.3.5",
65
+ "geojson2h3": "^1.2.0",
66
+ "leva": "^0.9.35",
67
+ "react": "~18.2.0",
68
+ "react-dom": "~18.2.0",
69
+ "three": "0.165.0",
70
+ "@dxos/react-ui": "0.7.5-labs.35b4b42",
71
+ "@dxos/react-ui-theme": "0.7.5-labs.35b4b42",
72
+ "@dxos/storybook-utils": "0.7.5-labs.35b4b42"
73
+ },
74
+ "peerDependencies": {
75
+ "react": "~18.2.0",
76
+ "react-dom": "~18.2.0",
77
+ "@dxos/react-ui-theme": "0.7.5-labs.35b4b42",
78
+ "@dxos/react-ui": "0.7.5-labs.35b4b42"
79
+ },
80
+ "publishConfig": {
81
+ "access": "public"
82
+ }
83
+ }
@@ -0,0 +1,332 @@
1
+ //
2
+ // Copyright 2018 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta } from '@storybook/react';
8
+ import { type FeatureCollection, type Geometry, type Position } from 'geojson';
9
+ import { Leva } from 'leva';
10
+ import React, { useMemo, useRef, useState } from 'react';
11
+ import { type Topology } from 'topojson-specification';
12
+
13
+ import { useAsyncState } from '@dxos/react-ui';
14
+ import { withTheme, withLayout } from '@dxos/storybook-utils';
15
+
16
+ import { Globe, type GlobeCanvasProps, type GlobeController, type GlobeRootProps } from './Globe';
17
+ import { useDrag, useGlobeZoomHandler, useSpinner, useTour, type Vector } from '../../hooks';
18
+ import { closestPoint, type LatLng, type StyleSet } from '../../util';
19
+ import { type ControlProps } from '../Toolbar';
20
+
21
+ // TODO(burdon): Local script (e.g., plot on chart) vs. remote functions.
22
+ // TODO(burdon): Add charts to sheet.
23
+ // TODO(burdon): Able to script (e.g., list of cities from named range).
24
+ // TODO(burdon): Search flight information. Calendar (itinerary).
25
+ // TODO(burdon): Show MANY packets flowing across the network.
26
+
27
+ const useImportJson = (filename: string) => {
28
+ return useAsyncState(
29
+ // TODO(burdon): Configure vite plugins for experimental syntax.
30
+ // @babel/plugin-syntax-import-assertions
31
+ // @babel/plugin-syntax-import-attributes
32
+ async () => await import(filename), // { assert: { type: 'json' } }),
33
+ );
34
+ };
35
+
36
+ const defaultStyles: StyleSet = {
37
+ water: {
38
+ fillStyle: '#0a0a0a',
39
+ },
40
+
41
+ land: {
42
+ fillStyle: '#050505',
43
+ strokeStyle: 'darkgreen',
44
+ },
45
+
46
+ graticule: {
47
+ strokeStyle: '#111',
48
+ },
49
+
50
+ line: {
51
+ lineWidth: 1,
52
+ lineDash: [4, 16],
53
+ strokeStyle: 'yellow',
54
+ },
55
+
56
+ point: {
57
+ pointRadius: 2,
58
+ fillStyle: 'red',
59
+ },
60
+
61
+ cursor: {
62
+ fillStyle: 'orange',
63
+ pointRadius: 2,
64
+ },
65
+
66
+ arc: {
67
+ lineWidth: 2,
68
+ strokeStyle: 'yellow',
69
+ },
70
+ };
71
+
72
+ const dotStyles: StyleSet = {
73
+ dots: {
74
+ fillStyle: '#444',
75
+ pointRadius: 2,
76
+ },
77
+
78
+ point: {
79
+ pointRadius: 2,
80
+ fillStyle: 'red',
81
+ },
82
+
83
+ cursor: {
84
+ fillStyle: 'orange',
85
+ pointRadius: 2,
86
+ },
87
+
88
+ arc: {
89
+ lineWidth: 2,
90
+ strokeStyle: 'yellow',
91
+ },
92
+ };
93
+
94
+ const routes: Record<string, string[]> = {
95
+ LAX: ['SFO', 'SEA'],
96
+ JFK: ['LAX', 'YYZ', 'TPA', 'CXH'],
97
+ CDG: ['BHX', 'BCN', 'VIE', 'WAW', 'CPH', 'ATH', 'IST', 'TXL', 'KBP', 'TLL'],
98
+ DXB: ['IKA'],
99
+ SIN: ['HND', 'SYD', 'HKG', 'BKK'],
100
+ };
101
+
102
+ // TODO(burdon): Make hierarchical/tree.
103
+ const createTrip = (
104
+ airports: FeatureCollection<Geometry & { coordinates: Position }, { iata: string }>,
105
+ routes: Record<string, string[]>,
106
+ points: Position[] = [],
107
+ ) => {
108
+ let previousHub: LatLng;
109
+ return Object.entries(routes).reduce<{ points: LatLng[]; lines: { source: LatLng; target: LatLng }[] }>(
110
+ (features, [hub, regional]) => {
111
+ const hubAirport = airports.features.find(({ properties }) => properties.iata === hub);
112
+ if (hubAirport) {
113
+ const [lng, lat] = closestPoint(points, hubAirport.geometry.coordinates);
114
+ const hubPoint = { lat, lng };
115
+ features.points.push(hubPoint);
116
+ if (previousHub) {
117
+ features.lines.push({ source: previousHub, target: hubPoint });
118
+ }
119
+
120
+ for (const dest of regional) {
121
+ const destAirport = airports.features.find(({ properties }) => properties.iata === dest);
122
+ if (destAirport) {
123
+ const [lng, lat] = closestPoint(points, destAirport.geometry.coordinates);
124
+ features.points.push({ lat, lng });
125
+ features.lines.push({ source: hubPoint, target: { lat, lng } });
126
+ }
127
+ }
128
+
129
+ previousHub = hubPoint;
130
+ }
131
+
132
+ return features;
133
+ },
134
+ { points: [], lines: [] },
135
+ );
136
+ };
137
+
138
+ type StoryProps = Pick<GlobeRootProps, 'scale' | 'translation' | 'rotation'> &
139
+ Pick<GlobeCanvasProps, 'projection' | 'styles'> & {
140
+ drag?: boolean;
141
+ spin?: boolean;
142
+ tour?: boolean;
143
+ xAxis?: boolean;
144
+ };
145
+
146
+ const Story = ({
147
+ scale: _scale = 1,
148
+ translation,
149
+ rotation = [0, 0, 0],
150
+ projection,
151
+ styles = defaultStyles,
152
+ drag = false,
153
+ spin = false,
154
+ tour = false,
155
+ xAxis = false,
156
+ }: StoryProps) => {
157
+ const controller = useRef<GlobeController>(null);
158
+ const [dots] = useAsyncState(async () => {
159
+ const points = (await import('../../../data/countries-dots-3.ts')).default;
160
+ return {
161
+ type: 'Topology',
162
+ objects: { dots: points },
163
+ } as any as Topology;
164
+ });
165
+ // const [topology] = useImportJson('../../../data/raw/countries-110m.json');
166
+ const [topology] = useAsyncState(async () => (await import('../../../data/countries-110m.ts')).default);
167
+ const [airports] = useAsyncState(async () => (await import('../../../data/airports.ts')).default);
168
+ const features = useMemo(() => {
169
+ return airports ? createTrip(airports, routes, (dots?.objects.dots as any)?.geometries[0].coordinates) : undefined;
170
+ }, [airports, routes, dots]);
171
+
172
+ // Control hooks.
173
+ const [startSpinner, stopSpinner] = useSpinner(controller.current, { disabled: !spin });
174
+ const [startTour, stopTour] = useTour(controller.current, features, {
175
+ disabled: !tour,
176
+ styles,
177
+ });
178
+ useDrag(controller.current, {
179
+ xAxis,
180
+ disabled: !drag,
181
+ onUpdate: (event) => {
182
+ switch (event.type) {
183
+ case 'start': {
184
+ stopSpinner();
185
+ stopTour();
186
+ break;
187
+ }
188
+ }
189
+ },
190
+ });
191
+
192
+ // TODO(burdon): Factor out handlers.
193
+ const handleAction: ControlProps['onAction'] = (event) => {
194
+ switch (event) {
195
+ case 'start': {
196
+ if (spin) {
197
+ startSpinner();
198
+ }
199
+ if (tour) {
200
+ startTour();
201
+ }
202
+ break;
203
+ }
204
+ case 'zoom-in': {
205
+ controller.current.setScale((scale) => scale * 1.1);
206
+ break;
207
+ }
208
+ case 'zoom-out': {
209
+ controller.current.setScale((scale) => scale * 0.9);
210
+ break;
211
+ }
212
+ }
213
+ };
214
+
215
+ return (
216
+ <Globe.Root classNames='absolute inset-0' scale={_scale} translation={translation} rotation={rotation}>
217
+ <Globe.Canvas
218
+ ref={controller}
219
+ topology={styles.dots ? dots : topology}
220
+ projection={projection}
221
+ styles={styles}
222
+ features={tour ? { points: features?.points ?? [] } : features}
223
+ />
224
+ <Globe.Zoom onAction={handleAction} />
225
+ <Globe.Action onAction={handleAction} />
226
+ <Globe.Debug />
227
+ <Globe.Panel position='topright' classNames='w-20 h-20'>
228
+ <Leva />
229
+ </Globe.Panel>
230
+ </Globe.Root>
231
+ );
232
+ };
233
+
234
+ const initialRotation: Vector = [0, -40, 0];
235
+
236
+ const meta: Meta = {
237
+ title: 'ui/react-ui-geo/Globe',
238
+ component: Globe.Root,
239
+ decorators: [withTheme, withLayout({ fullscreen: true, classNames: 'bg-[#000]', tooltips: true })],
240
+ };
241
+
242
+ export default meta;
243
+
244
+ export const Earth1 = () => {
245
+ // const [topology] = useImportJson('../../../data/raw/countries-110m.json');
246
+ const [topology] = useAsyncState(async () => (await import('../../../data/countries-110m.ts')).default);
247
+ const [controller, setController] = useState<GlobeController | null>();
248
+ const handleAction = useGlobeZoomHandler(controller);
249
+ useDrag(controller);
250
+
251
+ return (
252
+ <Globe.Root scale={1.2} rotation={[Math.random() * 360, 0, 0]}>
253
+ <Globe.Canvas ref={setController} topology={topology} />
254
+ <Globe.Zoom onAction={handleAction} />
255
+ </Globe.Root>
256
+ );
257
+ };
258
+
259
+ export const Earth2 = () => {
260
+ // const [topology] = useImportJson('../../../data/raw/countries-110m.json');
261
+ const [topology] = useAsyncState(async () => (await import('../../../data/countries-110m.ts')).default);
262
+ const [controller, setController] = useState<GlobeController | null>();
263
+ const handleAction = useGlobeZoomHandler(controller);
264
+ useDrag(controller);
265
+
266
+ return (
267
+ <div className='absolute bottom-0 left-0 right-0 '>
268
+ <Globe.Root classNames='h-[400px]' scale={2.8} translation={{ x: 0, y: 400 }}>
269
+ <Globe.Canvas ref={setController} topology={topology} />
270
+ <Globe.Zoom onAction={handleAction} />
271
+ </Globe.Root>
272
+ </div>
273
+ );
274
+ };
275
+
276
+ const monochrome: StyleSet = {
277
+ water: {
278
+ fillStyle: '#191919',
279
+ },
280
+
281
+ land: {
282
+ fillStyle: '#444',
283
+ strokeStyle: '#222',
284
+ },
285
+
286
+ border: {
287
+ strokeStyle: '#111',
288
+ },
289
+
290
+ graticule: {
291
+ strokeStyle: '#111',
292
+ },
293
+ };
294
+
295
+ export const Mercator = () => {
296
+ // const [topology] = useImportJson('../../../data/raw/countries-110m.json');
297
+ const [topology] = useAsyncState(async () => (await import('../../../data/countries-110m.ts')).default);
298
+ const [controller, setController] = useState<GlobeController | null>();
299
+ const handleAction = useGlobeZoomHandler(controller);
300
+ useDrag(controller);
301
+
302
+ return (
303
+ <Globe.Root classNames='flex grow overflow-hidden' scale={0.7} rotation={initialRotation}>
304
+ <Globe.Canvas ref={setController} topology={topology} projection='mercator' styles={monochrome} />
305
+ <Globe.Zoom onAction={handleAction} />
306
+ </Globe.Root>
307
+ );
308
+ };
309
+
310
+ export const Globe1 = () => {
311
+ return <Story drag projection='mercator' scale={0.8} rotation={initialRotation} />;
312
+ };
313
+
314
+ export const Globe2 = () => {
315
+ return <Story drag projection='transverse-mercator' scale={0.8} rotation={initialRotation} />;
316
+ };
317
+
318
+ export const Globe3 = () => {
319
+ return <Story drag spin scale={1.5} rotation={initialRotation} />;
320
+ };
321
+
322
+ export const Globe4 = () => {
323
+ return <Story drag tour scale={2} rotation={initialRotation} />;
324
+ };
325
+
326
+ export const Globe5 = () => {
327
+ return <Story drag tour scale={0.9} rotation={initialRotation} styles={dotStyles} />;
328
+ };
329
+
330
+ export const Globe6 = () => {
331
+ return <Story drag xAxis tour scale={2} translation={{ x: 0, y: 600 }} rotation={[0, -20, 0]} styles={dotStyles} />;
332
+ };