@johnmorrisdotca/chikyu-earth 0.40.0 → 0.42.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.
@@ -10,6 +10,7 @@ import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.
10
10
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
11
11
  import { createBorderLayer, newBorderState } from "../borders/layer.js";
12
12
  import { createGridLayer, newGridState } from "../grid/layer.js";
13
+ import { createRouteLayer, newRouteState } from "../route/layer.js";
13
14
  import { pointOnEarth } from "./tiles.js";
14
15
  import { paintMinute } from "../paint/buffer.js";
15
16
  import { createPaintTexture } from "../paint/texture.js";
@@ -48,6 +49,7 @@ export const newModel = () => ({
48
49
  bodyLabel: newBodyLabelState(),
49
50
  borders: newBorderState(),
50
51
  grid: newGridState(),
52
+ route: newRouteState(),
51
53
  });
52
54
  /**
53
55
  * 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.
@@ -199,6 +201,7 @@ export function createEarthItem(model, deps) {
199
201
  let borders = null;
200
202
  const placeRings = { sprites: null, tried: false };
201
203
  let gridLayer = null;
204
+ let routeLayer = null;
202
205
  return {
203
206
  scene,
204
207
  camera,
@@ -309,6 +312,16 @@ export function createEarthItem(model, deps) {
309
312
  }
310
313
  }
311
314
  gridLayer?.sync(radius);
315
+ if ((model.route.ends || routeLayer) && !routeLayer && !model.route.failed) {
316
+ try {
317
+ routeLayer = createRouteLayer(three, turned, model.route);
318
+ }
319
+ catch (error) {
320
+ model.route.failed = true;
321
+ console.warn(error instanceof Error ? error.message : error);
322
+ }
323
+ }
324
+ routeLayer?.sync();
312
325
  if (deps.paint) {
313
326
  const changed = deps.paint.step(model.time);
314
327
  paint.sync(deps.paint.on(), changed);
@@ -337,6 +350,7 @@ export function createEarthItem(model, deps) {
337
350
  borders?.dispose();
338
351
  placeRings.sprites?.dispose();
339
352
  gridLayer?.dispose();
353
+ routeLayer?.dispose();
340
354
  model.tiles = null;
341
355
  tiles.dispose();
342
356
  textures.dispose();
@@ -12,6 +12,7 @@ import { type Place, type PlaceLook } from "../markers/places.ts";
12
12
  import { type CityNamesStyle } from "../cities/host.ts";
13
13
  import { type BorderSets } from "../borders/lines.ts";
14
14
  import type { BorderData, BorderStats } from "../borders/layer.ts";
15
+ import { type RouteLeg } from "../route.ts";
15
16
  import type { GridStats } from "../grid/layer.ts";
16
17
  import { type CountryNamesStats, type CountryNamesStyle } from "../country-names/host.ts";
17
18
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
@@ -192,6 +193,38 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
192
193
  */
193
194
  get places(): Place[];
194
195
  set places(value: readonly Place[]);
196
+ /**
197
+ * Name each `here` place with the nearest city (the attribute `here-city`). `false` (the default) leaves the page's label and loads nothing.
198
+ * `true` looks within 100 km (`HERE_CITY_KM`). A number is that limit in kilometres, at most 20,000 (`HERE_CITY_MAX_KM`); a city further away is not used, and the page's label stays.
199
+ * The cities are kuni's capitals, the other cities of a million and the others of 100,000, an optional peer loaded only when this is on and a `here` place is set. The name follows the page's language
200
+ * (the short Japanese name, then the Japanese name, else English). `places` is not changed: only the drawn name is. Nothing is drawn again at rest.
201
+ *
202
+ * @example
203
+ * ```ts no-run
204
+ * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
205
+ *
206
+ * const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
207
+ * earth.hereCity = true;
208
+ * console.log(earth.hereCity); // 100
209
+ * earth.hereCity = false;
210
+ * ```
211
+ */
212
+ get hereCity(): false | number;
213
+ set hereCity(value: false | true | number);
214
+ /**
215
+ * A route between two places (the attribute `route`, `lon,lat,lon,lat`). Null, the default, draws none. The line is the WGS84 geodesic, split at the date line, and it turns with the Earth.
216
+ * Setting the property writes the attribute. Nothing is drawn again at rest: the line is drawn with the picture, and only when the route or the view changes.
217
+ */
218
+ get route(): {
219
+ from: GeoPoint;
220
+ to: GeoPoint;
221
+ } | null;
222
+ set route(value: {
223
+ from: GeoPoint;
224
+ to: GeoPoint;
225
+ } | null);
226
+ /** The distance, bearings and flight-time estimate for `route`, or null when none is set. The flight time assumes 900 km/h. */
227
+ get routeInfo(): RouteLeg | null;
195
228
  /**
196
229
  * Turn the Earth so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom
197
230
  * and pan stay. The place is named by its `id`, or by its label in any case. The tilt is held to 90 degrees either way, so a place more than 90 degrees of latitude from `center` comes as near the middle
@@ -367,6 +400,13 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
367
400
  dots: number;
368
401
  omitted: number;
369
402
  };
403
+ /** The nearest city on a `here` marker (`here-city`): whether it is on, the kilometre limit (0 when off), whether kuni's cities have arrived, and whether that load is still going. */
404
+ hereCity: {
405
+ on: boolean;
406
+ maxKm: number;
407
+ loaded: boolean;
408
+ pending: boolean;
409
+ };
370
410
  /** The names of cities: whether `city-names` is set and the most it asks for, the Earth's radius on the screen, the tiers of kuni's cities that have arrived and how many cities, the names shown at the last draw and how many times the layer was drawn. */
