@johnmorrisdotca/chikyu-earth 0.60.2 → 0.61.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 +8 -1
- package/README.md +2 -2
- package/dist/markers/index.d.ts +2 -2
- package/dist/markers/index.js +1 -1
- package/dist/markers/place-layer.d.ts +48 -2
- package/dist/markers/place-layer.js +135 -16
- package/dist/markers/places.d.ts +70 -4
- package/dist/markers/places.js +70 -7
- package/dist/realistic/element-base.d.ts +36 -1
- package/dist/realistic/element-base.js +63 -7
- package/dist/space/element-base.d.ts +36 -1
- package/dist/space/element-base.js +61 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.61.0 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
- **Places get a press event, a size and look each, layers, and names that give way to cities** (MODULES-1578). All of it is optional and a page that uses none of it draws as before.
|
|
6
|
+
- **Press.** A press on a place's marker or ring sends `chikyu-place-click` from `<chikyu-space>` and `<chikyu-earth-realistic>` with `detail: { id, kind, layer?, label?, lon, lat, x, y }` (`PlaceClickDetail`), so a page need not read the markers' boxes. A group of several places sends nothing.
|
|
7
|
+
- **Size and look.** A place may have `size: "small"` (a stick about half as long, a ring about 30 per cent smaller) and `look` (`beam`, `pin` or `ring`, over `places-look`).
|
|
8
|
+
- **Layers.** A place may have a `layer`; `place-layers` (`placeLayers`, `setPlaceLayer(name, shown)`) is a JSON object of a layer's name to true or false, and only `false` hides a layer's places, wholly (not drawn, named, grouped or pressable). `stats.places.hidden` counts them. `readPlaceLayers` and `shownPlaces` are the pure parts.
|
|
9
|
+
- **Names.** A place with `namePriority: "low"` has its name laid after the cities' names and left out where a city's name lies; the marker stays. The sea, country and star names keep clear of it once laid.
|
|
10
|
+
- **Tests and docs.** Unit tests for each part, `e2e/places.gl.ts` (a press, a layer, a look, a name giving way to Tokyo's, on both elements), and the places guide in English and Japanese.
|
|
4
11
|
|
|
5
12
|
## 0.60.2 - 2026-11-17
|
|
6
13
|
|
package/README.md
CHANGED
|
@@ -252,7 +252,7 @@ console.log(bodyLabelText("en"), bodyLabelText("ja"), BODY_LABEL_ATTRIBUTES.leng
|
|
|
252
252
|
|
|
253
253
|
`route` on `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` draws the line between two places (`lon,lat,lon,lat`). `routeInfo` gives the accurate distance on the Earth's real shape, the great-circle distance, the bearings and a flight time at 900 km/h. The line is off until it is set, and nothing is drawn at rest: [guide](docs/guides/routes.md).
|
|
254
254
|
|
|
255
|
-
`places` on `<chikyu-space>` and `<chikyu-earth-realistic>` marks places on the Earth, each a beam, a pin or a ring (`places-look`) standing out of the ground, turning with the Earth, hidden on its far side and dimmer at night: `kind: "here"` for the reader's own place (brighter, with a quiet pulse) and favourites, quieter, each with an optional `color`. Up to 5,000: the first 32 in sight stand up with their names, the rest are rings in one draw call, crowds are gathered with their count, and `goToPlace(id)` turns the view to one. Names never overlap; nothing is drawn at rest. `here-city` (off by default) names a `here` place with the nearest city within 100 km, in the page's language; kuni is loaded only then. The package never asks for the reader's place and stores or sends nothing: the page asks on a press and rounds the place with `nearby` first: [guide](docs/guides/places.md).
|
|
255
|
+
`places` on `<chikyu-space>` and `<chikyu-earth-realistic>` marks places on the Earth, each a beam, a pin or a ring (`places-look`) standing out of the ground, turning with the Earth, hidden on its far side and dimmer at night: `kind: "here"` for the reader's own place (brighter, with a quiet pulse) and favourites, quieter, each with an optional `color`. Up to 5,000: the first 32 in sight stand up with their names, the rest are rings in one draw call, crowds are gathered with their count, and `goToPlace(id)` turns the view to one. Names never overlap; nothing is drawn at rest. Each place can have a `layer` (switched with `place-layers`), a `size` or `look` of its own and a `namePriority`, so a harbour is a short mark and its name gives way to a city's; a press on a place sends `chikyu-place-click` with its `id` and `kind`. `here-city` (off by default) names a `here` place with the nearest city within 100 km, in the page's language; kuni is loaded only then. The package never asks for the reader's place and stores or sends nothing: the page asks on a press and rounds the place with `nearby` first: [guide](docs/guides/places.md).
|
|
256
256
|
|
|
257
257
|
```html
|
|
258
258
|
<chikyu-space places='[{"id":"me","lon":-79.4,"lat":43.7,"label":"You are here","kind":"here"}]'></chikyu-space>
|
|
@@ -615,7 +615,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
615
615
|
|
|
616
616
|
## How to cite
|
|
617
617
|
|
|
618
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
618
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.61.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
619
619
|
|
|
620
620
|
GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
|
|
621
621
|
|
package/dist/markers/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export { project, projectAll, canvasRatio, type Pose } from "./project.ts";
|
|
|
3
3
|
export { clusterPoints, type Cluster } from "./cluster.ts";
|
|
4
4
|
export { placeLabels, type LabelItem, type Placement } from "./labels.ts";
|
|
5
5
|
export type { GroupInfo, MarkerEventDetail, MarkerIcon, MarkerInput } from "./types.ts";
|
|
6
|
-
export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces, type Place, type PlaceGroup, type PlaceKind, type PlaceLabelSpot, type PlaceLayout, type PlaceLayoutOptions, type PlaceLook, type PlaceShape, type PlaceView, type SurfacePoint } from "./places.ts";
|
|
6
|
+
export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaceLayers, readPlaces, shownPlaces, type Place, type PlaceGroup, type PlaceKind, type PlaceLabelSpot, type PlaceLayout, type PlaceLayoutOptions, type PlaceLook, type PlaceNamePriority, type PlaceShape, type PlaceSize, type PlaceView, type SurfacePoint } from "./places.ts";
|
|
7
7
|
export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, chooseHereCity, hereCityLabels, hereCountries, readHereCity, type HereCityHit, type HereCitySource, type HereTown } from "./here-city.ts";
|
|
8
|
-
export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.ts";
|
|
8
|
+
export { PLACE_DOTS, PLACE_MARKS, type PlaceClickDetail } from "./place-layer.ts";
|
package/dist/markers/index.js
CHANGED
|
@@ -4,6 +4,6 @@ export { attachMarkers } from "./layer.js";
|
|
|
4
4
|
export { project, projectAll, canvasRatio } from "./project.js";
|
|
5
5
|
export { clusterPoints } from "./cluster.js";
|
|
6
6
|
export { placeLabels } from "./labels.js";
|
|
7
|
-
export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces } from "./places.js";
|
|
7
|
+
export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaceLayers, readPlaces, shownPlaces } from "./places.js";
|
|
8
8
|
export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, chooseHereCity, hereCityLabels, hereCountries, readHereCity } from "./here-city.js";
|
|
9
9
|
export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GeoPoint } from "../types.ts";
|
|
2
2
|
import type { PlaceSpriteData } from "./place-sprites.ts";
|
|
3
|
-
import { type Place, type PlaceLook, type PlaceView } from "./places.ts";
|
|
3
|
+
import { type Place, type PlaceKind, type PlaceLook, type PlaceView } from "./places.ts";
|
|
4
4
|
/** A `places-look` attribute: one of `PLACE_LOOKS`, else `beam`. */
|
|
5
5
|
export declare const readPlaceLook: (value: string | null) => PlaceLook;
|
|
6
6
|
/** The places' look, for the element's own style sheet. Colours: `--chikyu-place-here` and `--chikyu-place-favourite` on the element or the page. */
|
|
@@ -53,17 +53,55 @@ type Box = {
|
|
|
53
53
|
width: number;
|
|
54
54
|
height: number;
|
|
55
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* What `chikyu-place-click` carries in `event.detail`: the place that was pressed, and where the press was in CSS pixels inside the element's box.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import type { PlaceClickDetail } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
62
|
+
*
|
|
63
|
+
* const on = (event: Event): void => {
|
|
64
|
+
* const { id, kind, layer } = (event as CustomEvent<PlaceClickDetail>).detail;
|
|
65
|
+
* console.log(id, kind, layer ?? "no layer");
|
|
66
|
+
* };
|
|
67
|
+
* console.log(typeof on);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export interface PlaceClickDetail {
|
|
71
|
+
id: string;
|
|
72
|
+
/** `here` or `favourite`. */
|
|
73
|
+
kind: PlaceKind;
|
|
74
|
+
/** The place's `layer`, when it has one. */
|
|
75
|
+
layer?: string;
|
|
76
|
+
label?: string;
|
|
77
|
+
lon: number;
|
|
78
|
+
lat: number;
|
|
79
|
+
/** Where the press was, in CSS pixels inside the element's box. */
|
|
80
|
+
x: number;
|
|
81
|
+
y: number;
|
|
82
|
+
}
|
|
83
|
+
/** The detail of `chikyu-place-click` for a pressed place. */
|
|
84
|
+
export declare const placeClick: (place: Place, x: number, y: number) => PlaceClickDetail;
|
|
56
85
|
/**
|
|
57
86
|
* The places' markers in one element: hand it the places and the look, and a view at each draw.
|
|
58
87
|
*/
|
|
59
88
|
export interface PlaceLayer {
|
|
60
89
|
set(places: readonly Place[]): void;
|
|
90
|
+
/** Which layers are shown: a layer's name to false hides every place of it (see {@link shownPlaces}). A layer not named is shown. */
|
|
91
|
+
layers: Readonly<Record<string, boolean>>;
|
|
61
92
|
look: PlaceLook;
|
|
62
93
|
/**
|
|
63
94
|
* Lay the places on the picture just drawn; `null` hides them (the Earth is not in the picture). `taken` is boxes other names use; `marks` are satellites to ring and name, after the places' names and
|
|
64
95
|
* never over them; `sun` is where the Sun is overhead (null when the whole Earth is lit), for the night side's dimmer markers.
|
|
65
96
|
*/
|
|
66
97
|
frame(view: PlaceView | null, taken?: readonly Box[], marks?: readonly SatelliteMark[], sun?: GeoPoint | null): void;
|
|
98
|
+
/**
|
|
99
|
+
* Lay the names of the places whose `namePriority` is `low`, after the layers that come before them: `taken` gives those layers' boxes (the cities' names), asked for only when there is a name to lay, and a name with no free place is left out. Call it after each `frame`
|
|
100
|
+
* and again when those layers change; with no such place it does nothing.
|
|
101
|
+
*/
|
|
102
|
+
late(taken?: () => readonly Box[]): void;
|
|
103
|
+
/** The place under a point of the element (CSS pixels from its top left) in the last picture: a marker's stick or foot, or a ring, within a few pixels; null when there is none. A group of several is not a place. */
|
|
104
|
+
pick(x: number, y: number): Place | null;
|
|
67
105
|
/** The rings the picture draws for the places that are not markers of their own, as of the last `frame`; null while there are none. */
|
|
68
106
|
readonly sprites: PlaceSpriteData | null;
|
|
69
107
|
/**
|
|
@@ -79,6 +117,7 @@ export interface PlaceLayer {
|
|
|
79
117
|
dimOccluded: boolean;
|
|
80
118
|
readonly stats: {
|
|
81
119
|
places: number;
|
|
120
|
+
hidden: number;
|
|
82
121
|
shown: number;
|
|
83
122
|
labels: number;
|
|
84
123
|
renders: number;
|
|
@@ -90,13 +129,20 @@ export interface PlaceLayer {
|
|
|
90
129
|
dots: number;
|
|
91
130
|
omitted: number;
|
|
92
131
|
};
|
|
93
|
-
/** The boxes the names and the markers' heads take in the picture just drawn, for other names to keep clear of. */
|
|
132
|
+
/** The boxes the names and the markers' heads take in the picture just drawn, for other names to keep clear of; the low-priority names, once `late` has laid them, are in it. */
|
|
94
133
|
readonly boxes: readonly {
|
|
95
134
|
left: number;
|
|
96
135
|
top: number;
|
|
97
136
|
width: number;
|
|
98
137
|
height: number;
|
|
99
138
|
}[];
|
|
139
|
+
/** The same without the low-priority names, which the cities' names are laid out after. */
|
|
140
|
+
readonly earlyBoxes: readonly {
|
|
141
|
+
left: number;
|
|
142
|
+
top: number;
|
|
143
|
+
width: number;
|
|
144
|
+
height: number;
|
|
145
|
+
}[];
|
|
100
146
|
dispose(): void;
|
|
101
147
|
}
|
|
102
148
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { placeLabels } from "./labels.js";
|
|
2
|
-
import { groupCell, groupPlaces, layoutPlaces, PLACE_LOOKS } from "./places.js";
|
|
2
|
+
import { groupCell, groupPlaces, layoutPlaces, PLACE_LOOKS, shownPlaces, SMALL_RING } from "./places.js";
|
|
3
3
|
/** A `places-look` attribute: one of `PLACE_LOOKS`, else `beam`. */
|
|
4
4
|
export const readPlaceLook = (value) => PLACE_LOOKS.includes(value ?? "") ? value : "beam";
|
|
5
5
|
/** The places' look, for the element's own style sheet. Colours: `--chikyu-place-here` and `--chikyu-place-favourite` on the element or the page. */
|
|
@@ -19,10 +19,10 @@ export const PLACE_STYLE = "#places{position:absolute;inset:0;overflow:hidden;po
|
|
|
19
19
|
".pl-head{position:absolute;left:-2.5px;top:-2.5px;width:5px;height:5px;border-radius:50%;background:#fff;box-shadow:0 0 6px 1px var(--c)}" +
|
|
20
20
|
".pl-mark[data-kind=favourite] .pl-stick{width:1.5px;opacity:.8}" +
|
|
21
21
|
".pl-mark[data-kind=favourite] .pl-head{opacity:.85}" +
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
22
|
+
".pl-mark[data-look=pin] .pl-stick{background:var(--c);box-shadow:none;width:1.5px}" +
|
|
23
|
+
".pl-mark[data-look=pin] .pl-head{left:-4px;top:-4px;width:8px;height:8px;background:var(--c);box-shadow:0 0 0 1.5px rgba(4,10,20,.75)}" +
|
|
24
|
+
".pl-mark[data-look=pin] .pl-ring{box-shadow:none;background:none;opacity:.7}" +
|
|
25
|
+
".pl-mark[data-look=ring] .pl-stick,.pl-mark[data-look=ring] .pl-head{display:none}" +
|
|
26
26
|
".pl-name{position:absolute;left:0;top:0;box-sizing:border-box;padding:1px 6px;font:600 11px/16px system-ui,-apple-system,'Segoe UI',sans-serif;letter-spacing:.04em;white-space:nowrap;color:#eefcff;background:rgba(4,10,20,.72);border:1px solid color-mix(in srgb,var(--c) 60%,transparent);border-radius:3px;will-change:transform;--c:var(--chikyu-place-favourite,#ffd27a)}" +
|
|
27
27
|
".pl-name[data-kind=here]{--c:var(--chikyu-place-here,#7df9ff);color:#fff}" +
|
|
28
28
|
".pl-name[data-kind=group]{padding:0 5px;font-size:10px;line-height:14px;border-radius:7px;background:rgba(4,10,20,.6)}" +
|
|
@@ -76,6 +76,17 @@ const LIMB = 0.12;
|
|
|
76
76
|
const MARGIN = 60;
|
|
77
77
|
const RING = { here: 9, favourite: 6 };
|
|
78
78
|
const FALLBACK = { here: "#7df9ff", favourite: "#ffd27a" };
|
|
79
|
+
/** The detail of `chikyu-place-click` for a pressed place. */
|
|
80
|
+
export const placeClick = (place, x, y) => {
|
|
81
|
+
const detail = { id: place.id, kind: place.kind === "here" ? "here" : "favourite", lon: place.lon, lat: place.lat, x, y };
|
|
82
|
+
if (place.layer)
|
|
83
|
+
detail.layer = place.layer;
|
|
84
|
+
if (place.label)
|
|
85
|
+
detail.label = place.label;
|
|
86
|
+
return detail;
|
|
87
|
+
};
|
|
88
|
+
/** How far from a place's mark a press still counts as on it, in CSS pixels, as for a satellite's dot. */
|
|
89
|
+
const PRESS_REACH = 12;
|
|
79
90
|
/**
|
|
80
91
|
* Make the places' layer in a box of an element's shadow root (the box is `#places`, styled by {@link PLACE_STYLE}).
|
|
81
92
|
*
|
|
@@ -86,12 +97,14 @@ export function createPlaceLayer(box) {
|
|
|
86
97
|
const doc = box.ownerDocument;
|
|
87
98
|
box.setAttribute("aria-hidden", "true");
|
|
88
99
|
box.dataset["look"] = "beam";
|
|
100
|
+
let everything = [];
|
|
89
101
|
let places = [];
|
|
102
|
+
let switches = {};
|
|
90
103
|
let look = "beam";
|
|
91
104
|
const marks = [];
|
|
92
105
|
const names = [];
|
|
93
106
|
const sizes = new Map();
|
|
94
|
-
const stats = { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 };
|
|
107
|
+
const stats = { places: 0, hidden: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 };
|
|
95
108
|
let grouping = true;
|
|
96
109
|
let ringsInPicture = true;
|
|
97
110
|
let dimOccluded = true;
|
|
@@ -102,6 +115,15 @@ export function createPlaceLayer(box) {
|
|
|
102
115
|
// the ring sizes written last, so a frame that changes none does not copy the buffer
|
|
103
116
|
let shapeHeld = new Float32Array(0);
|
|
104
117
|
let boxes = [];
|
|
118
|
+
let earlyBoxes = [];
|
|
119
|
+
// the names that wait for the layers before them, and the last picture's markers, for `late` and `pick`
|
|
120
|
+
let lateItems = [];
|
|
121
|
+
let lateOwners = [];
|
|
122
|
+
let lateFrom = 0;
|
|
123
|
+
let earlyLabels = 0;
|
|
124
|
+
let lastView = null;
|
|
125
|
+
let lastShapes = [];
|
|
126
|
+
let lastOwn = [];
|
|
105
127
|
const rings = [];
|
|
106
128
|
const measures = [];
|
|
107
129
|
// the groups of the places for the cell they were made with, and the rings' data the picture reads
|
|
@@ -176,7 +198,7 @@ export function createPlaceLayer(box) {
|
|
|
176
198
|
head.className = "pl-head";
|
|
177
199
|
root.append(disc, stick, head);
|
|
178
200
|
box.append(root);
|
|
179
|
-
mark = { root, disc, stick, head, kind: "", ring: 0, color: "" };
|
|
201
|
+
mark = { root, disc, stick, head, kind: "", look: "", ring: 0, color: "" };
|
|
180
202
|
marks[i] = mark;
|
|
181
203
|
}
|
|
182
204
|
return mark;
|
|
@@ -317,6 +339,12 @@ export function createPlaceLayer(box) {
|
|
|
317
339
|
stats.groups = 0;
|
|
318
340
|
stats.sprites = 0;
|
|
319
341
|
stats.dots = 0;
|
|
342
|
+
lastView = null;
|
|
343
|
+
lastShapes = [];
|
|
344
|
+
lastOwn = [];
|
|
345
|
+
lateItems = [];
|
|
346
|
+
lateOwners = [];
|
|
347
|
+
earlyLabels = 0;
|
|
320
348
|
if (sprites && sprites.shapes.some((v) => v !== 0)) {
|
|
321
349
|
sprites.shapes.fill(0);
|
|
322
350
|
sprites.shapesVersion += 1;
|
|
@@ -324,11 +352,28 @@ export function createPlaceLayer(box) {
|
|
|
324
352
|
};
|
|
325
353
|
return {
|
|
326
354
|
set(next) {
|
|
327
|
-
|
|
355
|
+
everything = next;
|
|
356
|
+
lastView = null;
|
|
357
|
+
places = shownPlaces(next, switches);
|
|
328
358
|
stats.places = next.length;
|
|
329
|
-
|
|
359
|
+
stats.hidden = next.length - places.length;
|
|
360
|
+
if (places.length === 0) {
|
|
330
361
|
groups = [];
|
|
331
|
-
groupedFor =
|
|
362
|
+
groupedFor = places;
|
|
363
|
+
sprites = null;
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
get layers() {
|
|
367
|
+
return switches;
|
|
368
|
+
},
|
|
369
|
+
set layers(value) {
|
|
370
|
+
switches = value;
|
|
371
|
+
lastView = null;
|
|
372
|
+
places = shownPlaces(everything, switches);
|
|
373
|
+
stats.hidden = everything.length - places.length;
|
|
374
|
+
if (places.length === 0) {
|
|
375
|
+
groups = [];
|
|
376
|
+
groupedFor = places;
|
|
332
377
|
sprites = null;
|
|
333
378
|
}
|
|
334
379
|
},
|
|
@@ -368,6 +413,7 @@ export function createPlaceLayer(box) {
|
|
|
368
413
|
if (places.length > 0)
|
|
369
414
|
stats.renders += 1;
|
|
370
415
|
boxes = [];
|
|
416
|
+
earlyBoxes = [];
|
|
371
417
|
return;
|
|
372
418
|
}
|
|
373
419
|
stats.renders += 1;
|
|
@@ -399,7 +445,10 @@ export function createPlaceLayer(box) {
|
|
|
399
445
|
const chosen = [...singles.filter((g) => places[groups[g].members[0]].kind === "here"), ...singles.filter((g) => places[groups[g].members[0]].kind !== "here")].slice(0, PLACE_MARKS);
|
|
400
446
|
const own = chosen.map((g) => places[groups[g].members[0]]);
|
|
401
447
|
measureAll(own);
|
|
402
|
-
const layout = layoutPlaces(own, view, look, { size: (place) => size(place), taken, sun });
|
|
448
|
+
const layout = layoutPlaces(own, view, look, { size: (place) => (place.namePriority === "low" ? null : size(place)), taken, sun });
|
|
449
|
+
lastView = view;
|
|
450
|
+
lastShapes = layout.shapes;
|
|
451
|
+
lastOwn = own;
|
|
403
452
|
// favourites first, so a `here` marker is drawn over them
|
|
404
453
|
const order = [...layout.shapes].sort((a, b) => (own[a.index].kind === "here" ? 1 : 0) - (own[b.index].kind === "here" ? 1 : 0));
|
|
405
454
|
for (const [i, shape] of order.entries()) {
|
|
@@ -410,6 +459,11 @@ export function createPlaceLayer(box) {
|
|
|
410
459
|
mark.kind = kind;
|
|
411
460
|
mark.root.dataset["kind"] = kind;
|
|
412
461
|
}
|
|
462
|
+
const shown = place.look ?? look;
|
|
463
|
+
if (mark.look !== shown) {
|
|
464
|
+
mark.look = shown;
|
|
465
|
+
mark.root.dataset["look"] = shown;
|
|
466
|
+
}
|
|
413
467
|
if (mark.ring !== shape.ring) {
|
|
414
468
|
mark.ring = shape.ring;
|
|
415
469
|
mark.root.style.setProperty("--r", `${shape.ring}px`);
|
|
@@ -433,6 +487,16 @@ export function createPlaceLayer(box) {
|
|
|
433
487
|
}
|
|
434
488
|
hideFrom(marks.map((m) => m.root), order.length);
|
|
435
489
|
const nightOf = new Map(layout.shapes.map((shape) => [shape.index, shape.night]));
|
|
490
|
+
lateItems = [];
|
|
491
|
+
lateOwners = [];
|
|
492
|
+
for (const shape of layout.shapes) {
|
|
493
|
+
const place = own[shape.index];
|
|
494
|
+
const found = place.namePriority === "low" ? size(place) : null;
|
|
495
|
+
if (!found)
|
|
496
|
+
continue;
|
|
497
|
+
lateItems.push({ x: shape.tipX, y: shape.tipY, r: (place.look ?? look) === "ring" ? shape.ring : 3, w: found.width, h: found.height, priority: 0 });
|
|
498
|
+
lateOwners.push(place);
|
|
499
|
+
}
|
|
436
500
|
for (const [i, spot] of layout.labels.entries()) {
|
|
437
501
|
const place = own[spot.index];
|
|
438
502
|
showName(nameAt(i), place.label ?? "", place.kind === "here" ? "here" : "favourite", spot.left, spot.top, place.color, (nightOf.get(spot.index) ?? 0) > 0.5);
|
|
@@ -467,7 +531,7 @@ export function createPlaceLayer(box) {
|
|
|
467
531
|
const group = groups[g];
|
|
468
532
|
const n = group.members.length;
|
|
469
533
|
const first = places[group.members[0]];
|
|
470
|
-
const ring = n > 1 ? Math.min(14, 6 + 2.2 * Math.log2(n)) : RING[first.kind === "here" ? "here" : "favourite"];
|
|
534
|
+
const ring = n > 1 ? Math.min(14, 6 + 2.2 * Math.log2(n)) : RING[first.kind === "here" ? "here" : "favourite"] * (first.size === "small" ? SMALL_RING : 1);
|
|
471
535
|
shapes[g * 2] = ring;
|
|
472
536
|
shapes[g * 2 + 1] = n > 1 ? 0.3 : 0;
|
|
473
537
|
if (fallback) {
|
|
@@ -553,14 +617,17 @@ export function createPlaceLayer(box) {
|
|
|
553
617
|
used += 1;
|
|
554
618
|
}
|
|
555
619
|
hideFrom(names, used);
|
|
556
|
-
|
|
620
|
+
earlyBoxes = busy.slice(taken.length);
|
|
557
621
|
for (const spot of placed)
|
|
558
|
-
|
|
622
|
+
earlyBoxes.push({ left: spot.left, top: spot.top, width: items[spot.item].w, height: items[spot.item].h });
|
|
559
623
|
for (const shape of layout.shapes)
|
|
560
|
-
|
|
624
|
+
earlyBoxes.push({ left: shape.tipX - 5, top: shape.tipY - 5, width: 10, height: 10 });
|
|
561
625
|
// the ring round each satellite that can be seen: other layers' names keep off it as they keep off its name
|
|
562
626
|
for (const mark of seen)
|
|
563
|
-
|
|
627
|
+
earlyBoxes.push({ left: mark.x - SATELLITE_RING, top: mark.y - SATELLITE_RING, width: SATELLITE_RING * 2, height: SATELLITE_RING * 2 });
|
|
628
|
+
boxes = earlyBoxes;
|
|
629
|
+
lateFrom = used;
|
|
630
|
+
earlyLabels = layout.labels.length;
|
|
564
631
|
stats.shown = shown;
|
|
565
632
|
stats.marks = order.length;
|
|
566
633
|
stats.labels = layout.labels.length;
|
|
@@ -574,6 +641,58 @@ export function createPlaceLayer(box) {
|
|
|
574
641
|
get boxes() {
|
|
575
642
|
return boxes;
|
|
576
643
|
},
|
|
644
|
+
get earlyBoxes() {
|
|
645
|
+
return earlyBoxes;
|
|
646
|
+
},
|
|
647
|
+
late(taken) {
|
|
648
|
+
if (lateItems.length === 0 || !lastView)
|
|
649
|
+
return;
|
|
650
|
+
const placed = placeLabels(lateItems, lastView.width, lastView.height, 16, 64, [...(taken?.() ?? []), ...earlyBoxes]);
|
|
651
|
+
let at = lateFrom;
|
|
652
|
+
const added = [];
|
|
653
|
+
for (const spot of placed) {
|
|
654
|
+
const place = lateOwners[spot.item];
|
|
655
|
+
showName(nameAt(at), place.label ?? "", place.kind === "here" ? "here" : "favourite", spot.left, spot.top, place.color, false);
|
|
656
|
+
added.push({ left: spot.left, top: spot.top, width: lateItems[spot.item].w, height: lateItems[spot.item].h });
|
|
657
|
+
at += 1;
|
|
658
|
+
}
|
|
659
|
+
hideFrom(names, at);
|
|
660
|
+
boxes = [...earlyBoxes, ...added];
|
|
661
|
+
stats.labels = earlyLabels + placed.length;
|
|
662
|
+
},
|
|
663
|
+
pick(x, y) {
|
|
664
|
+
if (!lastView || !groupedFor)
|
|
665
|
+
return null;
|
|
666
|
+
const marked = new Set();
|
|
667
|
+
let best = null;
|
|
668
|
+
let near = PRESS_REACH;
|
|
669
|
+
for (const shape of lastShapes) {
|
|
670
|
+
const place = lastOwn[shape.index];
|
|
671
|
+
marked.add(place);
|
|
672
|
+
// the foot, or anywhere along the stick from the foot to its top
|
|
673
|
+
const dx = shape.tipX - shape.x;
|
|
674
|
+
const dy = shape.tipY - shape.y;
|
|
675
|
+
const along = dx === 0 && dy === 0 ? 0 : Math.max(0, Math.min(1, ((x - shape.x) * dx + (y - shape.y) * dy) / (dx * dx + dy * dy)));
|
|
676
|
+
const d = Math.hypot(x - (shape.x + dx * along), y - (shape.y + dy * along));
|
|
677
|
+
if (d < near || (d === near && best === null)) {
|
|
678
|
+
best = place;
|
|
679
|
+
near = d;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
for (const group of groups) {
|
|
683
|
+
if (group.members.length !== 1)
|
|
684
|
+
continue;
|
|
685
|
+
const place = groupedFor[group.members[0]];
|
|
686
|
+
if (marked.has(place) || !lastView.at(group.lon, group.lat, point) || point.facing <= EDGE)
|
|
687
|
+
continue;
|
|
688
|
+
const d = Math.hypot(x - point.x, y - point.y);
|
|
689
|
+
if (d < near) {
|
|
690
|
+
best = place;
|
|
691
|
+
near = d;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return best;
|
|
695
|
+
},
|
|
577
696
|
dispose() {
|
|
578
697
|
watcher?.disconnect();
|
|
579
698
|
fonts?.removeEventListener?.("loadingdone", refit);
|
package/dist/markers/places.d.ts
CHANGED
|
@@ -38,6 +38,14 @@ export interface Place {
|
|
|
38
38
|
kind?: PlaceKind;
|
|
39
39
|
/** A CSS colour for this place alone (`#e8475f`, `rgb(...)`, `hsl(...)` or a colour's name); left out, the kind's colour. */
|
|
40
40
|
color?: string;
|
|
41
|
+
/** A set of places (spaceports, harbours) the page shows or hides together with `place-layers`; left out, the place is always shown. */
|
|
42
|
+
layer?: string;
|
|
43
|
+
/** `small` draws a shorter, narrower mark; left out, the kind's own size. */
|
|
44
|
+
size?: PlaceSize;
|
|
45
|
+
/** How this place is drawn, over `places-look`; left out, `places-look`. */
|
|
46
|
+
look?: PlaceLook;
|
|
47
|
+
/** `low` lays this place's name after the cities' names, so it is shown only where it lies over none of them; left out (`high`), it is laid before them. */
|
|
48
|
+
namePriority?: PlaceNamePriority;
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
43
51
|
* How a place is drawn: `beam` (a light rising out of the ground with a ring at its foot), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground).
|
|
@@ -62,6 +70,30 @@ export type PlaceLook = "beam" | "pin" | "ring";
|
|
|
62
70
|
* ```
|
|
63
71
|
*/
|
|
64
72
|
export declare const PLACE_LOOKS: readonly PlaceLook[];
|
|
73
|
+
/**
|
|
74
|
+
* How big a place's mark is: `normal` (the default) or `small`, a shorter, narrower stick and a smaller ring, so a harbour can stand beside a city and "You are here" stays the tall beam.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import type { PlaceSize } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
79
|
+
*
|
|
80
|
+
* const size: PlaceSize = "small";
|
|
81
|
+
* console.log(size);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export type PlaceSize = "normal" | "small";
|
|
85
|
+
/**
|
|
86
|
+
* Where a place's name is laid among the others: `high` (the default) before the cities' names, which then keep clear of it, or `low`, after them, so the name is left out where a city's name is.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import type { PlaceNamePriority } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
91
|
+
*
|
|
92
|
+
* const priority: PlaceNamePriority = "low";
|
|
93
|
+
* console.log(priority);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export type PlaceNamePriority = "high" | "low";
|
|
65
97
|
/**
|
|
66
98
|
* The most places one element draws; the rest of a longer list are left out.
|
|
67
99
|
*
|
|
@@ -200,10 +232,13 @@ export interface PlaceLayoutOptions {
|
|
|
200
232
|
/** Where the Sun is overhead, for each shape's `night`; left out (or null), every place is in daylight. */
|
|
201
233
|
sun?: GeoPoint | null;
|
|
202
234
|
}
|
|
235
|
+
/** What a `small` place's stick and ring are of the kind's own. */
|
|
236
|
+
export declare const SMALL_LENGTH = 0.55;
|
|
237
|
+
export declare const SMALL_RING = 0.7;
|
|
203
238
|
/**
|
|
204
239
|
* The places of a list a page handed over, made safe to draw: each needs a longitude from -180 to 180 and a latitude from -90 to 90; one without an `id` is given its place in the list, a
|
|
205
|
-
* label is cut to 80 letters, a kind that is not `here` is `favourite`, and a colour is kept only when it is a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name.
|
|
206
|
-
* and at most {@link MAX_PLACES} are kept.
|
|
240
|
+
* label is cut to 80 letters, a kind that is not `here` is `favourite`, and a colour is kept only when it is a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. A `layer` is cut to 40 letters,
|
|
241
|
+
* a `size` is kept only when it is `small`, a `look` only when it is one of {@link PLACE_LOOKS} and a `namePriority` only when it is `low`. Anything else is left out, and at most {@link MAX_PLACES} are kept.
|
|
207
242
|
*
|
|
208
243
|
* @param list - What the page gave: an array of places, or anything.
|
|
209
244
|
* @returns The places to draw.
|
|
@@ -212,7 +247,7 @@ export interface PlaceLayoutOptions {
|
|
|
212
247
|
* ```ts
|
|
213
248
|
* import { cleanPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
214
249
|
*
|
|
215
|
-
* console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris", color: "#e8475f" }, { lon: 500, lat: 0 }]));
|
|
250
|
+
* console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris", color: "#e8475f" }, { lon: 500, lat: 0 }, { id: "yvr", lon: -123.18, lat: 49.19, layer: "airports", size: "small", look: "ring" }]));
|
|
216
251
|
* ```
|
|
217
252
|
*/
|
|
218
253
|
export declare function cleanPlaces(list: unknown): Place[];
|
|
@@ -273,7 +308,7 @@ export declare function orthoView(pose: Pose & {
|
|
|
273
308
|
*
|
|
274
309
|
* @param places - The places, as {@link cleanPlaces} makes them.
|
|
275
310
|
* @param view - The picture.
|
|
276
|
-
* @param look - `beam`, `pin` or `ring
|
|
311
|
+
* @param look - `beam`, `pin` or `ring`, for each place that has no `look` of its own; a `small` place has a shorter stick and a smaller ring.
|
|
277
312
|
* @param options - The size of each name, boxes already used, the most names (16) and where the Sun is overhead.
|
|
278
313
|
* @returns The markers to draw and where the names go.
|
|
279
314
|
*
|
|
@@ -362,3 +397,34 @@ export declare function groupPlaces(places: readonly Place[], cell: number): Pla
|
|
|
362
397
|
* ```
|
|
363
398
|
*/
|
|
364
399
|
export declare const readPlaceGroups: (value: string | null) => boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Which layers of places are shown (the attribute `place-layers`): a JSON object of layer names to true or false, such as `{"harbours":false}`. A layer that is not named is shown, and so is a place with no layer. Anything
|
|
402
|
+
* that is not an object of that kind is no switches.
|
|
403
|
+
*
|
|
404
|
+
* @param value - The attribute's text, or null.
|
|
405
|
+
* @returns The switches, a name to whether it is shown.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```ts
|
|
409
|
+
* import { readPlaceLayers } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
410
|
+
*
|
|
411
|
+
* console.log(readPlaceLayers('{"harbours":false,"airports":true}')); // { harbours: false, airports: true }
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
export declare function readPlaceLayers(value: string | null | undefined): Record<string, boolean>;
|
|
415
|
+
/**
|
|
416
|
+
* The places whose layer is shown: a place with no layer is always in, and a layer is in unless `layers` says `false` for it. The list is returned as it came when nothing is left out.
|
|
417
|
+
*
|
|
418
|
+
* @param places - The places, as {@link cleanPlaces} makes them.
|
|
419
|
+
* @param layers - The switches, a layer's name to whether it is shown ({@link readPlaceLayers}).
|
|
420
|
+
* @returns The places to draw.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* import { shownPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
425
|
+
*
|
|
426
|
+
* const places = [{ id: "yvr", lon: -123.18, lat: 49.19, layer: "airports" }, { id: "cavan", lon: -123.1, lat: 49.29, layer: "harbours" }, { id: "me", lon: -79.4, lat: 43.7 }];
|
|
427
|
+
* console.log(shownPlaces(places, { harbours: false }).map((place) => place.id)); // ["yvr", "me"]
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
export declare function shownPlaces(places: readonly Place[], layers: Readonly<Record<string, boolean>>): readonly Place[];
|
package/dist/markers/places.js
CHANGED
|
@@ -33,6 +33,9 @@ const EDGE = 0.02;
|
|
|
33
33
|
const FADE = 0.12;
|
|
34
34
|
const MARGIN = 60;
|
|
35
35
|
const SIZES = { here: { length: 46, ring: 9 }, favourite: { length: 28, ring: 6 } };
|
|
36
|
+
/** What a `small` place's stick and ring are of the kind's own. */
|
|
37
|
+
export const SMALL_LENGTH = 0.55;
|
|
38
|
+
export const SMALL_RING = 0.7;
|
|
36
39
|
const isObject = (value) => typeof value === "object" && value !== null;
|
|
37
40
|
/** A colour a page may give a place: a hex colour, `rgb()`/`hsl()` with numbers only, or a colour's name. Anything else is left out, so no other CSS gets in. */
|
|
38
41
|
const COLOR = /^(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgb|hsl)a?\([0-9.,%\s/+-]{1,60}\)|[a-z]{3,24})$/i;
|
|
@@ -48,8 +51,8 @@ const nightOf = (cosine) => {
|
|
|
48
51
|
};
|
|
49
52
|
/**
|
|
50
53
|
* The places of a list a page handed over, made safe to draw: each needs a longitude from -180 to 180 and a latitude from -90 to 90; one without an `id` is given its place in the list, a
|
|
51
|
-
* label is cut to 80 letters, a kind that is not `here` is `favourite`, and a colour is kept only when it is a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name.
|
|
52
|
-
* and at most {@link MAX_PLACES} are kept.
|
|
54
|
+
* label is cut to 80 letters, a kind that is not `here` is `favourite`, and a colour is kept only when it is a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. A `layer` is cut to 40 letters,
|
|
55
|
+
* a `size` is kept only when it is `small`, a `look` only when it is one of {@link PLACE_LOOKS} and a `namePriority` only when it is `low`. Anything else is left out, and at most {@link MAX_PLACES} are kept.
|
|
53
56
|
*
|
|
54
57
|
* @param list - What the page gave: an array of places, or anything.
|
|
55
58
|
* @returns The places to draw.
|
|
@@ -58,7 +61,7 @@ const nightOf = (cosine) => {
|
|
|
58
61
|
* ```ts
|
|
59
62
|
* import { cleanPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
60
63
|
*
|
|
61
|
-
* console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris", color: "#e8475f" }, { lon: 500, lat: 0 }]));
|
|
64
|
+
* console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris", color: "#e8475f" }, { lon: 500, lat: 0 }, { id: "yvr", lon: -123.18, lat: 49.19, layer: "airports", size: "small", look: "ring" }]));
|
|
62
65
|
* ```
|
|
63
66
|
*/
|
|
64
67
|
export function cleanPlaces(list) {
|
|
@@ -79,6 +82,14 @@ export function cleanPlaces(list) {
|
|
|
79
82
|
place.label = item["label"].trim().slice(0, 80);
|
|
80
83
|
if (typeof item["color"] === "string" && COLOR.test(item["color"].trim()))
|
|
81
84
|
place.color = item["color"].trim();
|
|
85
|
+
if (typeof item["layer"] === "string" && item["layer"].trim())
|
|
86
|
+
place.layer = item["layer"].trim().slice(0, 40);
|
|
87
|
+
if (item["size"] === "small")
|
|
88
|
+
place.size = "small";
|
|
89
|
+
if (PLACE_LOOKS.includes(item["look"]))
|
|
90
|
+
place.look = item["look"];
|
|
91
|
+
if (item["namePriority"] === "low")
|
|
92
|
+
place.namePriority = "low";
|
|
82
93
|
out.push(place);
|
|
83
94
|
}
|
|
84
95
|
return out;
|
|
@@ -172,7 +183,7 @@ export function orthoView(pose) {
|
|
|
172
183
|
*
|
|
173
184
|
* @param places - The places, as {@link cleanPlaces} makes them.
|
|
174
185
|
* @param view - The picture.
|
|
175
|
-
* @param look - `beam`, `pin` or `ring
|
|
186
|
+
* @param look - `beam`, `pin` or `ring`, for each place that has no `look` of its own; a `small` place has a shorter stick and a smaller ring.
|
|
176
187
|
* @param options - The size of each name, boxes already used, the most names (16) and where the Sun is overhead.
|
|
177
188
|
* @returns The markers to draw and where the names go.
|
|
178
189
|
*
|
|
@@ -197,6 +208,8 @@ export function layoutPlaces(places, view, look, options = {}) {
|
|
|
197
208
|
if (point.x < -MARGIN || point.y < -MARGIN || point.x > view.width + MARGIN || point.y > view.height + MARGIN)
|
|
198
209
|
continue;
|
|
199
210
|
const size = SIZES[place.kind === "here" ? "here" : "favourite"];
|
|
211
|
+
const small = place.size === "small";
|
|
212
|
+
const own = place.look ?? look;
|
|
200
213
|
const side = Math.min(1, Math.hypot(point.upX, point.upY));
|
|
201
214
|
// straight up from the ground as seen, bent towards the top of the screen as the reader comes to look straight down on it
|
|
202
215
|
let dx = point.upX;
|
|
@@ -210,7 +223,7 @@ export function layoutPlaces(places, view, look, options = {}) {
|
|
|
210
223
|
dx /= norm;
|
|
211
224
|
dy /= norm;
|
|
212
225
|
}
|
|
213
|
-
const length =
|
|
226
|
+
const length = own === "ring" ? 0 : size.length * (small ? SMALL_LENGTH : 1) * (0.55 + 0.45 * side);
|
|
214
227
|
const shape = {
|
|
215
228
|
index,
|
|
216
229
|
x: point.x,
|
|
@@ -221,14 +234,14 @@ export function layoutPlaces(places, view, look, options = {}) {
|
|
|
221
234
|
length,
|
|
222
235
|
ringAngle: side > 1e-4 ? Math.atan2(point.upX, -point.upY) / RAD : 0,
|
|
223
236
|
squash: Math.max(0.08, Math.min(1, point.facing)),
|
|
224
|
-
ring: size.ring,
|
|
237
|
+
ring: size.ring * (small ? SMALL_RING : 1),
|
|
225
238
|
opacity: Math.min(1, (point.facing - EDGE) / FADE),
|
|
226
239
|
night: sun ? nightOf(dotUnit(place.lon, place.lat, sun)) : 0,
|
|
227
240
|
};
|
|
228
241
|
shapes.push(shape);
|
|
229
242
|
const box = place.label ? options.size?.(place, index) : null;
|
|
230
243
|
if (box) {
|
|
231
|
-
items.push({ x: shape.tipX, y: shape.tipY, r:
|
|
244
|
+
items.push({ x: shape.tipX, y: shape.tipY, r: own === "ring" ? shape.ring : 3, w: box.width, h: box.height, priority: place.kind === "here" ? 1 : 0 });
|
|
232
245
|
named.push(index);
|
|
233
246
|
}
|
|
234
247
|
}
|
|
@@ -340,3 +353,53 @@ export function groupPlaces(places, cell) {
|
|
|
340
353
|
* ```
|
|
341
354
|
*/
|
|
342
355
|
export const readPlaceGroups = (value) => (value ?? "").trim().toLowerCase() !== "off";
|
|
356
|
+
/**
|
|
357
|
+
* Which layers of places are shown (the attribute `place-layers`): a JSON object of layer names to true or false, such as `{"harbours":false}`. A layer that is not named is shown, and so is a place with no layer. Anything
|
|
358
|
+
* that is not an object of that kind is no switches.
|
|
359
|
+
*
|
|
360
|
+
* @param value - The attribute's text, or null.
|
|
361
|
+
* @returns The switches, a name to whether it is shown.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* import { readPlaceLayers } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
366
|
+
*
|
|
367
|
+
* console.log(readPlaceLayers('{"harbours":false,"airports":true}')); // { harbours: false, airports: true }
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
export function readPlaceLayers(value) {
|
|
371
|
+
if (!value)
|
|
372
|
+
return {};
|
|
373
|
+
try {
|
|
374
|
+
const parsed = JSON.parse(value);
|
|
375
|
+
if (!isObject(parsed))
|
|
376
|
+
return {};
|
|
377
|
+
const out = {};
|
|
378
|
+
for (const [name, on] of Object.entries(parsed))
|
|
379
|
+
if (typeof on === "boolean")
|
|
380
|
+
out[name] = on;
|
|
381
|
+
return out;
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
return {};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The places whose layer is shown: a place with no layer is always in, and a layer is in unless `layers` says `false` for it. The list is returned as it came when nothing is left out.
|
|
389
|
+
*
|
|
390
|
+
* @param places - The places, as {@link cleanPlaces} makes them.
|
|
391
|
+
* @param layers - The switches, a layer's name to whether it is shown ({@link readPlaceLayers}).
|
|
392
|
+
* @returns The places to draw.
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```ts
|
|
396
|
+
* import { shownPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
397
|
+
*
|
|
398
|
+
* const places = [{ id: "yvr", lon: -123.18, lat: 49.19, layer: "airports" }, { id: "cavan", lon: -123.1, lat: 49.29, layer: "harbours" }, { id: "me", lon: -79.4, lat: 43.7 }];
|
|
399
|
+
* console.log(shownPlaces(places, { harbours: false }).map((place) => place.id)); // ["yvr", "me"]
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
export function shownPlaces(places, layers) {
|
|
403
|
+
const shown = places.filter((place) => !place.layer || layers[place.layer] !== false);
|
|
404
|
+
return shown.length === places.length ? places : shown;
|
|
405
|
+
}
|
|
@@ -204,7 +204,8 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
204
204
|
* is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
|
|
205
205
|
* and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
|
|
206
206
|
* it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked
|
|
207
|
-
* for less motion.
|
|
207
|
+
* for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays its name after the cities'
|
|
208
|
+
* names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
|
|
208
209
|
*/
|
|
209
210
|
get places(): Place[];
|
|
210
211
|
set places(value: readonly Place[]);
|
|
@@ -268,6 +269,39 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
268
269
|
*/
|
|
269
270
|
get placeGroups(): boolean;
|
|
270
271
|
set placeGroups(value: boolean);
|
|
272
|
+
/**
|
|
273
|
+
* Which layers of places are shown (the attribute `place-layers`, a JSON object of a layer's name to true or false): a place whose `layer` is named `false` is left out, and so is its name; any other place, and any layer not
|
|
274
|
+
* named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away.
|
|
275
|
+
* `stats.places.hidden` counts the places left out.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts no-run
|
|
279
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
280
|
+
*
|
|
281
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
282
|
+
* earth.placeLayers = { harbours: false };
|
|
283
|
+
* earth.getAttribute("place-layers"); // '{"harbours":false}'
|
|
284
|
+
* earth.setPlaceLayer("harbours", true);
|
|
285
|
+
* earth.placeLayers; // { harbours: true }
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
get placeLayers(): Record<string, boolean>;
|
|
289
|
+
set placeLayers(value: Readonly<Record<string, boolean>>);
|
|
290
|
+
/**
|
|
291
|
+
* Show or hide one layer of places, leaving the others as they are: the same as setting `placeLayers` with that layer changed.
|
|
292
|
+
*
|
|
293
|
+
* @param name - The layer's name, as in a place's `layer`.
|
|
294
|
+
* @param shown - Whether its places are shown.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts no-run
|
|
298
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
299
|
+
*
|
|
300
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
301
|
+
* earth.setPlaceLayer("airports", false);
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
setPlaceLayer(name: string, shown: boolean): void;
|
|
271
305
|
/** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
|
|
272
306
|
get placesLook(): PlaceLook;
|
|
273
307
|
set placesLook(value: PlaceLook);
|
|
@@ -441,6 +475,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
441
475
|
/** The places: how many were handed over, how many are drawn and named at the last draw, and how many times they were laid out. `sprites` is the rings in the picture's one draw call (0 when it cannot draw them); `dots` is the circles drawn in the page instead. */
|
|
442
476
|
places: {
|
|
443
477
|
places: number;
|
|
478
|
+
hidden: number;
|
|
444
479
|
shown: number;
|
|
445
480
|
labels: number;
|
|
446
481
|
renders: number;
|
|
@@ -22,10 +22,10 @@ import { folderSource } from "../door/map.js";
|
|
|
22
22
|
import { ownCredit } from "../door/own.js";
|
|
23
23
|
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
|
|
24
24
|
import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
|
|
25
|
-
import { cleanPlaces, orthoView, readPlaceGroups, readPlaces } from "../markers/places.js";
|
|
25
|
+
import { cleanPlaces, orthoView, readPlaceGroups, readPlaceLayers, readPlaces } from "../markers/places.js";
|
|
26
26
|
import { readHereCity } from "../markers/here-city.js";
|
|
27
27
|
import { createHereCity } from "../markers/here-city-host.js";
|
|
28
|
-
import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
28
|
+
import { createPlaceLayer, PLACE_STYLE, placeClick, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
29
29
|
import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
|
|
30
30
|
import { subsolarPoint } from "./sun.js";
|
|
31
31
|
import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
|
|
@@ -166,7 +166,7 @@ export const readTime = (value) => {
|
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
168
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
169
|
-
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "smooth-fps", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint", "satellite-streak-max", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far"];
|
|
169
|
+
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "smooth-fps", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "place-layers", "here-city", "route", "satellite-tint", "satellite-streak-max", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far"];
|
|
170
170
|
#model = newModel();
|
|
171
171
|
#paint = createPaintState();
|
|
172
172
|
#mode = "now";
|
|
@@ -279,6 +279,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
279
279
|
this.#placeLayer.set(this.#here.named(this.#placeList));
|
|
280
280
|
this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
|
|
281
281
|
this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
|
|
282
|
+
this.#placeLayer.layers = readPlaceLayers(this.getAttribute("place-layers"));
|
|
282
283
|
this.#cities = createCityHost({
|
|
283
284
|
root,
|
|
284
285
|
attribute: (name) => this.getAttribute(name),
|
|
@@ -536,6 +537,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
536
537
|
this.#placeLayer.grouping = readPlaceGroups(value);
|
|
537
538
|
this.#gate?.soon();
|
|
538
539
|
}
|
|
540
|
+
else if (name === "place-layers" && this.#placeLayer) {
|
|
541
|
+
this.#placeLayer.layers = readPlaceLayers(value);
|
|
542
|
+
this.#gate?.soon();
|
|
543
|
+
}
|
|
539
544
|
else if (name === "route") {
|
|
540
545
|
if (applyRoute(this.#model.route, readRoute(value)))
|
|
541
546
|
this.#gate?.soon();
|
|
@@ -692,7 +697,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
692
697
|
* is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
|
|
693
698
|
* and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
|
|
694
699
|
* it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked
|
|
695
|
-
* for less motion.
|
|
700
|
+
* for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays its name after the cities'
|
|
701
|
+
* names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
|
|
696
702
|
*/
|
|
697
703
|
get places() {
|
|
698
704
|
return this.#placeList.map((place) => ({ ...place }));
|
|
@@ -826,6 +832,49 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
826
832
|
else
|
|
827
833
|
this.setAttribute("place-groups", "off");
|
|
828
834
|
}
|
|
835
|
+
/**
|
|
836
|
+
* Which layers of places are shown (the attribute `place-layers`, a JSON object of a layer's name to true or false): a place whose `layer` is named `false` is left out, and so is its name; any other place, and any layer not
|
|
837
|
+
* named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away.
|
|
838
|
+
* `stats.places.hidden` counts the places left out.
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```ts no-run
|
|
842
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
843
|
+
*
|
|
844
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
845
|
+
* earth.placeLayers = { harbours: false };
|
|
846
|
+
* earth.getAttribute("place-layers"); // '{"harbours":false}'
|
|
847
|
+
* earth.setPlaceLayer("harbours", true);
|
|
848
|
+
* earth.placeLayers; // { harbours: true }
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
get placeLayers() {
|
|
852
|
+
return { ...(this.#placeLayer?.layers ?? readPlaceLayers(this.getAttribute("place-layers"))) };
|
|
853
|
+
}
|
|
854
|
+
set placeLayers(value) {
|
|
855
|
+
const names = Object.keys(value);
|
|
856
|
+
if (names.length === 0)
|
|
857
|
+
this.removeAttribute("place-layers");
|
|
858
|
+
else
|
|
859
|
+
this.setAttribute("place-layers", JSON.stringify(value));
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Show or hide one layer of places, leaving the others as they are: the same as setting `placeLayers` with that layer changed.
|
|
863
|
+
*
|
|
864
|
+
* @param name - The layer's name, as in a place's `layer`.
|
|
865
|
+
* @param shown - Whether its places are shown.
|
|
866
|
+
*
|
|
867
|
+
* @example
|
|
868
|
+
* ```ts no-run
|
|
869
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
870
|
+
*
|
|
871
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
872
|
+
* earth.setPlaceLayer("airports", false);
|
|
873
|
+
* ```
|
|
874
|
+
*/
|
|
875
|
+
setPlaceLayer(name, shown) {
|
|
876
|
+
this.placeLayers = { ...this.placeLayers, [name]: shown };
|
|
877
|
+
}
|
|
829
878
|
/** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself. */
|
|
830
879
|
#ringsDrawn(drawn) {
|
|
831
880
|
if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
|
|
@@ -952,6 +1001,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
952
1001
|
#relayNames(cities, sky) {
|
|
953
1002
|
if (cities && this.#nameFrame)
|
|
954
1003
|
this.#cities?.frame(this.#nameFrame, this.#boxesBeforeCities());
|
|
1004
|
+
this.#placeLayer?.late(() => [...(this.#cities?.boxes ?? []), ...[...this.#claimedNames.values()].flat()]);
|
|
955
1005
|
this.#seaFrame();
|
|
956
1006
|
this.#countryFrame();
|
|
957
1007
|
if (sky)
|
|
@@ -962,7 +1012,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
962
1012
|
#boxesBeforeCities() {
|
|
963
1013
|
const out = this.#beforeCities;
|
|
964
1014
|
out.length = 0;
|
|
965
|
-
out.push(...(this.#placeLayer?.
|
|
1015
|
+
out.push(...(this.#placeLayer?.earlyBoxes ?? []));
|
|
966
1016
|
for (const boxes of this.#claimedNames.values())
|
|
967
1017
|
out.push(...boxes);
|
|
968
1018
|
return out;
|
|
@@ -1237,7 +1287,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1237
1287
|
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
1238
1288
|
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
1239
1289
|
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: [] },
|
|
1240
|
-
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
|
|
1290
|
+
places: { ...(this.#placeLayer?.stats ?? { places: 0, hidden: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
|
|
1241
1291
|
hereCity: this.#here?.stats ?? { on: false, maxKm: 0, loaded: false, pending: false },
|
|
1242
1292
|
cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
|
|
1243
1293
|
borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
|
|
@@ -1679,7 +1729,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1679
1729
|
#downX = 0;
|
|
1680
1730
|
#downY = 0;
|
|
1681
1731
|
#down = (event) => {
|
|
1682
|
-
if (event.button !== 0 || this.#model.satellites.groups.size === 0)
|
|
1732
|
+
if (event.button !== 0 || (this.#model.satellites.groups.size === 0 && this.#placeList.length === 0))
|
|
1683
1733
|
return;
|
|
1684
1734
|
this.#downX = event.clientX;
|
|
1685
1735
|
this.#downY = event.clientY;
|
|
@@ -1698,6 +1748,12 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1698
1748
|
if (satellite) {
|
|
1699
1749
|
claimPress(event);
|
|
1700
1750
|
this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite), ...this.#estimateOf(satellite) }, bubbles: true, composed: true }));
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
const place = this.#placeLayer?.pick(event.clientX - rect.left, event.clientY - rect.top);
|
|
1754
|
+
if (place) {
|
|
1755
|
+
claimPress(event);
|
|
1756
|
+
this.dispatchEvent(new CustomEvent("chikyu-place-click", { detail: placeClick(place, event.clientX - rect.left, event.clientY - rect.top), bubbles: true, composed: true }));
|
|
1701
1757
|
}
|
|
1702
1758
|
};
|
|
1703
1759
|
#wheel = (event) => immersiveWheel(this, event);
|
|
@@ -335,7 +335,8 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
335
335
|
* is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
|
|
336
336
|
* and keep their size in pixels at any zoom. Names never overlap one another or the bodies' names; one with no room is left out. The element stores nothing and sends nothing: the page hands the places
|
|
337
337
|
* over and keeps them where it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight
|
|
338
|
-
* and for a reader who asked for less motion.
|
|
338
|
+
* and for a reader who asked for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays
|
|
339
|
+
* its name after the cities' names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
|
|
339
340
|
*/
|
|
340
341
|
get places(): Place[];
|
|
341
342
|
set places(value: readonly Place[]);
|
|
@@ -399,6 +400,39 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
399
400
|
*/
|
|
400
401
|
get placeGroups(): boolean;
|
|
401
402
|
set placeGroups(value: boolean);
|
|
403
|
+
/**
|
|
404
|
+
* Which layers of places are shown (the attribute `place-layers`, a JSON object of a layer's name to true or false): a place whose `layer` is named `false` is left out, and so is its name; any other place, and any layer not
|
|
405
|
+
* named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away.
|
|
406
|
+
* `stats.places.hidden` counts the places left out.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts no-run
|
|
410
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
411
|
+
*
|
|
412
|
+
* const space = document.querySelector("chikyu-space") as ChikyuSpace;
|
|
413
|
+
* space.placeLayers = { harbours: false };
|
|
414
|
+
* space.getAttribute("place-layers"); // '{"harbours":false}'
|
|
415
|
+
* space.setPlaceLayer("harbours", true);
|
|
416
|
+
* space.placeLayers; // { harbours: true }
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
get placeLayers(): Record<string, boolean>;
|
|
420
|
+
set placeLayers(value: Readonly<Record<string, boolean>>);
|
|
421
|
+
/**
|
|
422
|
+
* Show or hide one layer of places, leaving the others as they are: the same as setting `placeLayers` with that layer changed.
|
|
423
|
+
*
|
|
424
|
+
* @param name - The layer's name, as in a place's `layer`.
|
|
425
|
+
* @param shown - Whether its places are shown.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts no-run
|
|
429
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
430
|
+
*
|
|
431
|
+
* const space = document.querySelector("chikyu-space") as ChikyuSpace;
|
|
432
|
+
* space.setPlaceLayer("airports", false);
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
setPlaceLayer(name: string, shown: boolean): void;
|
|
402
436
|
/** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
|
|
403
437
|
get placesLook(): PlaceLook;
|
|
404
438
|
set placesLook(value: PlaceLook);
|
|
@@ -1130,6 +1164,7 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
1130
1164
|
*/
|
|
1131
1165
|
places: {
|
|
1132
1166
|
places: number;
|
|
1167
|
+
hidden: number;
|
|
1133
1168
|
shown: number;
|
|
1134
1169
|
labels: number;
|
|
1135
1170
|
renders: number;
|
|
@@ -3,10 +3,10 @@ import { adoptStyles } from "../adopt.js";
|
|
|
3
3
|
import { airFor, readAirThickness } from "../realistic/air.js";
|
|
4
4
|
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
|
|
5
5
|
import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
|
|
6
|
-
import { cleanPlaces, readPlaceGroups, readPlaces } from "../markers/places.js";
|
|
6
|
+
import { cleanPlaces, readPlaceGroups, readPlaceLayers, readPlaces } from "../markers/places.js";
|
|
7
7
|
import { readHereCity } from "../markers/here-city.js";
|
|
8
8
|
import { createHereCity } from "../markers/here-city-host.js";
|
|
9
|
-
import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
9
|
+
import { createPlaceLayer, PLACE_STYLE, placeClick, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
10
10
|
import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
|
|
11
11
|
import { subsolarPoint } from "../realistic/sun.js";
|
|
12
12
|
import { SHORT_NAMES } from "../satellites/names.js";
|
|
@@ -196,7 +196,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
196
196
|
* ```
|
|
197
197
|
*/
|
|
198
198
|
export class ChikyuSpace extends HTMLElement {
|
|
199
|
-
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-outside-km", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "smooth-fps"];
|
|
199
|
+
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "place-layers", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-outside-km", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "smooth-fps"];
|
|
200
200
|
#model = newSpaceModel();
|
|
201
201
|
/** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
|
|
202
202
|
#finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
|
|
@@ -327,6 +327,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
327
327
|
this.#placeLayer.set(this.#here.named(this.#placeList));
|
|
328
328
|
this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
|
|
329
329
|
this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
|
|
330
|
+
this.#placeLayer.layers = readPlaceLayers(this.getAttribute("place-layers"));
|
|
330
331
|
this.#dimOccluded = this.getAttribute("dim-occluded") !== "off";
|
|
331
332
|
this.#placeLayer.dimOccluded = this.#dimOccluded;
|
|
332
333
|
this.#cities = createCityHost({
|
|
@@ -590,6 +591,10 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
590
591
|
this.#placeLayer.grouping = readPlaceGroups(value);
|
|
591
592
|
this.#gate?.request();
|
|
592
593
|
}
|
|
594
|
+
else if (name === "place-layers" && this.#placeLayer) {
|
|
595
|
+
this.#placeLayer.layers = readPlaceLayers(value);
|
|
596
|
+
this.#gate?.request();
|
|
597
|
+
}
|
|
593
598
|
else if (name === "route") {
|
|
594
599
|
if (applyRoute(this.#model.route, readRoute(value)))
|
|
595
600
|
this.#gate?.request();
|
|
@@ -834,7 +839,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
834
839
|
* is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
|
|
835
840
|
* and keep their size in pixels at any zoom. Names never overlap one another or the bodies' names; one with no room is left out. The element stores nothing and sends nothing: the page hands the places
|
|
836
841
|
* over and keeps them where it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight
|
|
837
|
-
* and for a reader who asked for less motion.
|
|
842
|
+
* and for a reader who asked for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays
|
|
843
|
+
* its name after the cities' names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
|
|
838
844
|
*/
|
|
839
845
|
get places() {
|
|
840
846
|
return this.#placeList.map((place) => ({ ...place }));
|
|
@@ -967,6 +973,49 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
967
973
|
else
|
|
968
974
|
this.setAttribute("place-groups", "off");
|
|
969
975
|
}
|
|
976
|
+
/**
|
|
977
|
+
* Which layers of places are shown (the attribute `place-layers`, a JSON object of a layer's name to true or false): a place whose `layer` is named `false` is left out, and so is its name; any other place, and any layer not
|
|
978
|
+
* named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away.
|
|
979
|
+
* `stats.places.hidden` counts the places left out.
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* ```ts no-run
|
|
983
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
984
|
+
*
|
|
985
|
+
* const space = document.querySelector("chikyu-space") as ChikyuSpace;
|
|
986
|
+
* space.placeLayers = { harbours: false };
|
|
987
|
+
* space.getAttribute("place-layers"); // '{"harbours":false}'
|
|
988
|
+
* space.setPlaceLayer("harbours", true);
|
|
989
|
+
* space.placeLayers; // { harbours: true }
|
|
990
|
+
* ```
|
|
991
|
+
*/
|
|
992
|
+
get placeLayers() {
|
|
993
|
+
return { ...(this.#placeLayer?.layers ?? readPlaceLayers(this.getAttribute("place-layers"))) };
|
|
994
|
+
}
|
|
995
|
+
set placeLayers(value) {
|
|
996
|
+
const names = Object.keys(value);
|
|
997
|
+
if (names.length === 0)
|
|
998
|
+
this.removeAttribute("place-layers");
|
|
999
|
+
else
|
|
1000
|
+
this.setAttribute("place-layers", JSON.stringify(value));
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Show or hide one layer of places, leaving the others as they are: the same as setting `placeLayers` with that layer changed.
|
|
1004
|
+
*
|
|
1005
|
+
* @param name - The layer's name, as in a place's `layer`.
|
|
1006
|
+
* @param shown - Whether its places are shown.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```ts no-run
|
|
1010
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
1011
|
+
*
|
|
1012
|
+
* const space = document.querySelector("chikyu-space") as ChikyuSpace;
|
|
1013
|
+
* space.setPlaceLayer("airports", false);
|
|
1014
|
+
* ```
|
|
1015
|
+
*/
|
|
1016
|
+
setPlaceLayer(name, shown) {
|
|
1017
|
+
this.placeLayers = { ...this.placeLayers, [name]: shown };
|
|
1018
|
+
}
|
|
970
1019
|
/** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself. */
|
|
971
1020
|
#ringsDrawn(drawn) {
|
|
972
1021
|
if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
|
|
@@ -1010,6 +1059,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1010
1059
|
#relayNames(cities, sky) {
|
|
1011
1060
|
if (cities)
|
|
1012
1061
|
this.#cities?.frame(this.#lastNameFrame, this.#boxesBeforeCities());
|
|
1062
|
+
this.#placeLayer?.late(() => [...this.#bodyNameBoxes(), ...(this.#cities?.boxes ?? [])]);
|
|
1013
1063
|
this.#seaFrame();
|
|
1014
1064
|
this.#countryFrame();
|
|
1015
1065
|
if (sky)
|
|
@@ -1020,7 +1070,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1020
1070
|
#boxesBeforeCities() {
|
|
1021
1071
|
const out = this.#beforeCities;
|
|
1022
1072
|
out.length = 0;
|
|
1023
|
-
out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.
|
|
1073
|
+
out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.earlyBoxes ?? []));
|
|
1024
1074
|
return out;
|
|
1025
1075
|
}
|
|
1026
1076
|
/** What the stars' and constellations' names keep off: everything before them, the cities' names last. The list is refilled, not made again. */
|
|
@@ -2644,7 +2694,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
2644
2694
|
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: [] },
|
|
2645
2695
|
followModel: this.#model.followModel,
|
|
2646
2696
|
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {}, finer: null, fading: false },
|
|
2647
|
-
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
|
|
2697
|
+
places: { ...(this.#placeLayer?.stats ?? { places: 0, hidden: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
|
|
2648
2698
|
hereCity: this.#here?.stats ?? { on: false, maxKm: 0, loaded: false, pending: false },
|
|
2649
2699
|
cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
|
|
2650
2700
|
borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
|
|
@@ -2822,6 +2872,11 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
2822
2872
|
this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite), ...this.#estimateOf(satellite) }, bubbles: true, composed: true }));
|
|
2823
2873
|
return;
|
|
2824
2874
|
}
|
|
2875
|
+
const place = this.#placeLayer?.pick(x, y);
|
|
2876
|
+
if (place) {
|
|
2877
|
+
claimPress(event);
|
|
2878
|
+
this.dispatchEvent(new CustomEvent("chikyu-place-click", { detail: placeClick(place, x, y), bubbles: true, composed: true }));
|
|
2879
|
+
}
|
|
2825
2880
|
if (!this.#places)
|
|
2826
2881
|
return;
|
|
2827
2882
|
let best;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.61.0",
|
|
4
4
|
"description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"earth",
|
|
@@ -220,7 +220,7 @@
|
|
|
220
220
|
"family:readme": "node scripts/family-readme.mjs",
|
|
221
221
|
"site": "pnpm build && node scripts/site.ts",
|
|
222
222
|
"dev": "pnpm site && node scripts/dev.ts",
|
|
223
|
-
"test:demo": "pnpm site && node scripts/docs-site.mjs build && playwright test --project=chromium-desk --project=chromium-phone --project=webkit-desk --project=webkit-phone --project=chromium-gl",
|
|
223
|
+
"test:demo": "pnpm site && node scripts/docs-site.mjs build && playwright test --project=chromium-desk --project=chromium-phone --project=webkit-desk --project=webkit-phone --project=chromium-gl && playwright test --project=chromium-cost --workers=1",
|
|
224
224
|
"screenshots": "pnpm site && node scripts/screenshots.ts",
|
|
225
225
|
"textures": "python3 scripts/make-textures.py",
|
|
226
226
|
"tiles": "python3 -I scripts/make-earth-tiles.py build",
|