@johnmorrisdotca/chikyu-earth 0.5.0 → 0.7.0
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/CHANGELOG.md +42 -0
- package/NOTICE.md +11 -0
- package/README.md +172 -27
- package/dist/countries.d.ts +11 -0
- package/dist/countries.js +11 -0
- package/dist/element.d.ts +18 -0
- package/dist/element.js +15 -2
- package/dist/globe.d.ts +15 -1
- package/dist/globe.js +15 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +12 -1
- package/dist/markers/cluster.d.ts +27 -0
- package/dist/markers/cluster.js +16 -0
- package/dist/markers/labels.d.ts +40 -0
- package/dist/markers/labels.js +18 -0
- package/dist/markers/layer.d.ts +80 -0
- package/dist/markers/layer.js +21 -0
- package/dist/markers/project.d.ts +63 -2
- package/dist/markers/project.js +52 -2
- package/dist/markers/types.d.ts +48 -3
- package/dist/realistic/earth.d.ts +30 -5
- package/dist/realistic/earth.js +41 -134
- package/dist/realistic/element.d.ts +47 -7
- package/dist/realistic/element.js +48 -44
- package/dist/realistic/gate.d.ts +45 -1
- package/dist/realistic/gate.js +33 -1
- package/dist/realistic/shaders.d.ts +9 -4
- package/dist/realistic/shaders.js +54 -9
- package/dist/realistic/shared.d.ts +23 -0
- package/dist/realistic/shared.js +51 -0
- package/dist/realistic/sun.d.ts +40 -3
- package/dist/realistic/sun.js +40 -3
- package/dist/realistic/textures.d.ts +40 -0
- package/dist/realistic/textures.js +141 -0
- package/dist/realistic/tiers.d.ts +80 -6
- package/dist/realistic/tiers.js +69 -5
- package/dist/rotate.d.ts +59 -4
- package/dist/rotate.js +59 -4
- package/dist/space/element.d.ts +134 -0
- package/dist/space/element.js +394 -0
- package/dist/space/ephemeris.d.ts +151 -0
- package/dist/space/ephemeris.js +162 -0
- package/dist/space/index.d.ts +3 -0
- package/dist/space/index.js +5 -0
- package/dist/space/scale.d.ts +124 -0
- package/dist/space/scale.js +141 -0
- package/dist/space/scene.d.ts +131 -0
- package/dist/space/scene.js +295 -0
- package/dist/styles.d.ts +65 -2
- package/dist/styles.js +43 -2
- package/dist/textures/moon-1024.webp +0 -0
- package/dist/textures/moon-2048.webp +0 -0
- package/dist/types.d.ts +55 -5
- package/dist/view.d.ts +63 -4
- package/dist/view.js +52 -4
- package/package.json +55 -8
package/dist/markers/labels.js
CHANGED
|
@@ -4,6 +4,24 @@ const GAP = 3;
|
|
|
4
4
|
* Place up to `max` labels inside `width` x `height`. Each label is tried to the right of its dot, then to the left, above and below; the first spot that is inside
|
|
5
5
|
* and free of the labels already placed wins. Items are taken highest priority first (a tie keeps the order given). The cost is the number of items times at most
|
|
6
6
|
* four tries against a grid of what is placed.
|
|
7
|
+
*
|
|
8
|
+
* @param items - The dots and the size of each one's label.
|
|
9
|
+
* @param width - The width of the area the labels must stay inside, in pixels.
|
|
10
|
+
* @param height - The height of that area, in pixels.
|
|
11
|
+
* @param max - The most labels to place.
|
|
12
|
+
* @param cell - The side of the grid cell used to find overlaps, in pixels.
|
|
13
|
+
* @returns A placement for each label that fits; the others are left out.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { placeLabels } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
18
|
+
*
|
|
19
|
+
* const items = [
|
|
20
|
+
* { x: 100, y: 100, r: 4, w: 60, h: 20, priority: 1 },
|
|
21
|
+
* { x: 110, y: 104, r: 4, w: 60, h: 20, priority: 9 },
|
|
22
|
+
* ];
|
|
23
|
+
* console.log(placeLabels(items, 300, 300, 10).map((place) => place.item));
|
|
24
|
+
* ```
|
|
7
25
|
*/
|
|
8
26
|
export function placeLabels(items, width, height, max, cell = 64) {
|
|
9
27
|
const order = items.map((_, i) => i).sort((a, b) => items[b].priority - items[a].priority || a - b);
|
package/dist/markers/layer.d.ts
CHANGED
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
import { type Pose } from "./project.ts";
|
|
2
2
|
import type { GroupInfo, MarkerInput } from "./types.ts";
|
|
3
3
|
/** The view as an element tells it: the Pose, the size of the box it is drawn in, and the CSS transform its picture carries between redraws. */
|
|
4
|
+
/**
|
|
5
|
+
* The pose of an element's last drawing, with the size of its box and the CSS transform its picture carries between redraws.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import type { OverlayPose } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
10
|
+
*
|
|
11
|
+
* const where = (pose: OverlayPose): string => `${pose.lon}, ${pose.lat} at ${pose.width} x ${pose.height}`;
|
|
12
|
+
* console.log(typeof where);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
4
15
|
export interface OverlayPose extends Pose {
|
|
5
16
|
width: number;
|
|
6
17
|
height: number;
|
|
7
18
|
transform: string;
|
|
8
19
|
}
|
|
9
20
|
/** What an element gives the markers: a box laid over its view, the pose of its last draw, and a way to hear the next ones. */
|
|
21
|
+
/**
|
|
22
|
+
* What an element gives the markers (`element.overlay`): a box laid over its view, the pose of its last draw, and a way to hear the next ones.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import type { OverlayHost } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
27
|
+
*
|
|
28
|
+
* const follow = (host: OverlayHost): (() => void) => host.subscribe((pose) => console.log(pose.radius));
|
|
29
|
+
* console.log(typeof follow);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
10
32
|
export interface OverlayHost {
|
|
11
33
|
readonly overlayRoot: HTMLElement;
|
|
12
34
|
readonly pose: OverlayPose | null;
|
|
13
35
|
subscribe(listener: (pose: OverlayPose) => void): () => void;
|
|
14
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* What {@link attachMarkers} may be asked: the most labels, how close markers gather, and the default colour.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { attachMarkers, type MarkerOptions, type OverlayElement } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
43
|
+
*
|
|
44
|
+
* const options: MarkerOptions = { maxLabels: 12, clusterRadius: 20, color: "#ffcc00" };
|
|
45
|
+
* const mark = (element: OverlayElement) => attachMarkers(element, options);
|
|
46
|
+
* console.log(typeof mark);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
15
49
|
export interface MarkerOptions {
|
|
16
50
|
/** Most labels shown at once (24). */
|
|
17
51
|
maxLabels?: number;
|
|
@@ -20,6 +54,20 @@ export interface MarkerOptions {
|
|
|
20
54
|
/** The colour of a marker with none of its own. */
|
|
21
55
|
color?: string;
|
|
22
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The markers on one globe: add, update, remove and find them, show or hide groups, and detach.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts no-run
|
|
62
|
+
* import { attachMarkers, type Markers, type OverlayElement } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
63
|
+
*
|
|
64
|
+
* declare const earth: OverlayElement;
|
|
65
|
+
* const markers: Markers = attachMarkers(earth);
|
|
66
|
+
* markers.add({ id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", group: "Cities" });
|
|
67
|
+
* markers.toggleGroup("Cities");
|
|
68
|
+
* console.log(markers.size, markers.groups());
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
23
71
|
export interface Markers {
|
|
24
72
|
add(marker: MarkerInput): void;
|
|
25
73
|
addAll(markers: readonly MarkerInput[]): void;
|
|
@@ -43,7 +91,39 @@ export interface Markers {
|
|
|
43
91
|
};
|
|
44
92
|
detach(): void;
|
|
45
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* An element markers can be put on: any HTML element with an `overlay` (both `<chikyu-earth>` and `<chikyu-earth-realistic>` have one).
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { attachMarkers, type OverlayElement } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
100
|
+
*
|
|
101
|
+
* const mark = (element: OverlayElement) => attachMarkers(element);
|
|
102
|
+
* console.log(typeof mark);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
46
105
|
export type OverlayElement = HTMLElement & {
|
|
47
106
|
overlay: OverlayHost;
|
|
48
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Put markers on a globe, for either look: dots drawn in one pass on a canvas, a few labels as real buttons, crowded places gathered into clusters. It draws only when the view or the markers change, reads no layout to place a label, and shows no more labels than `maxLabels`. Hovering, clicking or focusing a marker fires `chikyu-marker-hover`, `chikyu-marker-click` and `chikyu-marker-focus` on the element, with your own `data` in the detail.
|
|
110
|
+
*
|
|
111
|
+
* @param element - `<chikyu-earth>` or `<chikyu-earth-realistic>`.
|
|
112
|
+
* @param options - The most labels, the cluster radius and the default colour; each has a default.
|
|
113
|
+
* @returns The markers: `add`, `addAll`, `update`, `remove`, `clear`, `groups`, `toggleGroup`, `stats` and `detach`.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts no-run
|
|
117
|
+
* import "@johnmorrisdotca/chikyu-earth/element";
|
|
118
|
+
* import { attachMarkers, type MarkerEventDetail } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
119
|
+
*
|
|
120
|
+
* const earth = document.querySelector("chikyu-earth")!;
|
|
121
|
+
* const markers = attachMarkers(earth);
|
|
122
|
+
* markers.add({ id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", group: "Cities" });
|
|
123
|
+
* earth.addEventListener("chikyu-marker-click", (event) => {
|
|
124
|
+
* const { marker } = (event as CustomEvent<MarkerEventDetail>).detail;
|
|
125
|
+
* console.log("chose", marker?.label);
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
49
129
|
export declare function attachMarkers(element: OverlayElement, options?: MarkerOptions): Markers;
|
package/dist/markers/layer.js
CHANGED
|
@@ -14,6 +14,27 @@ const CSS = `
|
|
|
14
14
|
const EDGE = 16;
|
|
15
15
|
const LABEL_FONT = "12px system-ui, -apple-system, sans-serif";
|
|
16
16
|
const TEXT_LIST_MAX = 200;
|
|
17
|
+
/**
|
|
18
|
+
* Put markers on a globe, for either look: dots drawn in one pass on a canvas, a few labels as real buttons, crowded places gathered into clusters. It draws only when the view or the markers change, reads no layout to place a label, and shows no more labels than `maxLabels`. Hovering, clicking or focusing a marker fires `chikyu-marker-hover`, `chikyu-marker-click` and `chikyu-marker-focus` on the element, with your own `data` in the detail.
|
|
19
|
+
*
|
|
20
|
+
* @param element - `<chikyu-earth>` or `<chikyu-earth-realistic>`.
|
|
21
|
+
* @param options - The most labels, the cluster radius and the default colour; each has a default.
|
|
22
|
+
* @returns The markers: `add`, `addAll`, `update`, `remove`, `clear`, `groups`, `toggleGroup`, `stats` and `detach`.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts no-run
|
|
26
|
+
* import "@johnmorrisdotca/chikyu-earth/element";
|
|
27
|
+
* import { attachMarkers, type MarkerEventDetail } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
28
|
+
*
|
|
29
|
+
* const earth = document.querySelector("chikyu-earth")!;
|
|
30
|
+
* const markers = attachMarkers(earth);
|
|
31
|
+
* markers.add({ id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", group: "Cities" });
|
|
32
|
+
* earth.addEventListener("chikyu-marker-click", (event) => {
|
|
33
|
+
* const { marker } = (event as CustomEvent<MarkerEventDetail>).detail;
|
|
34
|
+
* console.log("chose", marker?.label);
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
17
38
|
export function attachMarkers(element, options = {}) {
|
|
18
39
|
const host = element.overlay;
|
|
19
40
|
const root = host.overlayRoot;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
/** The view: the point of the Earth at the middle of the disc, the disc's radius and its centre, in CSS pixels. */
|
|
2
|
+
/**
|
|
3
|
+
* The view: the point of the Earth at the middle of the disc, the disc's radius and its centre, in CSS pixels.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { project, type Pose } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
8
|
+
*
|
|
9
|
+
* const pose: Pose = { lon: 10, lat: 20, radius: 100, cx: 150, cy: 150 };
|
|
10
|
+
* console.log(project(10, 20, pose));
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
2
13
|
export interface Pose {
|
|
3
14
|
lon: number;
|
|
4
15
|
lat: number;
|
|
@@ -9,13 +20,63 @@ export interface Pose {
|
|
|
9
20
|
/**
|
|
10
21
|
* Project a longitude and latitude (degrees) to the screen. `z` is the cosine of the angle from the middle of the disc: above 0 the point faces
|
|
11
22
|
* the viewer, below it is on the far side. North is up.
|
|
23
|
+
*
|
|
24
|
+
* @param lon - Longitude in degrees east.
|
|
25
|
+
* @param lat - Latitude in degrees north.
|
|
26
|
+
* @param pose - The view.
|
|
27
|
+
* @returns The point's x and y in pixels and `z`, the cosine of its angle from the middle of the disc.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { project } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
32
|
+
*
|
|
33
|
+
* const where = project(139.69, 35.69, { lon: 139.69, lat: 35.69, radius: 200, cx: 210, cy: 210 });
|
|
34
|
+
* console.log(where.x, where.y, where.z);
|
|
35
|
+
* ```
|
|
12
36
|
*/
|
|
13
37
|
export declare function project(lon: number, lat: number, pose: Pose): {
|
|
14
38
|
x: number;
|
|
15
39
|
y: number;
|
|
16
40
|
z: number;
|
|
17
41
|
};
|
|
18
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Project many points into flat arrays (reused between calls); `z` is the cosine used for a point's facing test.
|
|
44
|
+
*
|
|
45
|
+
* @param lons - Longitudes in degrees.
|
|
46
|
+
* @param lats - Latitudes in degrees.
|
|
47
|
+
* @param count - How many points to project.
|
|
48
|
+
* @param pose - The view.
|
|
49
|
+
* @param xs - Filled with each point's x in pixels.
|
|
50
|
+
* @param ys - Filled with each point's y in pixels.
|
|
51
|
+
* @param zs - Filled with each point's `z`: above 0 it faces the viewer.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { projectAll } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
56
|
+
*
|
|
57
|
+
* const xs = new Float32Array(2);
|
|
58
|
+
* const ys = new Float32Array(2);
|
|
59
|
+
* const zs = new Float32Array(2);
|
|
60
|
+
* projectAll([0, 180], [0, 0], 2, { lon: 0, lat: 0, radius: 100, cx: 100, cy: 100 }, xs, ys, zs);
|
|
61
|
+
* console.log(zs[0], zs[1]);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
19
64
|
export declare function projectAll(lons: ArrayLike<number>, lats: ArrayLike<number>, count: number, pose: Pose, xs: Float32Array, ys: Float32Array, zs: Float32Array): void;
|
|
20
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* The pixel ratio for an overlay canvas: the device's, to 2, held to 4096 a side and 6 million pixels (the same budget as the 3D canvas).
|
|
67
|
+
*
|
|
68
|
+
* @param width - The canvas's width in CSS pixels.
|
|
69
|
+
* @param height - The canvas's height in CSS pixels.
|
|
70
|
+
* @param deviceRatio - The device's pixel ratio.
|
|
71
|
+
* @param maxSide - The most pixels on a side.
|
|
72
|
+
* @param maxPixels - The most pixels in all.
|
|
73
|
+
* @returns The ratio to draw at, between 0.1 and 2.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { canvasRatio } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
78
|
+
*
|
|
79
|
+
* console.log(canvasRatio(420, 420, 3), canvasRatio(5000, 3000, 2));
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
21
82
|
export declare function canvasRatio(width: number, height: number, deviceRatio: number, maxSide?: number, maxPixels?: number): number;
|
package/dist/markers/project.js
CHANGED
|
@@ -3,6 +3,19 @@ const RAD = Math.PI / 180;
|
|
|
3
3
|
/**
|
|
4
4
|
* Project a longitude and latitude (degrees) to the screen. `z` is the cosine of the angle from the middle of the disc: above 0 the point faces
|
|
5
5
|
* the viewer, below it is on the far side. North is up.
|
|
6
|
+
*
|
|
7
|
+
* @param lon - Longitude in degrees east.
|
|
8
|
+
* @param lat - Latitude in degrees north.
|
|
9
|
+
* @param pose - The view.
|
|
10
|
+
* @returns The point's x and y in pixels and `z`, the cosine of its angle from the middle of the disc.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { project } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
15
|
+
*
|
|
16
|
+
* const where = project(139.69, 35.69, { lon: 139.69, lat: 35.69, radius: 200, cx: 210, cy: 210 });
|
|
17
|
+
* console.log(where.x, where.y, where.z);
|
|
18
|
+
* ```
|
|
6
19
|
*/
|
|
7
20
|
export function project(lon, lat, pose) {
|
|
8
21
|
const phi = lat * RAD;
|
|
@@ -16,7 +29,28 @@ export function project(lon, lat, pose) {
|
|
|
16
29
|
z,
|
|
17
30
|
};
|
|
18
31
|
}
|
|
19
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Project many points into flat arrays (reused between calls); `z` is the cosine used for a point's facing test.
|
|
34
|
+
*
|
|
35
|
+
* @param lons - Longitudes in degrees.
|
|
36
|
+
* @param lats - Latitudes in degrees.
|
|
37
|
+
* @param count - How many points to project.
|
|
38
|
+
* @param pose - The view.
|
|
39
|
+
* @param xs - Filled with each point's x in pixels.
|
|
40
|
+
* @param ys - Filled with each point's y in pixels.
|
|
41
|
+
* @param zs - Filled with each point's `z`: above 0 it faces the viewer.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { projectAll } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
46
|
+
*
|
|
47
|
+
* const xs = new Float32Array(2);
|
|
48
|
+
* const ys = new Float32Array(2);
|
|
49
|
+
* const zs = new Float32Array(2);
|
|
50
|
+
* projectAll([0, 180], [0, 0], 2, { lon: 0, lat: 0, radius: 100, cx: 100, cy: 100 }, xs, ys, zs);
|
|
51
|
+
* console.log(zs[0], zs[1]);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
20
54
|
export function projectAll(lons, lats, count, pose, xs, ys, zs) {
|
|
21
55
|
const phi0 = pose.lat * RAD;
|
|
22
56
|
const sin0 = Math.sin(phi0);
|
|
@@ -32,7 +66,23 @@ export function projectAll(lons, lats, count, pose, xs, ys, zs) {
|
|
|
32
66
|
ys[i] = pose.cy - pose.radius * (cos0 * sinPhi - sin0 * cosPhi * cosDelta);
|
|
33
67
|
}
|
|
34
68
|
}
|
|
35
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* The pixel ratio for an overlay canvas: the device's, to 2, held to 4096 a side and 6 million pixels (the same budget as the 3D canvas).
|
|
71
|
+
*
|
|
72
|
+
* @param width - The canvas's width in CSS pixels.
|
|
73
|
+
* @param height - The canvas's height in CSS pixels.
|
|
74
|
+
* @param deviceRatio - The device's pixel ratio.
|
|
75
|
+
* @param maxSide - The most pixels on a side.
|
|
76
|
+
* @param maxPixels - The most pixels in all.
|
|
77
|
+
* @returns The ratio to draw at, between 0.1 and 2.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { canvasRatio } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
82
|
+
*
|
|
83
|
+
* console.log(canvasRatio(420, 420, 3), canvasRatio(5000, 3000, 2));
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
36
86
|
export function canvasRatio(width, height, deviceRatio, maxSide = 4096, maxPixels = 6_000_000) {
|
|
37
87
|
let ratio = Math.min(Math.max(deviceRatio, 1), 2);
|
|
38
88
|
ratio = Math.min(ratio, maxSide / Math.max(width, 1), maxSide / Math.max(height, 1));
|
package/dist/markers/types.d.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The shapes a marker can be drawn as: `dot`, `ring`, `square` or `diamond`.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import type { MarkerIcon, MarkerInput } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
7
|
+
*
|
|
8
|
+
* const icon: MarkerIcon = "diamond";
|
|
9
|
+
* const stadium: MarkerInput = { id: "camp-nou", lon: 2.12, lat: 41.38, icon, group: "Stadiums" };
|
|
10
|
+
* console.log(stadium.icon);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
2
13
|
export type MarkerIcon = "dot" | "ring" | "square" | "diamond";
|
|
3
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* A place on the Earth. Chikyu ships none: the page brings its own.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import type { MarkerInput } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
20
|
+
*
|
|
21
|
+
* const tokyo: MarkerInput = { id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo", group: "Cities", priority: 5, data: { population: 14_000_000 } };
|
|
22
|
+
* console.log(tokyo.label);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
4
25
|
export interface MarkerInput {
|
|
5
26
|
/** Your own unique name for it. */
|
|
6
27
|
id: string;
|
|
@@ -23,7 +44,20 @@ export interface MarkerInput {
|
|
|
23
44
|
/** Yours: given back in every event. */
|
|
24
45
|
data?: unknown;
|
|
25
46
|
}
|
|
26
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* What the `chikyu-marker-hover`, `chikyu-marker-click` and `chikyu-marker-focus` events carry in `event.detail`. A cluster click has `marker: null` and `cluster` listing the ids in it.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import type { MarkerEventDetail } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
53
|
+
*
|
|
54
|
+
* const on = (event: Event): void => {
|
|
55
|
+
* const detail = (event as CustomEvent<MarkerEventDetail>).detail;
|
|
56
|
+
* console.log(detail.marker?.label ?? `${detail.cluster?.length} places`, detail.x, detail.y);
|
|
57
|
+
* };
|
|
58
|
+
* console.log(typeof on);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
27
61
|
export interface MarkerEventDetail {
|
|
28
62
|
marker: MarkerInput | null;
|
|
29
63
|
cluster?: string[];
|
|
@@ -31,6 +65,17 @@ export interface MarkerEventDetail {
|
|
|
31
65
|
x: number;
|
|
32
66
|
y: number;
|
|
33
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* One group of markers: its name, how many it holds and whether it is shown.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import type { GroupInfo } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
74
|
+
*
|
|
75
|
+
* const show = (groups: GroupInfo[]): string => groups.map((group) => `${group.name}: ${group.count}${group.visible ? "" : " (hidden)"}`).join(", ");
|
|
76
|
+
* console.log(show([{ name: "Cities", count: 3, visible: true }]));
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
34
79
|
export interface GroupInfo {
|
|
35
80
|
name: string;
|
|
36
81
|
count: number;
|
|
@@ -2,11 +2,20 @@ import type * as THREE from "three";
|
|
|
2
2
|
import type { AssetCache, Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
3
3
|
import type { GeoPoint, GlobeView } from "../types.ts";
|
|
4
4
|
import { lookAt } from "../view.ts";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export type ThreeParts
|
|
5
|
+
import type { Layer } from "./tiers.ts";
|
|
6
|
+
import { type ThreeParts } from "./textures.ts";
|
|
7
|
+
export type { ThreeParts };
|
|
8
8
|
type Three = ThreeParts;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The glow reaches this many radii from the centre; the globe at 1x is drawn to fit inside it.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { ATMOSPHERE_OUTER } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
15
|
+
*
|
|
16
|
+
* console.log(ATMOSPHERE_OUTER);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
10
19
|
export declare const ATMOSPHERE_OUTER = 1.08;
|
|
11
20
|
/** What the scene reads at each draw; the element changes it and asks for a draw. */
|
|
12
21
|
export interface EarthModel {
|
|
@@ -50,7 +59,23 @@ export interface EarthDeps {
|
|
|
50
59
|
}) => void;
|
|
51
60
|
}
|
|
52
61
|
export declare const newModel: () => EarthModel;
|
|
53
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The disc's radius in CSS pixels in a box of `width` x `height` at `zoom`: it fits the glow in the box at 1x.
|
|
64
|
+
*
|
|
65
|
+
* @param width - The box's width in CSS pixels.
|
|
66
|
+
* @param height - The box's height in CSS pixels.
|
|
67
|
+
* @param zoom - The view's zoom, 1 at Fit.
|
|
68
|
+
* @returns The radius in CSS pixels, at least 1.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { discRadius } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
73
|
+
*
|
|
74
|
+
* console.log(discRadius(400, 400, 1).toFixed(1));
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
54
77
|
export declare const discRadius: (width: number, height: number, zoom: number) => number;
|
|
55
78
|
export { lookAt };
|
|
79
|
+
/** An equirectangular sphere: +z is longitude 0 on the equator, +x east, +y north; v is 0 at the north pole (the top row of the picture). */
|
|
80
|
+
export declare function sphere(three: Three, columns: number, rows: number): THREE.BufferGeometry;
|
|
56
81
|
export declare function createEarthItem(model: EarthModel, deps: EarthDeps): Item3D<Three>;
|