drone-path 0.0.0 → 0.8.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 +179 -0
- package/LICENSE +21 -0
- package/README.md +83 -6
- package/THIRD-PARTY-NOTICES.md +77 -0
- package/app/main.mjs +496 -0
- package/app/preload.cjs +31 -0
- package/app/update-policy.d.mts +6 -0
- package/app/update-policy.mjs +6 -0
- package/app/update.d.mts +10 -0
- package/app/update.mjs +54 -0
- package/bin/drone-path.mjs +5 -0
- package/dist/appassets.js +44 -0
- package/dist/apppaths.js +28 -0
- package/dist/appsession.js +128 -0
- package/dist/appstate.js +109 -0
- package/dist/assets.js +67 -0
- package/dist/cammeta.js +292 -0
- package/dist/changeset-gate.js +46 -0
- package/dist/cli.js +156 -0
- package/dist/config.js +469 -0
- package/dist/configfile.js +81 -0
- package/dist/decimate.js +94 -0
- package/dist/errors.js +4 -0
- package/dist/exportjob.js +106 -0
- package/dist/ff.js +121 -0
- package/dist/fftools.js +65 -0
- package/dist/geo.js +70 -0
- package/dist/inputs.js +59 -0
- package/dist/manual/anchors.js +23 -0
- package/dist/manual/build.js +78 -0
- package/dist/manual/cliref.js +36 -0
- package/dist/manual/links.js +76 -0
- package/dist/manual/markdown.js +101 -0
- package/dist/manual/model.js +4 -0
- package/dist/manual/module.js +8 -0
- package/dist/manual/nav.js +13 -0
- package/dist/manual/reference.js +26 -0
- package/dist/page.js +108 -0
- package/dist/paths.js +28 -0
- package/dist/plan.js +119 -0
- package/dist/png.js +52 -0
- package/dist/proto.js +102 -0
- package/dist/range.js +58 -0
- package/dist/render.js +408 -0
- package/dist/renderer/boot.js +7 -0
- package/dist/renderer/dom.js +132 -0
- package/dist/renderer/framemath.js +34 -0
- package/dist/renderer/leaflet.js +5 -0
- package/dist/renderer/scene.js +358 -0
- package/dist/renderer/theme.js +34 -0
- package/dist/renderer/tilesources.js +34 -0
- package/dist/renderer/trail.js +53 -0
- package/dist/restyle.js +24 -0
- package/dist/run.js +446 -0
- package/dist/serve.js +70 -0
- package/dist/srt.js +76 -0
- package/dist/summary.js +22 -0
- package/dist/telemetry-math.js +302 -0
- package/dist/telemetry.js +38 -0
- package/dist/tilecache.js +26 -0
- package/dist/tiles.js +241 -0
- package/dist/tracing.js +208 -0
- package/dist/version.js +3 -0
- package/package.json +93 -7
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Renderer markup and styling, shared verbatim by the generated page and the
|
|
2
|
+
// app's map islands so both look and measure identically. Element ids are the
|
|
3
|
+
// renderer's DOM contract. The styles are scoped to one scene host each: the
|
|
4
|
+
// app mounts two scenes at once (player island and export preview), so bare
|
|
5
|
+
// selectors would let one scene's scale values restyle the other.
|
|
6
|
+
export function sceneCss(src, theme, width, height, scale, scope) {
|
|
7
|
+
const at = `.${scope}`;
|
|
8
|
+
return `
|
|
9
|
+
${at} { margin: 0; padding: 0; overflow: hidden; background: ${src.bg}; }
|
|
10
|
+
${at}, ${at} * { animation: none !important; transition: none !important; }
|
|
11
|
+
${at} #map-frame {
|
|
12
|
+
position: absolute; inset: 0; overflow: hidden; background: ${src.bg};
|
|
13
|
+
}
|
|
14
|
+
${at} #map {
|
|
15
|
+
position: absolute; left: 0; top: 0; width: ${width}px; height: ${height}px;
|
|
16
|
+
/* Leaflet's own container default is a light gray; the un-tiled field
|
|
17
|
+
takes the style's background so it never flashes bright (#167). */
|
|
18
|
+
background: ${src.bg};
|
|
19
|
+
}
|
|
20
|
+
${at} .leaflet-tile-pane { filter: ${src.tileFilter ?? 'none'}; }
|
|
21
|
+
${at} #vignette {
|
|
22
|
+
position: absolute; inset: 0; z-index: 500; pointer-events: none;
|
|
23
|
+
background: radial-gradient(ellipse 78% 78% at 50% 44%,
|
|
24
|
+
rgba(0,0,0,0) 52%, rgba(0,0,0,${theme.vignette}) 100%);
|
|
25
|
+
}
|
|
26
|
+
${at} .drone-wrap {
|
|
27
|
+
width: ${Math.round(46 * scale)}px; height: ${Math.round(46 * scale)}px;
|
|
28
|
+
border-radius: 50%;
|
|
29
|
+
background: ${theme.discBg};
|
|
30
|
+
border: ${Math.max(2, Math.round(2.2 * scale))}px solid rgba(255,255,255,0.92);
|
|
31
|
+
box-shadow:
|
|
32
|
+
0 0 0 ${Math.round(7 * scale)}px ${theme.glow},
|
|
33
|
+
0 ${Math.round(3 * scale)}px ${Math.round(12 * scale)}px rgba(0,0,0,0.45);
|
|
34
|
+
display: flex; align-items: center; justify-content: center;
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
}
|
|
37
|
+
${at} .drone-arrow { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
|
|
38
|
+
${at} .drone-arrow svg { width: 72%; height: 72%; display: block; }
|
|
39
|
+
${at} #hud {
|
|
40
|
+
position: absolute; top: ${Math.round(16 * scale)}px; left: ${Math.round(16 * scale)}px;
|
|
41
|
+
display: flex; flex-direction: column; gap: ${Math.round(8 * scale)}px;
|
|
42
|
+
font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
43
|
+
z-index: 1200; pointer-events: none;
|
|
44
|
+
}
|
|
45
|
+
${at} .chip {
|
|
46
|
+
background: rgba(14,19,28,0.9);
|
|
47
|
+
backdrop-filter: blur(${Math.round(14 * scale)}px) saturate(1.25);
|
|
48
|
+
-webkit-backdrop-filter: blur(${Math.round(14 * scale)}px) saturate(1.25);
|
|
49
|
+
color: #ffffff;
|
|
50
|
+
padding: ${Math.round(6 * scale)}px ${Math.round(14 * scale)}px ${Math.round(6 * scale)}px ${Math.round(13 * scale)}px;
|
|
51
|
+
border-radius: ${Math.round(13 * scale)}px;
|
|
52
|
+
font-size: ${Math.round(21 * scale)}px;
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
font-variant-numeric: tabular-nums;
|
|
55
|
+
letter-spacing: 0.3px;
|
|
56
|
+
display: inline-flex; align-items: baseline; gap: ${Math.round(7 * scale)}px;
|
|
57
|
+
width: fit-content;
|
|
58
|
+
border: 1px solid rgba(255,255,255,0.20);
|
|
59
|
+
box-shadow:
|
|
60
|
+
inset ${Math.max(3, Math.round(3 * scale))}px 0 0 ${theme.core},
|
|
61
|
+
0 ${Math.round(6 * scale)}px ${Math.round(18 * scale)}px rgba(0,0,0,0.30);
|
|
62
|
+
}
|
|
63
|
+
${at} .chip .label {
|
|
64
|
+
font-size: 0.55em; font-weight: 700; letter-spacing: 1.2px;
|
|
65
|
+
color: ${theme.core}; opacity: 0.95;
|
|
66
|
+
}
|
|
67
|
+
${at} .chip .unit { font-weight: 500; opacity: 0.72; font-size: 0.68em; }
|
|
68
|
+
${at} #attr {
|
|
69
|
+
position: absolute; right: 0; bottom: 0; z-index: 1000; max-width: 72%;
|
|
70
|
+
background: rgba(12, 14, 22, 0.62); color: rgba(255,255,255,0.78);
|
|
71
|
+
font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
72
|
+
font-size: ${Math.round(11 * scale)}px; line-height: 1.35;
|
|
73
|
+
padding: ${Math.round(2 * scale)}px ${Math.round(8 * scale)}px;
|
|
74
|
+
border-radius: ${Math.round(4 * scale)}px 0 0 0;
|
|
75
|
+
pointer-events: none;
|
|
76
|
+
}
|
|
77
|
+
${at} #attr a { color: rgba(255,255,255,0.92); text-decoration: none; }
|
|
78
|
+
${at} #scalebar {
|
|
79
|
+
position: absolute; left: ${Math.round(10 * scale)}px; bottom: ${Math.round(8 * scale)}px;
|
|
80
|
+
z-index: 1000; pointer-events: none;
|
|
81
|
+
font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
82
|
+
}
|
|
83
|
+
${at} #scaletext {
|
|
84
|
+
display: block; color: #ffffff; font-size: ${Math.round(11 * scale)}px;
|
|
85
|
+
text-shadow: 0 1px 2px rgba(0,0,0,0.8); margin-bottom: 2px;
|
|
86
|
+
}
|
|
87
|
+
${at} #scaleline {
|
|
88
|
+
height: ${Math.max(4, Math.round(5 * scale))}px;
|
|
89
|
+
border: 1px solid rgba(255,255,255,0.85); border-top: none;
|
|
90
|
+
box-shadow: 0 1px 2px rgba(0,0,0,0.6);
|
|
91
|
+
}`;
|
|
92
|
+
}
|
|
93
|
+
export function hudMarkup(hud) {
|
|
94
|
+
const chips = [];
|
|
95
|
+
if (hud.alt) {
|
|
96
|
+
chips.push('<div class="chip" id="chip-alt"><span class="label">ALT</span><span class="num">--</span><span class="unit">m</span></div>');
|
|
97
|
+
}
|
|
98
|
+
if (hud.speed) {
|
|
99
|
+
chips.push('<div class="chip" id="chip-speed"><span class="label">SPD</span><span class="num">--</span><span class="unit">m/s</span></div>');
|
|
100
|
+
}
|
|
101
|
+
return chips.map((chip) => ` ${chip}`).join('\n');
|
|
102
|
+
}
|
|
103
|
+
export function mapMarkup(hud, attribution) {
|
|
104
|
+
return `<div id="map-frame">
|
|
105
|
+
<div id="map"></div>
|
|
106
|
+
<div id="vignette"></div>
|
|
107
|
+
<div id="hud">
|
|
108
|
+
${hudMarkup(hud)}
|
|
109
|
+
</div>
|
|
110
|
+
<div id="attr">${attribution}</div>
|
|
111
|
+
<div id="scalebar"><span id="scaletext"></span><div id="scaleline"></div></div>
|
|
112
|
+
</div>`;
|
|
113
|
+
}
|
|
114
|
+
/** Attribution links are on-screen credits, not controls: keyboard skips them. */
|
|
115
|
+
export function quietAttributionLinks(attr) {
|
|
116
|
+
for (const a of attr.querySelectorAll('a'))
|
|
117
|
+
a.setAttribute('tabindex', '-1');
|
|
118
|
+
}
|
|
119
|
+
export function droneMarkerMarkup(coreColor) {
|
|
120
|
+
return ('<div class="drone-wrap"><div class="drone-arrow" id="drone-arrow">' +
|
|
121
|
+
'<svg viewBox="0 0 24 24"><path d="M12 1.8 L21 22 L12 16.9 L3 22 Z" fill="' +
|
|
122
|
+
coreColor +
|
|
123
|
+
'" stroke="rgba(255,255,255,0.9)" stroke-width="0.9" stroke-linejoin="round"/></svg>' +
|
|
124
|
+
'</div></div>');
|
|
125
|
+
}
|
|
126
|
+
/** Returns the element the renderer's DOM contract guarantees. */
|
|
127
|
+
export function el(root, selector) {
|
|
128
|
+
const found = root.querySelector(selector);
|
|
129
|
+
if (!found)
|
|
130
|
+
throw new Error(`renderer element missing: ${selector}`);
|
|
131
|
+
return found;
|
|
132
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Pure viewport and timeline math for the shared renderer. Kept free of DOM
|
|
2
|
+
// and Leaflet so the frame-exact behaviors stay unit-testable.
|
|
3
|
+
export function computeScale(width, height) {
|
|
4
|
+
return Math.max(0.7, Math.min(2.2, Math.min(width, height) / 1024));
|
|
5
|
+
}
|
|
6
|
+
export function smoothstep(t) {
|
|
7
|
+
const clamped = Math.max(0, Math.min(1, t));
|
|
8
|
+
return clamped * clamped * (3 - 2 * clamped);
|
|
9
|
+
}
|
|
10
|
+
// Intro/outro zoom-out: 0.5 = one zoom level further out, smoothstepped.
|
|
11
|
+
export function introOutroScale(i, introN, outroN, totalN) {
|
|
12
|
+
let kIn = 1;
|
|
13
|
+
let kOut = 1;
|
|
14
|
+
if (introN > 0 && i < introN) {
|
|
15
|
+
kIn = Math.pow(2, -(1 - smoothstep(i / introN)));
|
|
16
|
+
}
|
|
17
|
+
if (outroN > 0 && i > totalN - 1 - outroN) {
|
|
18
|
+
kOut = Math.pow(2, -(1 - smoothstep((totalN - 1 - i) / outroN)));
|
|
19
|
+
}
|
|
20
|
+
return Math.min(kIn, kOut);
|
|
21
|
+
}
|
|
22
|
+
export function metersPerPixel(lat, zoom) {
|
|
23
|
+
return (156543.033928 * Math.cos((lat * Math.PI) / 180)) / Math.pow(2, zoom);
|
|
24
|
+
}
|
|
25
|
+
// The map never zooms during a render, so the scale bar picks one step once.
|
|
26
|
+
export function scaleBarMeters(mPerPx, maxPx) {
|
|
27
|
+
const steps = [5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000, 10000];
|
|
28
|
+
let best = steps[0];
|
|
29
|
+
for (const step of steps) {
|
|
30
|
+
if (step / mPerPx <= maxPx)
|
|
31
|
+
best = step;
|
|
32
|
+
}
|
|
33
|
+
return best;
|
|
34
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The minimal Leaflet surface the shared renderer touches. Consumers pass the
|
|
2
|
+
// real namespace in (the generated page takes window.L, the app its bundled
|
|
3
|
+
// module import), so this code stays free of bundler and global assumptions
|
|
4
|
+
// and tests can drive it with a fake.
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// The shared map renderer: it receives all telemetry inline (no fetch), paints
|
|
2
|
+
// the map once, and exposes setFrame(i) for per-frame marker/trail updates.
|
|
3
|
+
// Headless capture workers (via the generated page's window.__setFrame bridge)
|
|
4
|
+
// and the app's React map island both drive this one implementation;
|
|
5
|
+
// setFrame resolves after the canvas has painted so screenshots are
|
|
6
|
+
// frame-exact. update(data) restyles in place for the app's settings panel,
|
|
7
|
+
// rebuilding only the decorations the new settings actually invalidate.
|
|
8
|
+
//
|
|
9
|
+
// Views:
|
|
10
|
+
// overview - static map fitted to the whole track (trail grows with time)
|
|
11
|
+
// follow - drone marker stays in the frame center and the map slides under
|
|
12
|
+
// it (all tiles are loaded once up-front; the per-frame move is a
|
|
13
|
+
// pure CSS transform, so no tile loads happen mid-render)
|
|
14
|
+
import { TILE_SOURCES } from './tilesources.js';
|
|
15
|
+
import { droneMarkerMarkup, el, hudMarkup, mapMarkup, quietAttributionLinks, sceneCss } from './dom.js';
|
|
16
|
+
import { computeScale, introOutroScale, metersPerPixel, scaleBarMeters } from './framemath.js';
|
|
17
|
+
import { themeFor } from './theme.js';
|
|
18
|
+
import { createTrailController } from './trail.js';
|
|
19
|
+
function hudEq(a, b) {
|
|
20
|
+
return (a.heading === b.heading && a.alt === b.alt && a.speed === b.speed);
|
|
21
|
+
}
|
|
22
|
+
function setChipText(chip, value, format) {
|
|
23
|
+
if (!chip)
|
|
24
|
+
return;
|
|
25
|
+
chip.textContent = value === null || value === undefined ? '--' : format(value);
|
|
26
|
+
}
|
|
27
|
+
// Per-scene style scope: the app mounts two scenes at once (the player island
|
|
28
|
+
// and the export preview), and one scene's scale values must never restyle the
|
|
29
|
+
// other's elements.
|
|
30
|
+
let scopeCount = 0;
|
|
31
|
+
class SceneState {
|
|
32
|
+
ready;
|
|
33
|
+
data;
|
|
34
|
+
L;
|
|
35
|
+
host;
|
|
36
|
+
scopeClass = `scene-scope-${(scopeCount += 1)}`;
|
|
37
|
+
styleEl;
|
|
38
|
+
readyTimer;
|
|
39
|
+
settleReady = () => { };
|
|
40
|
+
attrEl;
|
|
41
|
+
mapEl;
|
|
42
|
+
frameEl;
|
|
43
|
+
scalelineEl;
|
|
44
|
+
scaletextEl;
|
|
45
|
+
map;
|
|
46
|
+
tiles;
|
|
47
|
+
latlngs;
|
|
48
|
+
bb;
|
|
49
|
+
layout;
|
|
50
|
+
decor;
|
|
51
|
+
altEl = null;
|
|
52
|
+
speedEl = null;
|
|
53
|
+
curIdx = 0;
|
|
54
|
+
constructor(host, firstData, L) {
|
|
55
|
+
this.host = host;
|
|
56
|
+
this.data = firstData;
|
|
57
|
+
this.L = L;
|
|
58
|
+
host.classList.add(this.scopeClass);
|
|
59
|
+
this.styleEl = document.createElement('style');
|
|
60
|
+
document.head.appendChild(this.styleEl);
|
|
61
|
+
host.innerHTML = mapMarkup(firstData.hud, firstData.attribution);
|
|
62
|
+
this.attrEl = el(host, '#attr');
|
|
63
|
+
this.applyChrome();
|
|
64
|
+
this.mapEl = el(host, '#map');
|
|
65
|
+
this.map = L.map(this.mapEl, {
|
|
66
|
+
zoomControl: false,
|
|
67
|
+
attributionControl: false,
|
|
68
|
+
dragging: false,
|
|
69
|
+
scrollWheelZoom: false,
|
|
70
|
+
doubleClickZoom: false,
|
|
71
|
+
boxZoom: false,
|
|
72
|
+
keyboard: false,
|
|
73
|
+
touchZoom: false,
|
|
74
|
+
fadeAnimation: false,
|
|
75
|
+
zoomAnimation: false,
|
|
76
|
+
markerZoomAnimation: false,
|
|
77
|
+
preferCanvas: true,
|
|
78
|
+
zoomSnap: 1,
|
|
79
|
+
});
|
|
80
|
+
this.tiles = this.makeTileLayer(firstData.tileUrl, firstData.style);
|
|
81
|
+
this.tiles.addTo(this.map);
|
|
82
|
+
this.latlngs = this.latlngsOf(firstData);
|
|
83
|
+
this.bb = L.latLngBounds(this.latlngs);
|
|
84
|
+
this.frameEl = el(host, '#map-frame');
|
|
85
|
+
this.scalelineEl = el(host, '#scaleline');
|
|
86
|
+
this.scaletextEl = el(host, '#scaletext');
|
|
87
|
+
// Before the decorations below: Leaflet defers marker DOM creation until
|
|
88
|
+
// the map has a view, so the arrow/wrap elements only exist after this
|
|
89
|
+
// first call.
|
|
90
|
+
this.layoutMap();
|
|
91
|
+
this.decor = this.buildDecor();
|
|
92
|
+
this.rebuildHud();
|
|
93
|
+
this.ready = new Promise((resolve) => {
|
|
94
|
+
const markReady = () => resolve();
|
|
95
|
+
this.settleReady = markReady;
|
|
96
|
+
this.tiles.on('load', markReady);
|
|
97
|
+
this.readyTimer = setTimeout(markReady, 12000);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
scale() {
|
|
101
|
+
return computeScale(this.data.width, this.data.height);
|
|
102
|
+
}
|
|
103
|
+
makeTileLayer(tileUrl, style) {
|
|
104
|
+
return this.L.tileLayer(tileUrl, {
|
|
105
|
+
maxZoom: TILE_SOURCES[style].maxZoom,
|
|
106
|
+
maxNativeZoom: TILE_SOURCES[style].maxNativeZoom ?? undefined,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
latlngsOf(data) {
|
|
110
|
+
return data.lat.map((la, i) => [la, data.lon[i]]);
|
|
111
|
+
}
|
|
112
|
+
applyChrome() {
|
|
113
|
+
this.styleEl.textContent = sceneCss(TILE_SOURCES[this.data.style], themeFor(this.data.style), this.data.width, this.data.height, this.scale(), this.scopeClass);
|
|
114
|
+
this.attrEl.innerHTML = this.data.attribution;
|
|
115
|
+
quietAttributionLinks(this.attrEl);
|
|
116
|
+
}
|
|
117
|
+
// The map fills its frame at any size (headless: the export canvas; app:
|
|
118
|
+
// the pane currently holding it), so every frame size change re-lays out.
|
|
119
|
+
layoutMap() {
|
|
120
|
+
const { data, map, mapEl, frameEl } = this;
|
|
121
|
+
const vw = frameEl.clientWidth || data.width;
|
|
122
|
+
const vh = frameEl.clientHeight || data.height;
|
|
123
|
+
let bigW;
|
|
124
|
+
let bigH;
|
|
125
|
+
if (data.view === 'follow') {
|
|
126
|
+
const pb1 = map.project(this.bb.getNorthWest(), data.zoom);
|
|
127
|
+
const pb2 = map.project(this.bb.getSouthEast(), data.zoom);
|
|
128
|
+
bigW = Math.max(2 * vw, Math.ceil(Math.abs(pb2.x - pb1.x) + 2 * vw));
|
|
129
|
+
bigH = Math.max(2 * vh, Math.ceil(Math.abs(pb2.y - pb1.y) + 2 * vh));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
bigW = 2 * vw;
|
|
133
|
+
bigH = 2 * vh;
|
|
134
|
+
}
|
|
135
|
+
mapEl.style.width = bigW + 'px';
|
|
136
|
+
mapEl.style.height = bigH + 'px';
|
|
137
|
+
map.invalidateSize();
|
|
138
|
+
map.setView(data.view === 'follow' ? this.bb.getCenter() : [data.center.lat, data.center.lon], data.zoom);
|
|
139
|
+
const c0 = map.project(map.getCenter(), data.zoom);
|
|
140
|
+
// Static scale bar (the map never zooms during a render).
|
|
141
|
+
const latC = data.view === 'follow' ? this.bb.getCenter().lat : data.center.lat;
|
|
142
|
+
const mPerPx = metersPerPixel(latC, data.zoom);
|
|
143
|
+
const bestM = scaleBarMeters(mPerPx, 110 * this.scale());
|
|
144
|
+
this.scalelineEl.style.width = Math.round(bestM / mPerPx) + 'px';
|
|
145
|
+
this.scaletextEl.textContent = bestM >= 1000 ? bestM / 1000 + ' km' : bestM + ' m';
|
|
146
|
+
this.layout = { vw, vh, bigW, bigH, c0, bestM, mPerPx };
|
|
147
|
+
}
|
|
148
|
+
buildGhostLayers(theme, ghostLatlngs, ghostDash) {
|
|
149
|
+
const s = this.scale();
|
|
150
|
+
const layers = [];
|
|
151
|
+
if (theme.ghostCasing) {
|
|
152
|
+
const ghostCasing = this.L.polyline(ghostLatlngs, {
|
|
153
|
+
color: theme.ghostCasing,
|
|
154
|
+
weight: Math.max(3, 4.6 * s),
|
|
155
|
+
opacity: 1,
|
|
156
|
+
dashArray: ghostDash,
|
|
157
|
+
lineCap: 'round',
|
|
158
|
+
smoothFactor: 0,
|
|
159
|
+
});
|
|
160
|
+
ghostCasing.addTo(this.map);
|
|
161
|
+
layers.push(ghostCasing);
|
|
162
|
+
}
|
|
163
|
+
const ghost = this.L.polyline(ghostLatlngs, {
|
|
164
|
+
color: theme.ghost,
|
|
165
|
+
weight: Math.max(2, 2.8 * s),
|
|
166
|
+
opacity: theme.ghostOpacity,
|
|
167
|
+
dashArray: ghostDash,
|
|
168
|
+
lineCap: 'round',
|
|
169
|
+
smoothFactor: 0,
|
|
170
|
+
});
|
|
171
|
+
ghost.addTo(this.map);
|
|
172
|
+
layers.push(ghost);
|
|
173
|
+
return layers;
|
|
174
|
+
}
|
|
175
|
+
// The live trail layers (empty until the controller fills them): glow,
|
|
176
|
+
// casing and core, thickest first so the core stays on top.
|
|
177
|
+
buildTrailLayers(theme) {
|
|
178
|
+
// All geometry is pre-decimated (smoothFactor 0 skips Leaflet's own
|
|
179
|
+
// simplification) and the canvas renderer keeps redraws rAF-batched.
|
|
180
|
+
const wCore = Math.max(3, 5.5 * this.scale());
|
|
181
|
+
const trailGlow = this.L.polyline([], {
|
|
182
|
+
color: theme.glow,
|
|
183
|
+
weight: wCore * 2.6,
|
|
184
|
+
opacity: 1,
|
|
185
|
+
lineCap: 'round',
|
|
186
|
+
lineJoin: 'round',
|
|
187
|
+
smoothFactor: 0,
|
|
188
|
+
});
|
|
189
|
+
trailGlow.addTo(this.map);
|
|
190
|
+
const trailCasing = this.L.polyline([], {
|
|
191
|
+
color: theme.casing,
|
|
192
|
+
weight: wCore * 1.6,
|
|
193
|
+
opacity: 0.9,
|
|
194
|
+
lineCap: 'round',
|
|
195
|
+
lineJoin: 'round',
|
|
196
|
+
smoothFactor: 0,
|
|
197
|
+
});
|
|
198
|
+
trailCasing.addTo(this.map);
|
|
199
|
+
const trail = this.L.polyline([], {
|
|
200
|
+
color: theme.core,
|
|
201
|
+
weight: wCore,
|
|
202
|
+
opacity: 1,
|
|
203
|
+
lineCap: 'round',
|
|
204
|
+
lineJoin: 'round',
|
|
205
|
+
smoothFactor: 0,
|
|
206
|
+
});
|
|
207
|
+
trail.addTo(this.map);
|
|
208
|
+
return [trail, trailGlow, trailCasing];
|
|
209
|
+
}
|
|
210
|
+
buildMarker(theme, s) {
|
|
211
|
+
const startDot = this.L.circleMarker(this.latlngs[0], {
|
|
212
|
+
radius: Math.round(7 * s),
|
|
213
|
+
color: '#ffffff',
|
|
214
|
+
weight: Math.max(2, 2 * s),
|
|
215
|
+
fillColor: theme.core,
|
|
216
|
+
fillOpacity: 1,
|
|
217
|
+
});
|
|
218
|
+
startDot.addTo(this.map);
|
|
219
|
+
const drone = this.L.marker(this.latlngs[0], {
|
|
220
|
+
icon: this.L.divIcon({
|
|
221
|
+
className: 'drone-icon',
|
|
222
|
+
html: droneMarkerMarkup(theme.core),
|
|
223
|
+
iconSize: [Math.round(46 * s), Math.round(46 * s)],
|
|
224
|
+
iconAnchor: [Math.round(23 * s), Math.round(23 * s)],
|
|
225
|
+
}),
|
|
226
|
+
interactive: false,
|
|
227
|
+
keyboard: false,
|
|
228
|
+
});
|
|
229
|
+
drone.addTo(this.map);
|
|
230
|
+
return { startDot, drone };
|
|
231
|
+
}
|
|
232
|
+
buildDecor() {
|
|
233
|
+
const theme = themeFor(this.data.style);
|
|
234
|
+
const s = this.scale();
|
|
235
|
+
const ghostLatlngs = this.data.trailLat.map((la, i) => [la, this.data.trailLon[i]]);
|
|
236
|
+
const ghostDash = Math.round(7 * s) + ' ' + Math.round(9 * s);
|
|
237
|
+
const ghostLayers = this.buildGhostLayers(theme, ghostLatlngs, ghostDash);
|
|
238
|
+
const trailLayers = this.buildTrailLayers(theme);
|
|
239
|
+
const { startDot, drone } = this.buildMarker(theme, s);
|
|
240
|
+
const decor = {
|
|
241
|
+
layers: [...trailLayers, startDot, drone, ...ghostLayers],
|
|
242
|
+
trailLayers,
|
|
243
|
+
drone,
|
|
244
|
+
trailCtl: createTrailController({
|
|
245
|
+
lat: this.data.trailLat,
|
|
246
|
+
lon: this.data.trailLon,
|
|
247
|
+
frame: this.data.trailFrame,
|
|
248
|
+
}, { lat: this.data.lat, lon: this.data.lon }, trailLayers),
|
|
249
|
+
arrowEl: this.host.querySelector('#drone-arrow'),
|
|
250
|
+
wrapEl: this.host.querySelector('.drone-wrap'),
|
|
251
|
+
};
|
|
252
|
+
if (!this.data.hud.heading && decor.arrowEl)
|
|
253
|
+
decor.arrowEl.style.display = 'none';
|
|
254
|
+
return decor;
|
|
255
|
+
}
|
|
256
|
+
rebuildDecor() {
|
|
257
|
+
for (const layer of this.decor.layers)
|
|
258
|
+
layer.remove();
|
|
259
|
+
this.decor = this.buildDecor();
|
|
260
|
+
}
|
|
261
|
+
rebuildHud() {
|
|
262
|
+
el(this.host, '#hud').innerHTML = hudMarkup(this.data.hud);
|
|
263
|
+
this.altEl = this.host.querySelector('#chip-alt .num');
|
|
264
|
+
this.speedEl = this.host.querySelector('#chip-speed .num');
|
|
265
|
+
if (this.decor.arrowEl) {
|
|
266
|
+
this.decor.arrowEl.style.display = this.data.hud.heading ? '' : 'none';
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
updateTransform(i, k) {
|
|
270
|
+
const { data, layout, decor, mapEl } = this;
|
|
271
|
+
let dx = 0;
|
|
272
|
+
let dy = 0;
|
|
273
|
+
if (data.view === 'follow') {
|
|
274
|
+
const p = this.map.project(this.latlngs[i], data.zoom);
|
|
275
|
+
dx = p.x - layout.c0.x;
|
|
276
|
+
dy = p.y - layout.c0.y;
|
|
277
|
+
}
|
|
278
|
+
mapEl.style.transform =
|
|
279
|
+
'translate(' + (layout.vw / 2 - layout.bigW / 2 - k * dx) + 'px,' +
|
|
280
|
+
(layout.vh / 2 - layout.bigH / 2 - k * dy) + 'px) scale(' + k + ')';
|
|
281
|
+
if (decor.wrapEl) {
|
|
282
|
+
decor.wrapEl.style.transform = k === 1 ? '' : 'scale(' + 1 / k + ')';
|
|
283
|
+
}
|
|
284
|
+
this.scalelineEl.style.width = Math.round((layout.bestM / layout.mPerPx) * k) + 'px';
|
|
285
|
+
if (data.hud.heading && decor.arrowEl) {
|
|
286
|
+
decor.arrowEl.style.transform = 'rotate(' + data.headingDeg[i] + 'deg)';
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
updateHud(i) {
|
|
290
|
+
setChipText(this.altEl, this.data.alt[i], (a) => String(Math.round(a)));
|
|
291
|
+
setChipText(this.speedEl, this.data.speed[i], (s) => s.toFixed(1));
|
|
292
|
+
}
|
|
293
|
+
setFrame(i) {
|
|
294
|
+
this.curIdx = i;
|
|
295
|
+
this.decor.trailCtl.setFrame(i);
|
|
296
|
+
this.decor.drone.setLatLng(this.latlngs[i]);
|
|
297
|
+
const k = introOutroScale(i, this.data.introN, this.data.outroN, this.data.lat.length);
|
|
298
|
+
this.updateTransform(i, k);
|
|
299
|
+
this.updateHud(i);
|
|
300
|
+
// Canvas painting is deferred to requestAnimationFrame; the headless
|
|
301
|
+
// capture awaits this barrier so screenshots never catch the previous
|
|
302
|
+
// frame.
|
|
303
|
+
return new Promise((resolve) => {
|
|
304
|
+
requestAnimationFrame(() => {
|
|
305
|
+
requestAnimationFrame(() => resolve());
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
relayout() {
|
|
310
|
+
this.layoutMap();
|
|
311
|
+
void this.setFrame(this.curIdx);
|
|
312
|
+
}
|
|
313
|
+
update(next) {
|
|
314
|
+
const prev = this.data;
|
|
315
|
+
this.data = next;
|
|
316
|
+
if (next.lat !== prev.lat) {
|
|
317
|
+
this.latlngs = this.latlngsOf(next);
|
|
318
|
+
this.bb = this.L.latLngBounds(this.latlngs);
|
|
319
|
+
}
|
|
320
|
+
const chromeChanged = next.style !== prev.style ||
|
|
321
|
+
next.width !== prev.width ||
|
|
322
|
+
next.height !== prev.height ||
|
|
323
|
+
next.attribution !== prev.attribution;
|
|
324
|
+
if (chromeChanged)
|
|
325
|
+
this.applyChrome();
|
|
326
|
+
if (next.style !== prev.style) {
|
|
327
|
+
// The zoom constraints are per source (topo tiles are native to z17),
|
|
328
|
+
// so a style switch swaps the layer instead of only its URL.
|
|
329
|
+
this.tiles.remove();
|
|
330
|
+
this.tiles = this.makeTileLayer(next.tileUrl, next.style);
|
|
331
|
+
this.tiles.addTo(this.map);
|
|
332
|
+
}
|
|
333
|
+
else if (next.tileUrl !== prev.tileUrl) {
|
|
334
|
+
this.tiles.setUrl(next.tileUrl);
|
|
335
|
+
}
|
|
336
|
+
const decorInvalidated = next.style !== prev.style ||
|
|
337
|
+
next.trailLat !== prev.trailLat ||
|
|
338
|
+
next.lat !== prev.lat ||
|
|
339
|
+
next.width !== prev.width ||
|
|
340
|
+
next.height !== prev.height;
|
|
341
|
+
if (decorInvalidated)
|
|
342
|
+
this.rebuildDecor();
|
|
343
|
+
if (!hudEq(prev.hud, next.hud))
|
|
344
|
+
this.rebuildHud();
|
|
345
|
+
this.layoutMap();
|
|
346
|
+
return this.setFrame(this.curIdx);
|
|
347
|
+
}
|
|
348
|
+
dispose() {
|
|
349
|
+
clearTimeout(this.readyTimer);
|
|
350
|
+
this.settleReady();
|
|
351
|
+
this.map.remove();
|
|
352
|
+
this.styleEl.remove();
|
|
353
|
+
this.host.classList.remove(this.scopeClass);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
export function createScene(host, firstData, deps) {
|
|
357
|
+
return new SceneState(host, firstData, deps.L);
|
|
358
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Per-style renderer colors. One mapping so the generated page and the app's
|
|
2
|
+
// map island can never drift apart. The trail core is shared across styles so
|
|
3
|
+
// every flight trail wears the one palette accent (#147).
|
|
4
|
+
/** The flight-trail color: the palette accent, one color everywhere. */
|
|
5
|
+
const TRAIL_COLOR = '#e87f54';
|
|
6
|
+
function trailGlow(alpha) {
|
|
7
|
+
const [r, g, b] = [1, 3, 5].map((i) => Number.parseInt(TRAIL_COLOR.slice(i, i + 2), 16));
|
|
8
|
+
return `rgba(${r},${g},${b},${alpha})`;
|
|
9
|
+
}
|
|
10
|
+
const THEMES = {
|
|
11
|
+
satellite: {
|
|
12
|
+
core: TRAIL_COLOR,
|
|
13
|
+
glow: trailGlow(0.32),
|
|
14
|
+
casing: 'rgba(10,14,20,0.9)',
|
|
15
|
+
ghost: '#ffffff',
|
|
16
|
+
ghostOpacity: 0.85,
|
|
17
|
+
ghostCasing: 'rgba(8,12,18,0.55)',
|
|
18
|
+
discBg: 'rgba(10,14,20,0.82)',
|
|
19
|
+
vignette: 0.16,
|
|
20
|
+
},
|
|
21
|
+
topo: {
|
|
22
|
+
core: TRAIL_COLOR,
|
|
23
|
+
glow: trailGlow(0.26),
|
|
24
|
+
casing: '#ffffff',
|
|
25
|
+
ghost: '#6b6252',
|
|
26
|
+
ghostOpacity: 0.7,
|
|
27
|
+
ghostCasing: 'rgba(255,255,255,0.8)',
|
|
28
|
+
discBg: 'rgba(26,22,18,0.85)',
|
|
29
|
+
vignette: 0.06,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
export function themeFor(style) {
|
|
33
|
+
return THEMES[style];
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The tile-source vocabulary: where tiles come from and how they look. Pure
|
|
2
|
+
// data shared by the tile pipeline (Node) and the shared map renderer
|
|
3
|
+
// (browser); cache layout lives in tilecache.ts, download logic in tiles.ts.
|
|
4
|
+
// Lives inside renderer/ so the browser-served module graph stays within
|
|
5
|
+
// that directory.
|
|
6
|
+
export const TILE_SOURCES = {
|
|
7
|
+
// Esri World Imagery (free for non-commercial use, attribution required).
|
|
8
|
+
// Tiles are JPEG; the cache filename stays .png and browsers decode by
|
|
9
|
+
// content, which is fine for Leaflet <img> tiles.
|
|
10
|
+
satellite: {
|
|
11
|
+
cacheKey: 'esri-imagery',
|
|
12
|
+
url: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
|
|
13
|
+
subdomains: [''],
|
|
14
|
+
attribution: 'Imagery © <a href="https://www.esri.com/">Esri</a>, Maxar, Earthstar Geographics, and the GIS User Community',
|
|
15
|
+
bg: '#0b0e14',
|
|
16
|
+
placeholderBg: '#2a2f38',
|
|
17
|
+
tileFilter: 'saturate(1.06) contrast(1.03)',
|
|
18
|
+
maxZoom: 19,
|
|
19
|
+
},
|
|
20
|
+
// OpenTopoMap: OSM topography with contour lines and shaded relief - rich
|
|
21
|
+
// detail in alpine terrain. Tiles are native to z17; Leaflet auto-scales
|
|
22
|
+
// them above that (maxNativeZoom), so the view zoom stays style-independent.
|
|
23
|
+
topo: {
|
|
24
|
+
cacheKey: 'opentopomap',
|
|
25
|
+
url: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
|
|
26
|
+
subdomains: ['a', 'b', 'c'],
|
|
27
|
+
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, SRTM | Style: © <a href="https://opentopomap.org">OpenTopoMap</a> (CC-BY-SA)',
|
|
28
|
+
bg: '#eae5da',
|
|
29
|
+
placeholderBg: '#eae5da',
|
|
30
|
+
tileFilter: null,
|
|
31
|
+
maxZoom: 19,
|
|
32
|
+
maxNativeZoom: 17,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Trail growth state machine shared by the headless renderer and the app: at
|
|
2
|
+
// frame i the trail is the flown path so far - the decimated prefix before i
|
|
3
|
+
// plus the live tip at the frame's own position. The tip tracks the drone so
|
|
4
|
+
// the trail grows every frame (a prefix of decimated points alone stays empty
|
|
5
|
+
// for whole flights whenever the geometry collapses, #95), while the kept
|
|
6
|
+
// prefix stays bounded by the decimation budget. A changed frame pushes one
|
|
7
|
+
// setLatLngs per layer; repeated frames and empty tracks stay quiet.
|
|
8
|
+
// Largest k with trailFrame[k] <= i (trailFrame is strictly increasing):
|
|
9
|
+
// the textbook upper bound stepped back one; -1 when every point is later.
|
|
10
|
+
export function lastIndexAtOrBefore(trailFrame, i) {
|
|
11
|
+
let lo = 0;
|
|
12
|
+
let hi = trailFrame.length - 1;
|
|
13
|
+
let k = -1;
|
|
14
|
+
while (lo <= hi) {
|
|
15
|
+
const mid = (lo + hi) >> 1;
|
|
16
|
+
if (trailFrame[mid] <= i) {
|
|
17
|
+
k = mid;
|
|
18
|
+
lo = mid + 1;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
hi = mid - 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return k;
|
|
25
|
+
}
|
|
26
|
+
export function createTrailController(trail, frames, layers) {
|
|
27
|
+
let lastFrame = null;
|
|
28
|
+
let drawn = false;
|
|
29
|
+
return {
|
|
30
|
+
setFrame(i) {
|
|
31
|
+
if (i === lastFrame)
|
|
32
|
+
return;
|
|
33
|
+
const tip = i >= 0 && i < frames.lat.length ? [frames.lat[i], frames.lon[i]] : null;
|
|
34
|
+
// The tip already carries the frame's own position, so a kept point at
|
|
35
|
+
// exactly frame i would only duplicate it.
|
|
36
|
+
let end = lastIndexAtOrBefore(trail.frame, i);
|
|
37
|
+
if (tip !== null && trail.frame[end] === i)
|
|
38
|
+
end -= 1;
|
|
39
|
+
const points = [];
|
|
40
|
+
for (let j = 0; j <= end; j++)
|
|
41
|
+
points.push([trail.lat[j], trail.lon[j]]);
|
|
42
|
+
if (tip !== null)
|
|
43
|
+
points.push(tip);
|
|
44
|
+
lastFrame = i;
|
|
45
|
+
// Fresh layers already hold an empty path; only clear what was drawn.
|
|
46
|
+
if (points.length === 0 && !drawn)
|
|
47
|
+
return;
|
|
48
|
+
drawn = points.length > 0;
|
|
49
|
+
for (const layer of layers)
|
|
50
|
+
layer.setLatLngs(points);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
package/dist/restyle.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Settings -> scene mapping for the app's live restyle. It runs the very
|
|
2
|
+
// planning the pipeline runs (page.planPageOpts over the telemetry's fix
|
|
3
|
+
// bbox), so a preview and an export from the same settings agree frame for
|
|
4
|
+
// frame. Pure (no DOM, no I/O): the browser UI and unit tests drive it
|
|
5
|
+
// directly.
|
|
6
|
+
import { buildSceneData, planPageOpts } from './page.js';
|
|
7
|
+
export function restyleSceneData(prev, config, meta,
|
|
8
|
+
// The output size to plan at: the export preview plans at the size the
|
|
9
|
+
// pipeline will render, while the player keeps the prepared scene's own.
|
|
10
|
+
size = { width: prev.width, height: prev.height }) {
|
|
11
|
+
const planned = planPageOpts({
|
|
12
|
+
bbox: meta.bbox,
|
|
13
|
+
width: size.width,
|
|
14
|
+
height: size.height,
|
|
15
|
+
config,
|
|
16
|
+
source: { fps: meta.fps, frames: meta.frames },
|
|
17
|
+
frames: prev,
|
|
18
|
+
previous: {
|
|
19
|
+
zoom: prev.zoom,
|
|
20
|
+
decimated: { lat: prev.trailLat, lon: prev.trailLon, frame: prev.trailFrame },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return buildSceneData(planned, meta.tileBase);
|
|
24
|
+
}
|