drone-path-engine 0.0.0-stage → 1.0.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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -2
  3. package/THIRD-PARTY-NOTICES.md +11 -0
  4. package/dist/assets.d.ts +34 -0
  5. package/dist/assets.js +60 -0
  6. package/dist/config.d.ts +208 -0
  7. package/dist/config.js +577 -0
  8. package/dist/configfile.d.ts +20 -0
  9. package/dist/configfile.js +82 -0
  10. package/dist/decimate.d.ts +2 -0
  11. package/dist/decimate.js +1 -0
  12. package/dist/ffmpeg-output.d.ts +9 -0
  13. package/dist/ffmpeg-output.js +40 -0
  14. package/dist/logging.d.ts +1 -0
  15. package/dist/logging.js +1 -0
  16. package/dist/paths.d.ts +4 -0
  17. package/dist/paths.js +21 -0
  18. package/dist/pipeline.d.ts +90 -0
  19. package/dist/pipeline.js +436 -0
  20. package/dist/plan.d.ts +47 -0
  21. package/dist/plan.js +113 -0
  22. package/dist/png.d.ts +1 -0
  23. package/dist/png.js +32 -0
  24. package/dist/range.d.ts +19 -0
  25. package/dist/range.js +50 -0
  26. package/dist/recordings.d.ts +5 -0
  27. package/dist/recordings.js +45 -0
  28. package/dist/render-page.d.ts +35 -0
  29. package/dist/render-page.js +85 -0
  30. package/dist/render.d.ts +57 -0
  31. package/dist/render.js +397 -0
  32. package/dist/renderer/boot.d.ts +4 -0
  33. package/dist/renderer/boot.js +28 -0
  34. package/dist/renderer/dom.d.ts +28 -0
  35. package/dist/renderer/dom.js +179 -0
  36. package/dist/renderer/framemath.d.ts +5 -0
  37. package/dist/renderer/framemath.js +30 -0
  38. package/dist/renderer/scene.d.ts +38 -0
  39. package/dist/renderer/scene.js +394 -0
  40. package/dist/renderer/theme.d.ts +13 -0
  41. package/dist/renderer/theme.js +82 -0
  42. package/dist/renderer/tilesources.d.ts +14 -0
  43. package/dist/renderer/tilesources.js +38 -0
  44. package/dist/renderer/trail.d.ts +18 -0
  45. package/dist/renderer/trail.js +42 -0
  46. package/dist/restyle.d.ts +13 -0
  47. package/dist/restyle.js +16 -0
  48. package/dist/serve.d.ts +6 -0
  49. package/dist/serve.js +27 -0
  50. package/dist/tilecache.d.ts +12 -0
  51. package/dist/tilecache.js +21 -0
  52. package/dist/tiles.d.ts +25 -0
  53. package/dist/tiles.js +215 -0
  54. package/dist/version.d.ts +1 -0
  55. package/dist/version.js +3 -0
  56. package/package.json +37 -4