371
411
  cityNames: {
372
412
  on: boolean;
@@ -381,6 +421,13 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
381
421
  borders: BorderStats;
382
422
  /** The grid: whether it was drawn at the last draw, whether every 15 degrees (else 30), its segments then, how many times its lines were made, and whether it could not be made. */
383
423
  grid: GridStats;
424
+ /** The route between two places: whether one is set, and its geodesic distance, great-circle distance and flight time at 900 km/h. */
425
+ route: {
426
+ on: boolean;
427
+ kilometres: number;
428
+ greatCircleKm: number;
429
+ flightHours: number;
430
+ };
384
431
  /** The names of countries: whether `country-names` is set and the most it asks for, the countries loaded, the names shown at the last draw, how many times they were laid out, and whether the outlines could not be loaded. */
385
432
  countryNames: CountryNamesStats;
386
433
  };
@@ -17,6 +17,8 @@ import { ownCredit } from "../door/own.js";
17
17
  import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
18
18
  import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
19
19
  import { cleanPlaces, orthoView, readPlaceGroups, readPlaces } from "../markers/places.js";
20
+ import { readHereCity } from "../markers/here-city.js";
21
+ import { createHereCity } from "../markers/here-city-host.js";
20
22
  import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
21
23
  import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
22
24
  import { subsolarPoint } from "./sun.js";
@@ -24,6 +26,8 @@ import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../citi
24
26
  import { project } from "../markers/project.js";
25
27
  import { BORDER_ATTRIBUTES, readBorders } from "../borders/lines.js";
26
28
  import { GRID_ATTRIBUTES, readGrid } from "../grid/lines.js";
29
+ import { readRoute, routeLeg, routeText } from "../route.js";
30
+ import { applyRoute } from "../route/layer.js";
27
31
  import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
28
32
  import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
29
33
  import { createGate, frameCap } from "./gate.js";
