@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,149 @@
1
+ //
2
+ // Copyright 2020 DXOS.org
3
+ //
4
+
5
+ import * as d3 from 'd3';
6
+ import { type GeoPath, type GeoPermissibleObjects } from 'd3';
7
+ import * as topojson from 'topojson-client';
8
+ import { type Topology } from 'topojson-specification';
9
+
10
+ import { type LatLng, geoLine, geoPoint } from './path';
11
+
12
+ export type Styles = Record<string, any>;
13
+
14
+ export type Style = 'water' | 'graticule' | 'land' | 'border' | 'dots' | 'point' | 'line' | 'cursor' | 'arc';
15
+
16
+ export type StyleSet = Partial<Record<Style, Styles>>;
17
+
18
+ export type Features = {
19
+ points?: LatLng[];
20
+ lines?: { source: LatLng; target: LatLng }[];
21
+ };
22
+
23
+ export type Layer = {
24
+ styles: Styles;
25
+ path: GeoPermissibleObjects;
26
+ };
27
+
28
+ /**
29
+ * Create rendering layers.
30
+ */
31
+ export const createLayers = (topology: Topology, features: Features, styles: StyleSet): Layer[] => {
32
+ const layers: Layer[] = [];
33
+
34
+ if (styles.water) {
35
+ layers.push({
36
+ styles: styles.water,
37
+ path: {
38
+ type: 'Sphere',
39
+ },
40
+ });
41
+ }
42
+
43
+ if (styles.graticule) {
44
+ layers.push({
45
+ styles: styles.graticule,
46
+ path: d3.geoGraticule().step([6, 6])(),
47
+ });
48
+ }
49
+
50
+ //
51
+ // Topology.
52
+ //
53
+
54
+ if (topology) {
55
+ if (topology.objects.land && styles.land) {
56
+ layers.push({
57
+ styles: styles.land,
58
+ path: topojson.feature(topology, topology.objects.land),
59
+ });
60
+ }
61
+
62
+ if (topology.objects.countries && styles.border) {
63
+ layers.push({
64
+ styles: styles.border,
65
+ path: topojson.mesh(topology, topology.objects.countries, (a: any, b: any) => a !== b),
66
+ });
67
+ }
68
+
69
+ if (topology.objects.dots && styles.dots) {
70
+ layers.push({
71
+ styles: styles.dots,
72
+ path: topology.objects.dots as any, // TODO(burdon): Type.
73
+ });
74
+ }
75
+ }
76
+
77
+ //
78
+ // Features.
79
+ //
80
+
81
+ if (features) {
82
+ const { points, lines } = features;
83
+
84
+ if (points && styles.point) {
85
+ layers.push({
86
+ styles: styles.point,
87
+ path: {
88
+ type: 'GeometryCollection',
89
+ geometries: points.map((point) => geoPoint(point)),
90
+ },
91
+ });
92
+ }
93
+
94
+ if (lines && styles.line) {
95
+ layers.push({
96
+ styles: styles.line,
97
+ path: {
98
+ type: 'GeometryCollection',
99
+ geometries: lines.map(({ source, target }) => geoLine(source, target)),
100
+ },
101
+ });
102
+ }
103
+ }
104
+
105
+ return layers;
106
+ };
107
+
108
+ /**
109
+ * Render layers created above.
110
+ */
111
+ export const renderLayers = (generator: GeoPath, layers: Layer[] = [], scale: number) => {
112
+ const context: CanvasRenderingContext2D = generator.context();
113
+ const {
114
+ canvas: { width, height },
115
+ } = context;
116
+ context.reset();
117
+
118
+ // TODO(burdon): Option.
119
+ // Clear background.
120
+ context.clearRect(0, 0, width, height);
121
+
122
+ // Render features.
123
+ // https://github.com/d3/d3-geo#_path
124
+ layers.forEach(({ path, styles }) => {
125
+ context.save();
126
+ let fill = false;
127
+ let stroke = false;
128
+ if (styles) {
129
+ Object.entries(styles).forEach(([key, value]) => {
130
+ if (key === 'pointRadius') {
131
+ generator.pointRadius(value * scale);
132
+ } else {
133
+ context[key] = value;
134
+ fill ||= key === 'fillStyle';
135
+ stroke ||= key === 'strokeStyle';
136
+ }
137
+ });
138
+ }
139
+
140
+ context.beginPath();
141
+
142
+ generator(path);
143
+ fill && context.fill();
144
+ stroke && context.stroke();
145
+ context.restore();
146
+ });
147
+
148
+ return context;
149
+ };