@@ -0,0 +1,38 @@
1
+ import type { HudLayout, MapStyle, ViewMode } from '../config.js';
2
+ import type { LatLon } from 'drone-path-core/geo';
3
+ import type { StripLabels } from './dom.js';
4
+ import type * as Leaflet from 'leaflet';
5
+ import type { FrameChannels } from 'drone-path-core/telemetry-math';
6
+ export type LeafletApi = typeof Leaflet;
7
+ export interface SceneData extends FrameChannels {
8
+ style: MapStyle;
9
+ trailColor: string | null;
10
+ tileUrl: string;
11
+ view: ViewMode;
12
+ width: number;
13
+ height: number;
14
+ zoom: number;
15
+ center: LatLon;
16
+ attribution: string;
17
+ introN: number;
18
+ outroN: number;
19
+ hud: HudLayout;
20
+ /** Whether this viewer draws the in-frame HUD pills; a caller that overlays
21
+ its own toggles (the Map appearance preview) sets this to false. */
22
+ hudPills?: boolean;
23
+ stripLabels?: StripLabels;
24
+ trailLat: number[];
25
+ trailLon: number[];
26
+ trailFrame: number[];
27
+ }
28
+ export interface Scene {
29
+ setFrame(i: number): Promise<void>;
30
+ relayout(): void;
31
+ update(data: SceneData): Promise<void>;
32
+ ready: Promise<void>;
33
+ dispose(): void;
34
+ }
35
+ export declare function createScene(host: HTMLElement, firstData: SceneData, deps: {
36
+ L: LeafletApi;
37
+ hudHost?: HTMLElement;
38
+ }): Scene;
@@ -0,0 +1,394 @@
1
+ import { TILE_SOURCES } from './tilesources.js';
2
+ import { droneMarkerMarkup, el, hudMarkup, mapMarkup, quietAttributionLinks, sceneCss, stripReadoutMarkup } from './dom.js';
3
+ import { computeScale, introOutroScale, metersPerPixel, scaleBarMeters } from './framemath.js';
4
+ import { themeFor } from './theme.js';
5
+ import { createTrailController } from './trail.js';
6
+ function hudEq(a, b) {
7
+ return (a.heading === b.heading && a.alt === b.alt && a.speed === b.speed);
8
+ }
9
+ /** A missing value renders exactly like a disabled chip: the dimmed "--". */
10
+ function isMissing(value) {
11
+ return value === null || value === undefined;
12
+ }
13
+ function setChipText(chip, value, format) {
14
+ if (!chip)
15
+ return;
16
+ chip.textContent = isMissing(value) ? '--' : format(value);
17
+ }
18
+ let scopeCount = 0;
19
+ class SceneState {
20
+ ready;
21
+ data;
22
+ L;
23
+ host;
24
+ scopeClass = `scene-scope-${(scopeCount += 1)}`;
25
+ styleEl;
26
+ readyTimer;
27
+ settleReady = () => { };
28
+ attrEl;
29
+ mapEl;
30
+ frameEl;
31
+ scalelineEl;
32
+ scaletextEl;
33
+ map;
34
+ tiles;
35
+ latlngs;
36
+ bb;
37
+ layout;
38
+ decor;
39
+ headingChip = null;
40
+ altChip = null;
41
+ speedChip = null;
42
+ /** Chip container: inside the map frame for exports, or an external strip. */
43
+ hudRoot;
44
+ /** External strips get the column markup; the export frame keeps its pills. */
45
+ externalHud;
46
+ curIdx = 0;
47
+ disposed = false;
48
+ constructor(host, firstData, L, hudHost) {
49
+ this.host = host;
50
+ this.data = firstData;
51
+ this.L = L;
52
+ host.classList.add(this.scopeClass);
53
+ this.styleEl = document.createElement('style');
54
+ document.head.appendChild(this.styleEl);
55
+ // One definedness rule for both: a caller either supplies the external
56
+ // strip host or gets the in-frame export HUD, never a mix of the two.
57
+ const externalHud = hudHost !== undefined;
58
+ host.innerHTML = mapMarkup(externalHud ? null : firstData.hud, firstData.attribution);
59
+ this.hudRoot = hudHost ?? el(host, '#hud');
60
+ this.externalHud = externalHud;
61
+ this.attrEl = el(host, '#attr');
62
+ this.applyChrome();
63
+ this.mapEl = el(host, '#map');
64
+ this.map = L.map(this.mapEl, {
65
+ zoomControl: false,
66
+ attributionControl: false,
67
+ dragging: false,
68
+ scrollWheelZoom: false,
69
+ doubleClickZoom: false,
70
+ boxZoom: false,
71
+ keyboard: false,
72
+ touchZoom: false,
73
+ fadeAnimation: false,
74
+ zoomAnimation: false,
75
+ markerZoomAnimation: false,
76
+ preferCanvas: true,
77
+ zoomSnap: 1,
78
+ });
79
+ this.tiles = this.makeTileLayer(firstData.tileUrl, firstData.style);
80
+ this.tiles.addTo(this.map);
81
+ this.latlngs = this.latlngsOf(firstData);
82
+ this.bb = L.latLngBounds(this.latlngs);
83
+ this.frameEl = el(host, '#map-frame');
84
+ this.scalelineEl = el(host, '#scaleline');
85
+ this.scaletextEl = el(host, '#scaletext');
86
+ // Leaflet only creates marker DOM once the map has a view: layoutMap() must precede buildDecor() so the arrow/wrap elements exist.
87
+ this.layoutMap();
88
+ this.decor = this.buildDecor();
89
+ this.rebuildHud();
90
+ this.ready = new Promise((resolve) => {
91
+ const markReady = () => {
92
+ clearTimeout(this.readyTimer);
93
+ this.readyTimer = undefined;
94
+ resolve();
95
+ };
96
+ this.settleReady = markReady;
97
+ this.tiles.once('load', markReady);
98
+ this.readyTimer = setTimeout(markReady, 12000);
99
+ });
100
+ }
101
+ scale() {
102
+ return computeScale(this.data.width, this.data.height);
103
+ }
104
+ makeTileLayer(tileUrl, style) {
105
+ return this.L.tileLayer(tileUrl, {
106
+ maxZoom: TILE_SOURCES[style].maxZoom,
107
+ maxNativeZoom: TILE_SOURCES[style].maxNativeZoom ?? undefined,
108
+ });
109
+ }
110
+ latlngsOf(data) {
111
+ return data.lat.map((la, i) => [la, data.lon[i]]);
112
+ }
113
+ applyChrome() {
114
+ this.styleEl.textContent = sceneCss(TILE_SOURCES[this.data.style], themeFor(this.data.style, this.data.trailColor), this.data.width, this.data.height, this.scale(), this.scopeClass);
115
+ this.attrEl.innerHTML = this.data.attribution;
116
+ // The compact map card truncates the credit to one line; the hover title
117
+ // carries the full text wherever the browser can show it.
118
+ this.attrEl.title = this.attrEl.textContent ?? '';
119
+ quietAttributionLinks(this.attrEl);
120
+ }
121
+ layoutMap() {
122
+ const { data, map, mapEl, frameEl } = this;
123
+ const vw = frameEl.clientWidth || data.width;
124
+ const vh = frameEl.clientHeight || data.height;
125
+ let bigW;
126
+ let bigH;
127
+ if (data.view === 'follow') {
128
+ const pb1 = map.project(this.bb.getNorthWest(), data.zoom);
129
+ const pb2 = map.project(this.bb.getSouthEast(), data.zoom);
130
+ bigW = Math.max(2 * vw, Math.ceil(Math.abs(pb2.x - pb1.x) + 2 * vw));
131
+ bigH = Math.max(2 * vh, Math.ceil(Math.abs(pb2.y - pb1.y) + 2 * vh));
132
+ }
133
+ else {
134
+ bigW = 2 * vw;
135
+ bigH = 2 * vh;
136
+ }
137
+ mapEl.style.width = bigW + 'px';
138
+ mapEl.style.height = bigH + 'px';
139
+ map.invalidateSize();
140
+ map.setView(data.view === 'follow' ? this.bb.getCenter() : [data.center.lat, data.center.lon], data.zoom);
141
+ const c0 = map.project(map.getCenter(), data.zoom);
142
+ const latC = data.view === 'follow' ? this.bb.getCenter().lat : data.center.lat;
143
+ const mPerPx = metersPerPixel(latC, data.zoom);
144
+ const bestM = scaleBarMeters(mPerPx, 110 * this.scale());
145
+ this.scalelineEl.style.width = Math.round(bestM / mPerPx) + 'px';
146
+ this.scaletextEl.textContent = bestM >= 1000 ? bestM / 1000 + ' km' : bestM + ' m';
147
+ this.layout = { vw, vh, bigW, bigH, c0, bestM, mPerPx };
148
+ }
149
+ buildGhostLayers(theme, ghostLatlngs, ghostDash) {
150
+ const s = this.scale();
151
+ const layers = [];
152
+ if (theme.ghostCasing) {
153
+ const ghostCasing = this.L.polyline(ghostLatlngs, {
154
+ color: theme.ghostCasing,
155
+ weight: Math.max(3, 4.6 * s),
156
+ opacity: 1,
157
+ dashArray: ghostDash,
158
+ lineCap: 'round',
159
+ smoothFactor: 0,
160
+ });
161
+ ghostCasing.addTo(this.map);
162
+ layers.push(ghostCasing);
163
+ }
164
+ const ghost = this.L.polyline(ghostLatlngs, {
165
+ color: theme.ghost,
166
+ weight: Math.max(2, 2.8 * s),
167
+ opacity: theme.ghostOpacity,
168
+ dashArray: ghostDash,
169
+ lineCap: 'round',
170
+ smoothFactor: 0,
171
+ });
172
+ ghost.addTo(this.map);
173
+ layers.push(ghost);
174
+ return layers;
175
+ }
176
+ // Creation order sets stacking: thickest first so the core stays on top.
177
+ buildTrailLayers(theme) {
178
+ // smoothFactor 0 keeps Leaflet from re-simplifying the pre-decimated path.
179
+ const wCore = Math.max(3, 5.5 * this.scale());
180
+ const trailGlow = this.L.polyline([], {
181
+ color: theme.glow,
182
+ weight: wCore * 2.6,
183
+ opacity: 1,
184
+ lineCap: 'round',
185
+ lineJoin: 'round',
186
+ smoothFactor: 0,
187
+ });
188
+ trailGlow.addTo(this.map);
189
+ const trailCasing = this.L.polyline([], {
190
+ color: theme.casing,
191
+ weight: wCore * 1.6,
192
+ opacity: 0.9,
193
+ lineCap: 'round',
194
+ lineJoin: 'round',
195
+ smoothFactor: 0,
196
+ });
197
+ trailCasing.addTo(this.map);
198
+ const trail = this.L.polyline([], {
199
+ color: theme.trailCore,
200
+ weight: wCore,
201
+ opacity: 1,
202
+ lineCap: 'round',
203
+ lineJoin: 'round',
204
+ smoothFactor: 0,
205
+ });
206
+ trail.addTo(this.map);
207
+ return [trail, trailGlow, trailCasing];
208
+ }
209
+ buildMarker(theme, s) {
210
+ const startDot = this.L.circleMarker(this.latlngs[0], {
211
+ radius: Math.round(7 * s),
212
+ color: '#ffffff',
213
+ weight: Math.max(2, 2 * s),
214
+ fillColor: theme.core,
215
+ fillOpacity: 1,
216
+ });
217
+ startDot.addTo(this.map);
218
+ const drone = this.L.marker(this.latlngs[0], {
219
+ icon: this.L.divIcon({
220
+ className: 'drone-icon',
221
+ html: droneMarkerMarkup(theme.core),
222
+ iconSize: [Math.round(46 * s), Math.round(46 * s)],
223
+ iconAnchor: [Math.round(23 * s), Math.round(23 * s)],
224
+ }),
225
+ interactive: false,
226
+ keyboard: false,
227
+ });
228
+ drone.addTo(this.map);
229
+ return { startDot, drone };
230
+ }
231
+ buildDecor() {
232
+ const theme = themeFor(this.data.style, this.data.trailColor);
233
+ const s = this.scale();
234
+ const ghostLatlngs = this.data.trailLat.map((la, i) => [la, this.data.trailLon[i]]);
235
+ const ghostDash = Math.round(7 * s) + ' ' + Math.round(9 * s);
236
+ const ghostLayers = this.buildGhostLayers(theme, ghostLatlngs, ghostDash);
237
+ const trailLayers = this.buildTrailLayers(theme);
238
+ const { startDot, drone } = this.buildMarker(theme, s);
239
+ const decor = {
240
+ layers: [...trailLayers, startDot, drone, ...ghostLayers],
241
+ trailLayers,
242
+ drone,
243
+ trailCtl: createTrailController({
244
+ lat: this.data.trailLat,
245
+ lon: this.data.trailLon,
246
+ frame: this.data.trailFrame,
247
+ }, { lat: this.data.lat, lon: this.data.lon }, trailLayers),
248
+ arrowEl: this.host.querySelector('#drone-arrow'),
249
+ wrapEl: this.host.querySelector('.drone-wrap'),
250
+ };
251
+ if (!this.data.hud.heading && decor.arrowEl)
252
+ decor.arrowEl.style.display = 'none';
253
+ return decor;
254
+ }
255
+ rebuildDecor() {
256
+ for (const layer of this.decor.layers)
257
+ layer.remove();
258
+ this.decor = this.buildDecor();
259
+ }
260
+ rebuildHud() {
261
+ // Scoped to the chip container so an external strip and a second scene
262
+ // (the export preview) can never cross-write. A scene whose caller
263
+ // overlays its own pills draws none of its own (#283).
264
+ this.hudRoot.innerHTML = this.externalHud
265
+ ? stripReadoutMarkup(this.data.hud, this.data.stripLabels)
266
+ : this.data.hudPills === false
267
+ ? ''
268
+ : hudMarkup(this.data.hud);
269
+ this.headingChip = this.hudRoot.querySelector('#chip-heading');
270
+ this.altChip = this.hudRoot.querySelector('#chip-alt');
271
+ this.speedChip = this.hudRoot.querySelector('#chip-speed');
272
+ if (this.decor.arrowEl) {
273
+ this.decor.arrowEl.style.display = this.data.hud.heading ? '' : 'none';
274
+ }
275
+ }
276
+ updateTransform(i, k) {
277
+ const { data, layout, decor, mapEl } = this;
278
+ let dx = 0;
279
+ let dy = 0;
280
+ if (data.view === 'follow') {
281
+ const p = this.map.project(this.latlngs[i], data.zoom);
282
+ dx = p.x - layout.c0.x;
283
+ dy = p.y - layout.c0.y;
284
+ }
285
+ mapEl.style.transform =
286
+ 'translate(' + (layout.vw / 2 - layout.bigW / 2 - k * dx) + 'px,' +
287
+ (layout.vh / 2 - layout.bigH / 2 - k * dy) + 'px) scale(' + k + ')';
288
+ if (decor.wrapEl) {
289
+ decor.wrapEl.style.transform = k === 1 ? '' : 'scale(' + 1 / k + ')';
290
+ }
291
+ this.scalelineEl.style.width = Math.round((layout.bestM / layout.mPerPx) * k) + 'px';
292
+ if (data.hud.heading && decor.arrowEl) {
293
+ decor.arrowEl.style.transform = 'rotate(' + data.headingDeg[i] + 'deg)';
294
+ }
295
+ }
296
+ updateHud(i) {
297
+ // A disabled chip and a missing sample share one presentation: the dimmed
298
+ // "--" placeholder instead of a value (#272 review).
299
+ this.setReadout(this.altChip, this.data.hud.alt ? this.data.alt[i] : null, (a) => String(Math.round(a)));
300
+ this.setReadout(this.speedChip, this.data.hud.speed ? this.data.speed[i] : null, (s) => s.toFixed(1));
301
+ this.setHeading(this.headingChip, this.data.headingDeg[i]);
302
+ }
303
+ /** The heading pill rotates its arrow like the marker does; a missing
304
+ sample falls back to the dimmed "--", matching the preview chip (#283). */
305
+ setHeading(chip, deg) {
306
+ if (!chip)
307
+ return;
308
+ const missing = isMissing(deg);
309
+ const arrow = chip.querySelector('.chip-arrow');
310
+ const num = chip.querySelector('.num');
311
+ if (arrow) {
312
+ arrow.style.display = missing ? 'none' : '';
313
+ if (!missing)
314
+ arrow.style.transform = 'rotate(' + deg + 'deg)';
315
+ }
316
+ if (num)
317
+ num.style.display = missing ? '' : 'none';
318
+ }
319
+ setReadout(chip, value, format) {
320
+ if (!chip)
321
+ return;
322
+ setChipText(chip.querySelector('.num'), value, format);
323
+ if (this.externalHud)
324
+ chip.classList.toggle('map-readout-off', isMissing(value));
325
+ }
326
+ setFrame(i) {
327
+ this.curIdx = i;
328
+ this.decor.trailCtl.setFrame(i);
329
+ this.decor.drone.setLatLng(this.latlngs[i]);
330
+ const k = introOutroScale(i, this.data.introN, this.data.outroN, this.data.lat.length);
331
+ this.updateTransform(i, k);
332
+ this.updateHud(i);
333
+ // Canvas painting is deferred to requestAnimationFrame
334
+ return new Promise((resolve) => {
335
+ requestAnimationFrame(() => {
336
+ requestAnimationFrame(() => resolve());
337
+ });
338
+ });
339
+ }
340
+ relayout() {
341
+ if (this.disposed)
342
+ return;
343
+ this.layoutMap();
344
+ void this.setFrame(this.curIdx);
345
+ }
346
+ update(next) {
347
+ const prev = this.data;
348
+ this.data = next;
349
+ const styleChanged = next.style !== prev.style;
350
+ const sizeChanged = next.width !== prev.width || next.height !== prev.height;
351
+ const trackChanged = next.lat !== prev.lat || next.lon !== prev.lon;
352
+ if (trackChanged) {
353
+ this.latlngs = this.latlngsOf(next);
354
+ this.bb = this.L.latLngBounds(this.latlngs);
355
+ }
356
+ const lookChanged = styleChanged || next.trailColor !== prev.trailColor || sizeChanged;
357
+ if (lookChanged || next.attribution !== prev.attribution)
358
+ this.applyChrome();
359
+ if (styleChanged) {
360
+ // Zoom constraints are per tile layer (topo is native to z17), so a style switch swaps the layer instead of only its URL.
361
+ this.tiles.remove();
362
+ this.tiles = this.makeTileLayer(next.tileUrl, next.style);
363
+ this.tiles.addTo(this.map);
364
+ }
365
+ else if (next.tileUrl !== prev.tileUrl) {
366
+ this.tiles.setUrl(next.tileUrl);
367
+ }
368
+ const trailChanged = next.trailLat !== prev.trailLat ||
369
+ next.trailLon !== prev.trailLon ||
370
+ next.trailFrame !== prev.trailFrame;
371
+ if (lookChanged || trailChanged || trackChanged)
372
+ this.rebuildDecor();
373
+ if (!hudEq(prev.hud, next.hud) ||
374
+ next.hudPills !== prev.hudPills ||
375
+ next.stripLabels?.speed !== prev.stripLabels?.speed ||
376
+ next.stripLabels?.altitude !== prev.stripLabels?.altitude)
377
+ this.rebuildHud();
378
+ this.layoutMap();
379
+ this.curIdx = Math.max(0, Math.min(this.curIdx, this.latlngs.length - 1));
380
+ return this.setFrame(this.curIdx);
381
+ }
382
+ dispose() {
383
+ this.disposed = true;
384
+ clearTimeout(this.readyTimer);
385
+ this.readyTimer = undefined;
386
+ this.settleReady();
387
+ this.map.remove();
388
+ this.styleEl.remove();
389
+ this.host.classList.remove(this.scopeClass);
390
+ }
391
+ }
392
+ export function createScene(host, firstData, deps) {
393
+ return new SceneState(host, firstData, deps.L, deps.hudHost);
394
+ }
@@ -0,0 +1,13 @@
1
+ import type { MapStyle } from '../config.js';
2
+ export interface Theme {
3
+ core: string;
4
+ trailCore: string;
5
+ glow: string;
6
+ casing: string;
7
+ ghost: string;
8
+ ghostOpacity: number;
9
+ ghostCasing: string | null;
10
+ discBg: string;
11
+ vignette: number;
12
+ }
13
+ export declare function themeFor(style: MapStyle, trailColor?: string | null): Theme;
@@ -0,0 +1,82 @@
1
+ const TRAIL_COLOR = '#e87f54';
2
+ function parseHexColor(hex) {
3
+ const m = /^#([0-9a-f]{6}|[0-9a-f]{8})$/i.exec(hex);
4
+ if (!m)
5
+ throw new Error(`invalid trail color: ${hex}`);
6
+ const [r, g, b, a] = [0, 2, 4, 6].map((i) => i < m[1].length ? Number.parseInt(m[1].slice(i, i + 2), 16) : 255);
7
+ return { r, g, b, a: a / 255 };
8
+ }
9
+ function rgba(c, alpha) {
10
+ return `rgba(${c.r},${c.g},${c.b},${Math.round(alpha * 10000) / 10000})`;
11
+ }
12
+ function luminance(c) {
13
+ const linear = (v) => {
14
+ const s = v / 255;
15
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
16
+ };
17
+ return 0.2126 * linear(c.r) + 0.7152 * linear(c.g) + 0.0722 * linear(c.b);
18
+ }
19
+ function mix(base, tint, amount) {
20
+ const k = (x, y) => Math.round(x + (y - x) * amount);
21
+ return { r: k(base.r, tint.r), g: k(base.g, tint.g), b: k(base.b, tint.b), a: 1 };
22
+ }
23
+ const CASING_ANCHORS = {
24
+ satellite: {
25
+ anchor: { r: 10, g: 14, b: 20, a: 1 },
26
+ opposite: { r: 255, g: 255, b: 255, a: 1 },
27
+ alpha: 0.9,
28
+ },
29
+ topo: {
30
+ anchor: { r: 255, g: 255, b: 255, a: 1 },
31
+ opposite: { r: 10, g: 14, b: 20, a: 1 },
32
+ alpha: 1,
33
+ },
34
+ };
35
+ const CONTRAST_FLIP = 0.18;
36
+ const CORE_TINT = 0.2;
37
+ function deriveCasing(style, core) {
38
+ const { anchor, opposite, alpha } = CASING_ANCHORS[style];
39
+ const base = Math.abs(luminance(core) - luminance(anchor)) < CONTRAST_FLIP ? opposite : anchor;
40
+ return rgba(mix(base, core, CORE_TINT), alpha);
41
+ }
42
+ const GLOW_ALPHA = { satellite: 0.32, topo: 0.26 };
43
+ function trailGlow(alpha) {
44
+ return rgba(parseHexColor(TRAIL_COLOR), alpha);
45
+ }
46
+ const THEMES = {
47
+ satellite: {
48
+ core: TRAIL_COLOR,
49
+ trailCore: TRAIL_COLOR,
50
+ glow: trailGlow(GLOW_ALPHA.satellite),
51
+ casing: 'rgba(10,14,20,0.9)',
52
+ ghost: '#ffffff',
53
+ ghostOpacity: 0.85,
54
+ ghostCasing: 'rgba(8,12,18,0.55)',
55
+ discBg: 'rgba(10,14,20,0.82)',
56
+ vignette: 0.16,
57
+ },
58
+ topo: {
59
+ core: TRAIL_COLOR,
60
+ trailCore: TRAIL_COLOR,
61
+ glow: trailGlow(GLOW_ALPHA.topo),
62
+ casing: '#ffffff',
63
+ ghost: '#6b6252',
64
+ ghostOpacity: 0.7,
65
+ ghostCasing: 'rgba(255,255,255,0.8)',
66
+ discBg: 'rgba(26,22,18,0.85)',
67
+ vignette: 0.06,
68
+ },
69
+ };
70
+ export function themeFor(style, trailColor = null) {
71
+ const base = THEMES[style];
72
+ if (trailColor === null)
73
+ return base;
74
+ const core = parseHexColor(trailColor);
75
+ return {
76
+ ...base,
77
+ core: rgba(core, 1),
78
+ trailCore: trailColor,
79
+ glow: rgba(core, GLOW_ALPHA[style] * core.a),
80
+ casing: deriveCasing(style, core),
81
+ };
82
+ }
@@ -0,0 +1,14 @@
1
+ import type { MapStyle } from '../config.js';
2
+ export interface TileSource {
3
+ cacheKey: string;
4
+ url: string;
5
+ subdomains: string[];
6
+ attribution: string;
7
+ bg: string;
8
+ placeholderBg: string;
9
+ tileFilter: string | null;
10
+ maxZoom: number;
11
+ maxNativeZoom?: number;
12
+ }
13
+ export declare const TILE_SOURCES: Record<MapStyle, TileSource>;
14
+ export declare const TILE_CREDITS: string;
@@ -0,0 +1,38 @@
1
+ export const TILE_SOURCES = {
2
+ // Esri World Imagery (free for non-commercial use, attribution required).
3
+ satellite: {
4
+ cacheKey: 'esri-imagery',
5
+ url: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
6
+ subdomains: [''],
7
+ attribution: 'Imagery &copy; <a href="https://www.esri.com/">Esri</a>, Maxar, Earthstar Geographics, and the GIS User Community',
8
+ bg: '#0b0e14',
9
+ placeholderBg: '#2a2f38',
10
+ tileFilter: 'saturate(1.06) contrast(1.03)',
11
+ maxZoom: 19,
12
+ },
13
+ topo: {
14
+ cacheKey: 'opentopomap',
15
+ url: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
16
+ subdomains: ['a', 'b', 'c'],
17
+ attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, SRTM | Style: &copy; <a href="https://opentopomap.org">OpenTopoMap</a> (CC-BY-SA)',
18
+ bg: '#eae5da',
19
+ placeholderBg: '#eae5da',
20
+ tileFilter: null,
21
+ maxZoom: 19,
22
+ maxNativeZoom: 17,
23
+ },
24
+ };
25
+ /** Leaflet wants HTML and the map style thumbnails plain text; the thumbnail
26
+ credits derive from these attributions so the wording can never drift. */
27
+ function plainCredit(html) {
28
+ return html
29
+ .replaceAll('&copy;', '©')
30
+ .replace(/<a [^>]+>/g, '')
31
+ .replaceAll('</a>', '')
32
+ .split(' | ')
33
+ .map((part) => part.replace('Style: ', 'Style ')); // the thumbnail wording drops the colon
34
+ }
35
+ export const TILE_CREDITS = [
36
+ ...plainCredit(TILE_SOURCES.satellite.attribution),
37
+ ...plainCredit(TILE_SOURCES.topo.attribution),
38
+ ].join(' · ');
@@ -0,0 +1,18 @@
1
+ import type { LatLngTuple } from 'leaflet';
2
+ export interface TrailLayer {
3
+ setLatLngs(points: LatLngTuple[]): void;
4
+ }
5
+ export interface TrailController {
6
+ setFrame(i: number): void;
7
+ }
8
+ export interface TrailTrack {
9
+ lat: readonly number[];
10
+ lon: readonly number[];
11
+ frame: readonly number[];
12
+ }
13
+ export interface FrameTrack {
14
+ lat: readonly number[];
15
+ lon: readonly number[];
16
+ }
17
+ export declare function lastIndexAtOrBefore(trailFrame: readonly number[], i: number): number;
18
+ export declare function createTrailController(trail: TrailTrack, frames: FrameTrack, layers: readonly TrailLayer[]): TrailController;
@@ -0,0 +1,42 @@
1
+ export function lastIndexAtOrBefore(trailFrame, i) {
2
+ let lo = 0;
3
+ let hi = trailFrame.length - 1;
4
+ let k = -1;
5
+ while (lo <= hi) {
6
+ const mid = (lo + hi) >> 1;
7
+ if (trailFrame[mid] <= i) {
8
+ k = mid;
9
+ lo = mid + 1;
10
+ }
11
+ else {
12
+ hi = mid - 1;
13
+ }
14
+ }
15
+ return k;
16
+ }
17
+ export function createTrailController(trail, frames, layers) {
18
+ let lastFrame = null;
19
+ let drawn = false;
20
+ return {
21
+ setFrame(i) {
22
+ if (i === lastFrame)
23
+ return;
24
+ const tip = i >= 0 && i < frames.lat.length ? [frames.lat[i], frames.lon[i]] : null;
25
+ // A kept point at exactly frame i would duplicate the tip's position.
26
+ let end = lastIndexAtOrBefore(trail.frame, i);
27
+ if (tip !== null && trail.frame[end] === i)
28
+ end -= 1;
29
+ const points = [];
30
+ for (let j = 0; j <= end; j++)
31
+ points.push([trail.lat[j], trail.lon[j]]);
32
+ if (tip !== null)
33
+ points.push(tip);
34
+ lastFrame = i;
35
+ if (points.length === 0 && !drawn)
36
+ return;
37
+ drawn = points.length > 0;
38
+ for (const layer of layers)
39
+ layer.setLatLngs(points);
40
+ },
41
+ };
42
+ }
@@ -0,0 +1,13 @@
1
+ import type { AppearanceSettings } from './config.js';
2
+ import type { Bbox } from 'drone-path-core/geo';
3
+ import type { SceneData } from './renderer/scene.js';
4
+ export interface RestyleMeta {
5
+ fps: number;
6
+ frames: number;
7
+ tileBase: string;
8
+ bbox: Bbox;
9
+ }
10
+ export declare function restyleSceneData(prev: SceneData, config: AppearanceSettings, meta: RestyleMeta, size?: {
11
+ width: number;
12
+ height: number;
13
+ }): SceneData;
@@ -0,0 +1,16 @@
1
+ import { buildSceneData, planPageOpts } from './render-page.js';
2
+ export function restyleSceneData(prev, config, meta, size = { width: prev.width, height: prev.height }) {
3
+ const planned = planPageOpts({
4
+ bbox: meta.bbox,
5
+ width: size.width,
6
+ height: size.height,
7
+ config,
8
+ source: { fps: meta.fps, frames: meta.frames },
9
+ frames: prev,
10
+ previous: {
11
+ zoom: prev.zoom,
12
+ decimated: { lat: prev.trailLat, lon: prev.trailLon, frame: prev.trailFrame },
13
+ },
14
+ });
15
+ return buildSceneData(planned, meta.tileBase);
16
+ }
@@ -0,0 +1,6 @@
1
+ import type http from 'node:http';
2
+ import type { AssetRoutes } from './assets.js';
3
+ export declare const RENDERER_DIR: string;
4
+ type ServeRoutes = Omit<AssetRoutes, 'leafletDir'>;
5
+ export declare function serveAsset(url: string, res: http.ServerResponse, routes: ServeRoutes): boolean;
6
+ export {};