@@ -154,7 +158,7 @@ export const readTime = (value) => {
154
158
  * ```
155
159
  */
156
160
  export class ChikyuEarthRealistic extends HTMLElement {
157
- static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "satellite-tint"];
161
+ static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint"];
158
162
  #model = newModel();
159
163
  #paint = createPaintState();
160
164
  #mode = "now";
@@ -187,6 +191,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
187
191
  #countriesStyle = {};
188
192
  #listeners = new Set();
189
193
  #placeLayer;
194
+ /** The nearest city's name on a `here` marker (`here-city`), loaded only when that is on. */
195
+ #here;
190
196
  /** Whether the page has been told that places in sight were left undrawn. */
191
197
  #placesLost = { told: false };
192
198
  #placeList = [];
@@ -246,8 +252,9 @@ export class ChikyuEarthRealistic extends HTMLElement {
246
252
  this.#sky.setStyle(this.#skyStyle);
247
253
  this.#sky.setKeepClear(this.#keepClear);
248
254
  this.#placeLayer = createPlaceLayer(root.getElementById("places"));
255
+ this.#here = this.#openHereCity();
249
256
  this.#placeList = readPlaces(this.getAttribute("places"));
250
- this.#placeLayer.set(this.#placeList);
257
+ this.#placeLayer.set(this.#here.named(this.#placeList));
251
258
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
252
259
  this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
253
260
  this.#cities = createCityHost({
@@ -388,6 +395,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
388
395
  this.#taken = undefined;
389
396
  this.#sky?.dispose();
390
397
  this.#sky = undefined;
398
+ this.#here?.dispose();
399
+ this.#here = undefined;
391
400
  this.#placeLayer?.dispose();
392
401
  this.#placeLayer = undefined;
393
402
  this.#cities?.dispose();
@@ -437,6 +446,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
437
446
  this.#sky?.refresh();
438
447
  this.#cities?.refresh();
439
448
  this.#countries?.refresh();
449
+ this.#here?.refresh();
440
450
  }
441
451
  }
442
452
  else if (BODY_LABEL_ATTRIBUTES.includes(name))
@@ -445,8 +455,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
445
455
  this.#sky?.refresh();
446
456
  else if (name === "places") {
447
457
  this.#placeList = readPlaces(value);
448
- this.#placeLayer?.set(this.#placeList);
449
- this.#gate?.soon();
458
+ this.#applyPlaces();
459
+ }
460
+ else if (name === "here-city") {
461
+ this.#here?.setLimit(readHereCity(value));
462
+ this.#applyPlaces();
450
463
  }
451
464
  else if (name === "places-look" && this.#placeLayer) {
452
465
  this.#placeLayer.look = readPlaceLook(value);
@@ -456,6 +469,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
456
469
  this.#placeLayer.grouping = readPlaceGroups(value);
457
470
  this.#gate?.soon();
458
471
  }
472
+ else if (name === "route") {
473
+ if (applyRoute(this.#model.route, readRoute(value)))
474
+ this.#gate?.soon();
475
+ }
459
476
  else if (CITY_NAMES_ATTRIBUTES.includes(name))
460
477
  this.#cities?.refresh();
461
478
  else if (name === "borders") {
@@ -604,6 +621,77 @@ export class ChikyuEarthRealistic extends HTMLElement {
604
621
  else
605
622
  this.setAttribute("places", JSON.stringify(clean));
606
623
  }
624
+ /**
625
+ * Name each `here` place with the nearest city (the attribute `here-city`). `false` (the default) leaves the page's label and loads nothing.
626
+ * `true` looks within 100 km (`HERE_CITY_KM`). A number is that limit in kilometres, at most 20,000 (`HERE_CITY_MAX_KM`); a city further away is not used, and the page's label stays.
627
+ * The cities are kuni's capitals, the other cities of a million and the others of 100,000, an optional peer loaded only when this is on and a `here` place is set. The name follows the page's language
628
+ * (the short Japanese name, then the Japanese name, else English). `places` is not changed: only the drawn name is. Nothing is drawn again at rest.
629
+ *
630
+ * @example
631
+ * ```ts no-run
632
+ * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
633
+ *
634
+ * const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
635
+ * earth.hereCity = true;
636
+ * console.log(earth.hereCity); // 100
637
+ * earth.hereCity = false;
638
+ * ```
639
+ */
640
+ get hereCity() {
641
+ return readHereCity(this.getAttribute("here-city"));
642
+ }
643
+ set hereCity(value) {
644
+ if (value === true)
645
+ this.setAttribute("here-city", "");
646
+ else if (value === false)
647
+ this.removeAttribute("here-city");
648
+ else {
649
+ const km = readHereCity(String(value));
650
+ if (km === false)
651
+ this.removeAttribute("here-city");
652
+ else
653
+ this.setAttribute("here-city", String(km));
654
+ }
655
+ }
656
+ /** The cities for `here-city`, asked for only when the attribute is on. */
657
+ #openHereCity() {
658
+ const host = createHereCity({
659
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
660
+ onChange: () => {
661
+ if (this.isConnected)
662
+ this.#applyPlaces();
663
+ },
664
+ onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-here-city-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
665
+ });
666
+ host.setLimit(readHereCity(this.getAttribute("here-city")));
667
+ return host;
668
+ }
669
+ /** Hand the places to the layer, with a here marker's city name when one is known, and draw once. */
670
+ #applyPlaces() {
671
+ const layer = this.#placeLayer;
672
+ if (!layer)
673
+ return;
674
+ layer.set(this.#here?.named(this.#placeList) ?? this.#placeList);
675
+ this.#gate?.soon();
676
+ }
677
+ /**
678
+ * A route between two places (the attribute `route`, `lon,lat,lon,lat`). Null, the default, draws none. The line is the WGS84 geodesic, split at the date line, and it turns with the Earth.
679
+ * Setting the property writes the attribute. Nothing is drawn again at rest: the line is drawn with the picture, and only when the route or the view changes.
680
+ */
681
+ get route() {
682
+ return readRoute(this.getAttribute("route"));
683
+ }
684
+ set route(value) {
685
+ if (!value)
686
+ this.removeAttribute("route");
687
+ else
688
+ this.setAttribute("route", routeText(value));
689
+ }
690
+ /** The distance, bearings and flight-time estimate for `route`, or null when none is set. The flight time assumes 900 km/h. */
691
+ get routeInfo() {
692
+ const route = this.route;
693
+ return route ? routeLeg(route.from, route.to) : null;
694
+ }
607
695
  /**
608
696
  * Turn the Earth so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom
609
697
  * and pan stay. The place is named by its `id`, or by its label in any case. The tilt is held to 90 degrees either way, so a place more than 90 degrees of latitude from `center` comes as near the middle
@@ -1000,9 +1088,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
1000
1088
  bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
1001
1089
  sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
1002
1090
  places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
1091
+ hereCity: this.#here?.stats ?? { on: false, maxKm: 0, loaded: false, pending: false },
1003
1092
  cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
1004
1093
  borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
1005
1094
  grid: { ...this.#model.grid.stats },
1095
+ route: { ...this.#model.route.stats },
1006
1096
  countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
1007
1097
  };
1008
1098
  }
@@ -0,0 +1,32 @@
1
+ import type * as THREE from "three";
2
+ import type { ThreeParts } from "../realistic/textures.ts";
3
+ import type { GeoPoint } from "../types.ts";
4
+ export interface RouteStats {
5
+ on: boolean;
6
+ kilometres: number;
7
+ greatCircleKm: number;
8
+ flightHours: number;
9
+ }
10
+ export interface RouteState {
11
+ ends: {
12
+ from: GeoPoint;
13
+ to: GeoPoint;
14
+ } | null;
15
+ version: number;
16
+ failed: boolean;
17
+ stats: RouteStats;
18
+ }
19
+ export declare const newRouteState: () => RouteState;
20
+ /** Put a route on the model. Returns false when it did not change, so the element does not ask for a frame. */
21
+ export declare function applyRoute(state: RouteState, ends: {
22
+ from: GeoPoint;
23
+ to: GeoPoint;
24
+ } | null): boolean;
25
+ export interface RouteLayer {
26
+ sync(): void;
27
+ dispose(): void;
28
+ }
29
+ /**
30
+ * The route under `parent` (the group that turns with the Earth). Needs `LineSegments`, as the grid does.
31
+ */
32
+ export declare function createRouteLayer(three: ThreeParts, parent: THREE.Object3D, state: RouteState): RouteLayer;
@@ -0,0 +1,74 @@
1
+ import { routeLeg, routePoints } from "../route.js";
2
+ /** How far above the ground the line sits, in Earth radii: over the grid and the sphere's facets. */
3
+ const ROUTE_RADIUS = 1.003;
4
+ const ROUTE_COLOUR = 0x7df9ff;
5
+ export const newRouteState = () => ({ ends: null, version: 0, failed: false, stats: { on: false, kilometres: 0, greatCircleKm: 0, flightHours: 0 } });
6
+ const same = (a, b) => a === b || (a !== null && b !== null && a.from.lon === b.from.lon && a.from.lat === b.from.lat && a.to.lon === b.to.lon && a.to.lat === b.to.lat);
7
+ /** Put a route on the model. Returns false when it did not change, so the element does not ask for a frame. */
8
+ export function applyRoute(state, ends) {
9
+ if (same(state.ends, ends))
10
+ return false;
11
+ state.ends = ends;
12
+ state.version += 1;
13
+ const leg = ends ? routeLeg(ends.from, ends.to) : null;
14
+ state.stats = { on: leg !== null, kilometres: leg?.kilometres ?? 0, greatCircleKm: leg?.greatCircleKm ?? 0, flightHours: leg?.flightHours ?? 0 };
15
+ return true;
16
+ }
17
+ const positionsOf = (from, to) => {
18
+ const points = routePoints(from, to, 96);
19
+ if (points.length < 2)
20
+ return null;
21
+ const out = new Float32Array((points.length - 1) * 6);
22
+ const put = (at, place) => {
23
+ const lat = (place.lat * Math.PI) / 180;
24
+ const lon = (place.lon * Math.PI) / 180;
25
+ const c = Math.cos(lat) * ROUTE_RADIUS;
26
+ out[at] = c * Math.sin(lon);
27
+ out[at + 1] = Math.sin(lat) * ROUTE_RADIUS;
28
+ out[at + 2] = c * Math.cos(lon);
29
+ };
30
+ for (let i = 0; i < points.length - 1; i += 1) {
31
+ put(i * 6, points[i]);
32
+ put(i * 6 + 3, points[i + 1]);
33
+ }
34
+ return out;
35
+ };
36
+ /**
37
+ * The route under `parent` (the group that turns with the Earth). Needs `LineSegments`, as the grid does.
38
+ */
39
+ export function createRouteLayer(three, parent, state) {
40
+ const Lines = three.LineSegments;
41
+ if (!Lines)
42
+ throw new Error("the three.js handed over has no LineSegments, which the route needs");
43
+ const geometry = new three.BufferGeometry();
44
+ const material = new three.LineBasicMaterial({ color: ROUTE_COLOUR, transparent: true, opacity: 0.95, depthWrite: false });
45
+ const line = new Lines(geometry, material);
46
+ line.visible = false;
47
+ line.frustumCulled = false;
48
+ line.renderOrder = 2;
49
+ parent.add(line);
50
+ let built = -1;
51
+ return {
52
+ sync() {
53
+ if (built === state.version)
54
+ return;
55
+ built = state.version;
56
+ const ends = state.ends;
57
+ const positions = ends ? positionsOf(ends.from, ends.to) : null;
58
+ if (!positions) {
59
+ line.visible = false;
60
+ return;
61
+ }
62
+ // let the renderer free the buffer of the line it had, so changing the route leaves the GPU objects as they were
63
+ geometry.dispose();
64
+ geometry.setAttribute("position", new three.BufferAttribute(positions, 3));
65
+ geometry.computeBoundingSphere();
66
+ line.visible = true;
67
+ },
68
+ dispose() {
69
+ parent.remove(line);
70
+ geometry.dispose();
71
+ material.dispose();
72
+ },
73
+ };
74
+ }
@@ -0,0 +1,171 @@
1
+ import type { GeoPoint } from "./types.ts";
2
+ /**
3
+ * WGS84 equatorial radius, metres (NIMA TR8350.2).
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { WGS84_A_M } from "@johnmorrisdotca/chikyu-earth";
8
+ *
9
+ * console.log(WGS84_A_M);
10
+ * ```
11
+ */
12
+ export declare const WGS84_A_M = 6378137;
13
+ /**
14
+ * WGS84 flattening (NIMA TR8350.2).
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { WGS84_F } from "@johnmorrisdotca/chikyu-earth";
19
+ *
20
+ * console.log(WGS84_F.toFixed(12));
21
+ * ```
22
+ */
23
+ export declare const WGS84_F: number;
24
+ /**
25
+ * Mean Earth radius, kilometres, the same sphere the city distances use.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { MEAN_RADIUS_KM } from "@johnmorrisdotca/chikyu-earth";
30
+ *
31
+ * console.log(MEAN_RADIUS_KM);
32
+ * ```
33
+ */
34
+ export declare const MEAN_RADIUS_KM = 6371.0088;
35
+ /**
36
+ * The speed a flight-time estimate assumes, in kilometres an hour: a jet's cruise, with no wind, climb or holding.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { FLIGHT_SPEED_KM_H } from "@johnmorrisdotca/chikyu-earth";
41
+ *
42
+ * console.log(FLIGHT_SPEED_KM_H);
43
+ * ```
44
+ */
45
+ export declare const FLIGHT_SPEED_KM_H = 900;
46
+ /**
47
+ * The distance and the bearings between two places.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import type { RouteLeg } from "@johnmorrisdotca/chikyu-earth";
52
+ *
53
+ * const none: RouteLeg | null = null;
54
+ * console.log(none);
55
+ * ```
56
+ */
57
+ export interface RouteLeg {
58
+ /** Geodesic distance on WGS84, kilometres. The great-circle distance when the geodesic did not converge. */
59
+ kilometres: number;
60
+ /** Great-circle distance on a sphere of {@link MEAN_RADIUS_KM}, kilometres. */
61
+ greatCircleKm: number;
62
+ /** Degrees clockwise from north, 0 to 360, at the start. */
63
+ initialBearing: number;
64
+ /** Degrees clockwise from north, 0 to 360, at the end. */
65
+ finalBearing: number;
66
+ /** Hours at {@link FLIGHT_SPEED_KM_H}. */
67
+ flightHours: number;
68
+ /** The point halfway along the geodesic (or the great circle, when the geodesic did not converge). */
69
+ midpoint: GeoPoint;
70
+ /** False when Vincenty's formula did not converge (nearly antipodal): the distance is then the great circle. */
71
+ exact: boolean;
72
+ }
73
+ /**
74
+ * The great-circle distance, kilometres, on a sphere of {@link MEAN_RADIUS_KM}. The same angle `trackSteps` uses between two unit vectors.
75
+ *
76
+ * @param from - The start, degrees.
77
+ * @param to - The end, degrees.
78
+ * @returns The distance, or null when a place is not on the Earth.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * import { greatCircleKm } from "@johnmorrisdotca/chikyu-earth";
83
+ *
84
+ * console.log(greatCircleKm({ lon: 0, lat: 0 }, { lon: 0, lat: 0 }));
85
+ * ```
86
+ */
87
+ export declare function greatCircleKm(from: GeoPoint, to: GeoPoint): number | null;
88
+ /**
89
+ * Distance, bearings, midpoint and a flight-time estimate between two places. The distance quoted is the WGS84 geodesic.
90
+ * The flight time is that distance at {@link FLIGHT_SPEED_KM_H}, an estimate with no wind.
91
+ *
92
+ * @param from - The start, degrees.
93
+ * @param to - The end, degrees.
94
+ * @returns The leg, or null when a place is not on the Earth.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import { routeLeg } from "@johnmorrisdotca/chikyu-earth";
99
+ *
100
+ * const leg = routeLeg({ lon: 0, lat: 0 }, { lon: 1, lat: 0 });
101
+ * console.log(leg?.kilometres.toFixed(3), leg?.initialBearing);
102
+ * ```
103
+ */
104
+ export declare function routeLeg(from: GeoPoint, to: GeoPoint): RouteLeg | null;
105
+ /**
106
+ * Points along the geodesic from `from` to `to`, including both ends. `count` is how many (2 when they are the same place, 64 when left out).
107
+ * When the geodesic does not converge, the points are the great circle (`trackSteps`).
108
+ *
109
+ * @param from - The start.
110
+ * @param to - The end.
111
+ * @param count - How many points, at least 2.
112
+ * @returns The points, or an empty list when a place is not on the Earth.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * import { routePoints } from "@johnmorrisdotca/chikyu-earth";
117
+ *
118
+ * console.log(routePoints({ lon: 0, lat: 0 }, { lon: 1, lat: 0 }, 3).length);
119
+ * ```
120
+ */
121
+ export declare function routePoints(from: GeoPoint, to: GeoPoint, count?: number): GeoPoint[];
122
+ /**
123
+ * The runs of a route after it is split at the date line, so a flat map draws two pieces instead of a line across the world.
124
+ * A run that does not cross is one piece. Uses `splitDateLine`.
125
+ *
126
+ * @param points - Points in order along the route, including the ends.
127
+ * @returns One list of points per piece.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { routeRuns } from "@johnmorrisdotca/chikyu-earth";
132
+ *
133
+ * console.log(routeRuns([{ lon: 179, lat: 0 }, { lon: -179, lat: 0 }]).length);
134
+ * ```
135
+ */
136
+ export declare function routeRuns(points: readonly GeoPoint[]): GeoPoint[][];
137
+ /**
138
+ * Read the `route` attribute: `lon,lat,lon,lat`. Anything else is no route.
139
+ *
140
+ * @param value - The attribute's text, or null.
141
+ * @returns The two places, or null.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * import { readRoute } from "@johnmorrisdotca/chikyu-earth";
146
+ *
147
+ * console.log(readRoute("139.69,35.69,-0.13,51.51")?.from.lat);
148
+ * console.log(readRoute("no"));
149
+ * ```
150
+ */
151
+ export declare function readRoute(value: string | null | undefined): {
152
+ from: GeoPoint;
153
+ to: GeoPoint;
154
+ } | null;
155
+ /**
156
+ * The `route` attribute for two places, four decimals.
157
+ *
158
+ * @param route - The two places.
159
+ * @returns `lon,lat,lon,lat`.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * import { routeText } from "@johnmorrisdotca/chikyu-earth";
164
+ *
165
+ * console.log(routeText({ from: { lon: 1, lat: 2 }, to: { lon: 3, lat: 4 } }));
166
+ * ```
167
+ */
168
+ export declare function routeText(route: {
169
+ from: GeoPoint;
170
+ to: GeoPoint;
171
+ }): string;