drone-path-engine 2.0.1 → 2.2.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/README.md +31 -10
- package/dist/renderer/boot.d.ts +2 -1
- package/dist/renderer/boot.js +1 -1
- package/dist/renderer/dom.d.ts +2 -13
- package/dist/renderer/dom.js +2 -17
- package/dist/renderer/scene.d.ts +2 -3
- package/dist/renderer/scene.js +35 -27
- package/dist/renderer/trackpick.d.ts +13 -0
- package/dist/renderer/trackpick.js +72 -0
- package/dist/renderer/trackpicker.d.ts +43 -0
- package/dist/renderer/trackpicker.js +101 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
# drone-path-engine
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Generate flight-path map overlay videos from DJI recordings in your own Node.js
|
|
4
|
+
application. The engine plans outputs, fetches and caches map tiles, and renders
|
|
5
|
+
maps in Chromium before encoding the video with FFmpeg.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Requires Node.js 24 or later. To render video, you also need FFmpeg, FFprobe,
|
|
10
|
+
a Chromium browser such as Chrome or Edge, and internet access for uncached
|
|
11
|
+
map tiles.
|
|
6
12
|
|
|
7
13
|
```sh
|
|
8
14
|
npm install drone-path-engine
|
|
9
15
|
```
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
## Render a map video
|
|
18
|
+
|
|
19
|
+
Render a topographic overlay for a DJI recording with embedded CAM-meta
|
|
20
|
+
telemetry or a matching SRT sidecar:
|
|
12
21
|
|
|
13
22
|
```js
|
|
14
23
|
import { DEFAULT_CONFIG } from 'drone-path-engine/config';
|
|
15
24
|
import { runBatch } from 'drone-path-engine/pipeline';
|
|
25
|
+
|
|
26
|
+
const config = { ...DEFAULT_CONFIG, style: 'topo', outDir: './out' };
|
|
27
|
+
const result = await runBatch(['flight.mp4'], config, console.error, console.log);
|
|
28
|
+
if (result.failed > 0) process.exitCode = 1;
|
|
16
29
|
```
|
|
17
30
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
This writes `out/flight_map.mp4`. The callbacks receive progress messages and
|
|
32
|
+
per-recording results, respectively.
|
|
33
|
+
|
|
34
|
+
## TypeScript
|
|
35
|
+
|
|
36
|
+
Each module ships TypeScript declarations.
|
|
21
37
|
|
|
22
38
|
Install `@types/node` for your Node.js major version. In TypeScript 6, list
|
|
23
39
|
`node` in `compilerOptions.types` to load the Node declarations.
|
|
@@ -31,6 +47,11 @@ Install `@types/node` for your Node.js major version. In TypeScript 6, list
|
|
|
31
47
|
}
|
|
32
48
|
```
|
|
33
49
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
the
|
|
50
|
+
## Learn more
|
|
51
|
+
|
|
52
|
+
Use the [`drone-path` CLI](https://www.npmjs.com/package/drone-path) to render
|
|
53
|
+
without writing code. See
|
|
54
|
+
[Getting started](https://github.com/MrManny/drone-path/blob/main/docs/user/getting-started.md)
|
|
55
|
+
for browser and FFmpeg setup, and the
|
|
56
|
+
[CLI guide](https://github.com/MrManny/drone-path/blob/main/docs/user/cli.md)
|
|
57
|
+
for examples of render options.
|
package/dist/renderer/boot.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LeafletApi, Scene, SceneData } from './scene.js';
|
|
2
|
+
import type { TrackPickHandlers } from './trackpicker.js';
|
|
2
3
|
export declare function bootScene(host: HTMLElement, data: SceneData, L: LeafletApi, opts?: {
|
|
3
|
-
|
|
4
|
+
trackPick?: TrackPickHandlers;
|
|
4
5
|
}): Scene;
|
package/dist/renderer/boot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createScene } from './scene.js';
|
|
2
2
|
export function bootScene(host, data, L, opts) {
|
|
3
|
-
const scene = createScene(host, data, { L,
|
|
3
|
+
const scene = createScene(host, data, { L, trackPick: opts?.trackPick });
|
|
4
4
|
let disposed = false;
|
|
5
5
|
let rafId;
|
|
6
6
|
const baseDispose = scene.dispose.bind(scene);
|
package/dist/renderer/dom.d.ts
CHANGED
|
@@ -8,19 +8,8 @@ export declare const EXPORT_HUD_LABELS: {
|
|
|
8
8
|
readonly speed: "SPD";
|
|
9
9
|
};
|
|
10
10
|
export declare function hudMarkup(hud: HudLayout): string;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
* shape never depends on settings; a disabled chip keeps its column and shows
|
|
14
|
-
* the dimmed "--" placeholder instead of a value. The ids and .num/.unit spans
|
|
15
|
-
* match the export HUD contract, so the scene's value queries work for both.
|
|
16
|
-
*/
|
|
17
|
-
export interface StripLabels {
|
|
18
|
-
speed: string;
|
|
19
|
-
altitude: string;
|
|
20
|
-
}
|
|
21
|
-
export declare function stripReadoutMarkup(hud: HudLayout, labels?: StripLabels): string;
|
|
22
|
-
/** A null hud keeps the chips out of the map frame: the caller mounts them in
|
|
23
|
-
a strip outside the map image instead. */
|
|
11
|
+
/** A null hud keeps the chips out of the map frame: the caller renders its own
|
|
12
|
+
readout outside the map image instead. */
|
|
24
13
|
export declare function mapMarkup(hud: HudLayout | null, attribution: string): string;
|
|
25
14
|
/** Attribution links are on-screen credits, not controls: keyboard skips them. */
|
|
26
15
|
export declare function quietAttributionLinks(attr: HTMLElement): void;
|
package/dist/renderer/dom.js
CHANGED
|
@@ -130,23 +130,8 @@ export function hudMarkup(hud) {
|
|
|
130
130
|
}
|
|
131
131
|
return chips.map((chip) => ` ${chip}`).join('\n');
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
export function stripReadoutMarkup(hud, labels) {
|
|
137
|
-
const column = (id, label, unit, live) => `<div class="map-readout${live ? '' : ' map-readout-off'}" id="chip-${id}">` +
|
|
138
|
-
`<span class="label">${escapeText(label)}</span>` +
|
|
139
|
-
`<span class="value"><span class="num">--</span><span class="unit">${unit}</span></span>` +
|
|
140
|
-
`</div>`;
|
|
141
|
-
return [
|
|
142
|
-
column('speed', labels?.speed ?? 'Speed', 'm/s', hud.speed),
|
|
143
|
-
column('alt', labels?.altitude ?? 'Altitude', 'm', hud.alt),
|
|
144
|
-
]
|
|
145
|
-
.map((col) => ` ${col}`)
|
|
146
|
-
.join('\n');
|
|
147
|
-
}
|
|
148
|
-
/** A null hud keeps the chips out of the map frame: the caller mounts them in
|
|
149
|
-
a strip outside the map image instead. */
|
|
133
|
+
/** A null hud keeps the chips out of the map frame: the caller renders its own
|
|
134
|
+
readout outside the map image instead. */
|
|
150
135
|
export function mapMarkup(hud, attribution) {
|
|
151
136
|
const hudBlock = hud === null ? '' : `<div id="hud">
|
|
152
137
|
${hudMarkup(hud)}
|
package/dist/renderer/scene.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { HudLayout, MapStyle, ViewMode } from '../config.js';
|
|
2
2
|
import type { LatLon } from 'drone-path-core/geo';
|
|
3
|
-
import type { StripLabels } from './dom.js';
|
|
4
3
|
import type * as Leaflet from 'leaflet';
|
|
5
4
|
import type { FrameChannels } from 'drone-path-core/telemetry-math';
|
|
5
|
+
import type { TrackPickHandlers } from './trackpicker.js';
|
|
6
6
|
export type LeafletApi = typeof Leaflet;
|
|
7
7
|
export interface SceneData extends FrameChannels {
|
|
8
8
|
style: MapStyle;
|
|
@@ -18,7 +18,6 @@ export interface SceneData extends FrameChannels {
|
|
|
18
18
|
/** Whether this viewer draws the in-frame HUD pills; a caller that overlays
|
|
19
19
|
its own toggles (the Map appearance preview) sets this to false. */
|
|
20
20
|
hudPills?: boolean;
|
|
21
|
-
stripLabels?: StripLabels;
|
|
22
21
|
trailLat: number[];
|
|
23
22
|
trailLon: number[];
|
|
24
23
|
trailFrame: number[];
|
|
@@ -32,5 +31,5 @@ export interface Scene {
|
|
|
32
31
|
}
|
|
33
32
|
export declare function createScene(host: HTMLElement, firstData: SceneData, deps: {
|
|
34
33
|
L: LeafletApi;
|
|
35
|
-
|
|
34
|
+
trackPick?: TrackPickHandlers;
|
|
36
35
|
}): Scene;
|
package/dist/renderer/scene.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { TILE_SOURCES } from './tilesources.js';
|
|
2
|
-
import { droneMarkerMarkup, el, hudMarkup, mapMarkup, quietAttributionLinks, sceneCss
|
|
2
|
+
import { droneMarkerMarkup, el, hudMarkup, mapMarkup, quietAttributionLinks, sceneCss } from './dom.js';
|
|
3
3
|
import { computeScale, metersPerPixel, scaleBarMeters } from './framemath.js';
|
|
4
4
|
import { themeFor } from './theme.js';
|
|
5
5
|
import { createTrailController } from './trail.js';
|
|
6
|
+
import { TrackPicker } from './trackpicker.js';
|
|
6
7
|
function hudEq(a, b) {
|
|
7
8
|
return (a.heading === b.heading && a.alt === b.alt && a.speed === b.speed);
|
|
8
9
|
}
|
|
@@ -60,28 +61,22 @@ class SceneState {
|
|
|
60
61
|
headingChip = null;
|
|
61
62
|
altChip = null;
|
|
62
63
|
speedChip = null;
|
|
63
|
-
/** Chip container
|
|
64
|
+
/** Chip container inside the map frame for exports. */
|
|
64
65
|
hudRoot;
|
|
65
|
-
/** External strips get the column markup; the export frame keeps its pills. */
|
|
66
|
-
externalHud;
|
|
67
66
|
curIdx = 0;
|
|
68
67
|
disposed = false;
|
|
69
|
-
|
|
68
|
+
picker = null;
|
|
69
|
+
constructor(host, firstData, L, trackPick) {
|
|
70
70
|
this.host = host;
|
|
71
71
|
this.data = firstData;
|
|
72
72
|
this.L = L;
|
|
73
73
|
host.classList.add(this.scopeClass);
|
|
74
74
|
this.styleEl = document.createElement('style');
|
|
75
75
|
document.head.appendChild(this.styleEl);
|
|
76
|
-
|
|
77
|
-
// strip host or gets the in-frame export HUD (unless hudPills is false),
|
|
78
|
-
// never a mix of the two.
|
|
79
|
-
const externalHud = hudHost !== undefined;
|
|
80
|
-
const suppressHud = externalHud || firstData.hudPills === false;
|
|
76
|
+
const suppressHud = firstData.hudPills === false;
|
|
81
77
|
host.innerHTML = mapMarkup(suppressHud ? null : firstData.hud, firstData.attribution);
|
|
82
78
|
this.frameEl = el(host, '#map-frame');
|
|
83
|
-
this.hudRoot =
|
|
84
|
-
this.externalHud = externalHud;
|
|
79
|
+
this.hudRoot = host.querySelector('#hud');
|
|
85
80
|
this.attrEl = el(host, '#attr');
|
|
86
81
|
this.applyChrome();
|
|
87
82
|
this.mapEl = el(host, '#map');
|
|
@@ -110,6 +105,17 @@ class SceneState {
|
|
|
110
105
|
this.layoutMap();
|
|
111
106
|
this.decor = this.buildDecor();
|
|
112
107
|
this.rebuildHud();
|
|
108
|
+
if (trackPick) {
|
|
109
|
+
this.picker = new TrackPicker({
|
|
110
|
+
L,
|
|
111
|
+
map: this.map,
|
|
112
|
+
surface: this.frameEl,
|
|
113
|
+
handlers: trackPick,
|
|
114
|
+
latlngs: () => this.latlngs,
|
|
115
|
+
playhead: () => this.curIdx,
|
|
116
|
+
look: () => this.trackPickLook(),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
113
119
|
this.ready = new Promise((resolve) => {
|
|
114
120
|
const markReady = () => {
|
|
115
121
|
clearTimeout(this.readyTimer);
|
|
@@ -124,6 +130,15 @@ class SceneState {
|
|
|
124
130
|
scale() {
|
|
125
131
|
return computeScale(this.data.width, this.data.height);
|
|
126
132
|
}
|
|
133
|
+
trackPickLook() {
|
|
134
|
+
const s = this.scale();
|
|
135
|
+
return {
|
|
136
|
+
hitRadius: Math.max(10, Math.round(12 * s)),
|
|
137
|
+
markerRadius: Math.round(6 * s),
|
|
138
|
+
markerWeight: Math.max(2, Math.round(3 * s)),
|
|
139
|
+
color: themeFor(this.data.style, this.data.trailColor).core,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
127
142
|
makeTileLayer(tileUrl, style) {
|
|
128
143
|
return this.L.tileLayer(tileUrl, {
|
|
129
144
|
maxZoom: TILE_SOURCES[style].maxZoom,
|
|
@@ -168,6 +183,7 @@ class SceneState {
|
|
|
168
183
|
this.scalelineEl.style.width = Math.round(bestM / mPerPx) + 'px';
|
|
169
184
|
this.scaletextEl.textContent = bestM >= 1000 ? bestM / 1000 + ' km' : bestM + ' m';
|
|
170
185
|
this.layout = { vw, vh, bigW, bigH, c0, bestM, mPerPx };
|
|
186
|
+
this.picker?.invalidate();
|
|
171
187
|
}
|
|
172
188
|
buildGhostLayers(theme, ghostLatlngs, ghostDash) {
|
|
173
189
|
const s = this.scale();
|
|
@@ -278,17 +294,11 @@ class SceneState {
|
|
|
278
294
|
for (const layer of this.decor.layers)
|
|
279
295
|
layer.remove();
|
|
280
296
|
this.decor = this.buildDecor();
|
|
297
|
+
this.picker?.invalidate();
|
|
281
298
|
}
|
|
282
299
|
rebuildHud() {
|
|
283
|
-
//
|
|
284
|
-
|
|
285
|
-
// overlays its own pills draws none of its own (#283).
|
|
286
|
-
if (this.externalHud) {
|
|
287
|
-
if (this.hudRoot) {
|
|
288
|
-
this.hudRoot.innerHTML = stripReadoutMarkup(this.data.hud, this.data.stripLabels);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
else if (this.data.hudPills === false) {
|
|
300
|
+
// A scene whose caller overlays its own pills draws none of its own (#283).
|
|
301
|
+
if (this.data.hudPills === false) {
|
|
292
302
|
this.hudRoot?.remove();
|
|
293
303
|
this.hudRoot = null;
|
|
294
304
|
}
|
|
@@ -352,8 +362,6 @@ class SceneState {
|
|
|
352
362
|
if (!chip)
|
|
353
363
|
return;
|
|
354
364
|
setChipText(chip.querySelector('.num'), value, format);
|
|
355
|
-
if (this.externalHud)
|
|
356
|
-
chip.classList.toggle('map-readout-off', isMissing(value));
|
|
357
365
|
}
|
|
358
366
|
setFrame(i) {
|
|
359
367
|
this.curIdx = i;
|
|
@@ -361,6 +369,7 @@ class SceneState {
|
|
|
361
369
|
this.decor.drone.setLatLng(this.latlngs[i]);
|
|
362
370
|
this.updateTransform(i);
|
|
363
371
|
this.updateHud(i);
|
|
372
|
+
this.picker?.refresh();
|
|
364
373
|
// Canvas painting is deferred to requestAnimationFrame
|
|
365
374
|
return new Promise((resolve) => {
|
|
366
375
|
requestAnimationFrame(() => {
|
|
@@ -402,9 +411,7 @@ class SceneState {
|
|
|
402
411
|
if (lookChanged || trailChanged || trackChanged)
|
|
403
412
|
this.rebuildDecor();
|
|
404
413
|
if (!hudEq(prev.hud, next.hud) ||
|
|
405
|
-
next.hudPills !== prev.hudPills
|
|
406
|
-
next.stripLabels?.speed !== prev.stripLabels?.speed ||
|
|
407
|
-
next.stripLabels?.altitude !== prev.stripLabels?.altitude)
|
|
414
|
+
next.hudPills !== prev.hudPills)
|
|
408
415
|
this.rebuildHud();
|
|
409
416
|
this.layoutMap();
|
|
410
417
|
this.curIdx = Math.max(0, Math.min(this.curIdx, this.latlngs.length - 1));
|
|
@@ -415,11 +422,12 @@ class SceneState {
|
|
|
415
422
|
clearTimeout(this.readyTimer);
|
|
416
423
|
this.readyTimer = undefined;
|
|
417
424
|
this.settleReady();
|
|
425
|
+
this.picker?.dispose();
|
|
418
426
|
this.map.remove();
|
|
419
427
|
this.styleEl.remove();
|
|
420
428
|
this.host.classList.remove(this.scopeClass);
|
|
421
429
|
}
|
|
422
430
|
}
|
|
423
431
|
export function createScene(host, firstData, deps) {
|
|
424
|
-
return new SceneState(host, firstData, deps.L, deps.
|
|
432
|
+
return new SceneState(host, firstData, deps.L, deps.trackPick);
|
|
425
433
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ScreenPoint {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The frame a pointer at `target` picks on a track drawn through `points` (one
|
|
7
|
+
* per frame, joined by straight segments), or null when the track does not come
|
|
8
|
+
* within `radius`. Each pass of the flight near the pointer picks its nearest
|
|
9
|
+
* frame, the earliest on ties. Where the path crosses itself, the passes about as
|
|
10
|
+
* near as the nearest one resolve to the one closest in time to `playhead`, the
|
|
11
|
+
* earlier on ties.
|
|
12
|
+
*/
|
|
13
|
+
export declare function pickTrackFrame(points: readonly ScreenPoint[], target: ScreenPoint, radius: number, playhead: number): number | null;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Distance differences below this are treated as noise: a pass must move this much
|
|
2
|
+
away and back to end, and passes this close to the nearest one count as the same
|
|
3
|
+
hit, so a crossing resolves by time rather than by a sub-pixel difference. */
|
|
4
|
+
const PASS_SLACK_PX = 3;
|
|
5
|
+
/** The nearest spot on the segment from frame `i` to `i + 1`, attributed to the nearer frame. */
|
|
6
|
+
function segmentSample(points, i, target) {
|
|
7
|
+
const a = points[i];
|
|
8
|
+
const b = points[i + 1];
|
|
9
|
+
const vx = b.x - a.x;
|
|
10
|
+
const vy = b.y - a.y;
|
|
11
|
+
const len2 = vx * vx + vy * vy;
|
|
12
|
+
const t = len2 === 0 ? 0 : Math.min(1, Math.max(0, ((target.x - a.x) * vx + (target.y - a.y) * vy) / len2));
|
|
13
|
+
return { frame: t <= 0.5 ? i : i + 1, dist: Math.hypot(a.x + t * vx - target.x, a.y + t * vy - target.y) };
|
|
14
|
+
}
|
|
15
|
+
/** The track as seen from `target`: each frame, then the segment drawn to the next one. */
|
|
16
|
+
function* samples(points, target) {
|
|
17
|
+
for (let i = 0; i < points.length; i++) {
|
|
18
|
+
yield { frame: i, dist: Math.hypot(points[i].x - target.x, points[i].y - target.y) };
|
|
19
|
+
if (i + 1 < points.length)
|
|
20
|
+
yield segmentSample(points, i, target);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Splits the track into passes near `target`: a pass ends when the track leaves the
|
|
24
|
+
radius, or clearly moves away and clearly comes back without leaving it (a tight
|
|
25
|
+
loop). Sub-pixel wobble along a straight trail never splits a pass. */
|
|
26
|
+
function passesWithin(points, target, radius) {
|
|
27
|
+
const passes = [];
|
|
28
|
+
let current = null;
|
|
29
|
+
// The farthest the track has strayed since the current pass's nearest sample.
|
|
30
|
+
let peak = 0;
|
|
31
|
+
for (const { frame, dist } of samples(points, target)) {
|
|
32
|
+
if (dist > radius) {
|
|
33
|
+
current = null;
|
|
34
|
+
}
|
|
35
|
+
else if (current === null || (peak > current.dist + PASS_SLACK_PX && dist < peak - PASS_SLACK_PX)) {
|
|
36
|
+
current = { frame, dist };
|
|
37
|
+
passes.push(current);
|
|
38
|
+
peak = dist;
|
|
39
|
+
}
|
|
40
|
+
else if (dist < current.dist) {
|
|
41
|
+
current.frame = frame;
|
|
42
|
+
current.dist = dist;
|
|
43
|
+
peak = dist;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
peak = Math.max(peak, dist);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return passes;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The frame a pointer at `target` picks on a track drawn through `points` (one
|
|
53
|
+
* per frame, joined by straight segments), or null when the track does not come
|
|
54
|
+
* within `radius`. Each pass of the flight near the pointer picks its nearest
|
|
55
|
+
* frame, the earliest on ties. Where the path crosses itself, the passes about as
|
|
56
|
+
* near as the nearest one resolve to the one closest in time to `playhead`, the
|
|
57
|
+
* earlier on ties.
|
|
58
|
+
*/
|
|
59
|
+
export function pickTrackFrame(points, target, radius, playhead) {
|
|
60
|
+
const passes = passesWithin(points, target, radius);
|
|
61
|
+
if (passes.length === 0)
|
|
62
|
+
return null;
|
|
63
|
+
const nearest = Math.min(...passes.map((pass) => pass.dist));
|
|
64
|
+
let best = null;
|
|
65
|
+
for (const pass of passes) {
|
|
66
|
+
if (pass.dist > nearest + PASS_SLACK_PX)
|
|
67
|
+
continue;
|
|
68
|
+
if (best === null || Math.abs(pass.frame - playhead) < Math.abs(best.frame - playhead))
|
|
69
|
+
best = pass;
|
|
70
|
+
}
|
|
71
|
+
return best === null ? null : best.frame;
|
|
72
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type * as Leaflet from 'leaflet';
|
|
2
|
+
export interface TrackPickHandlers {
|
|
3
|
+
/** The playback time shown beside the hovered point. */
|
|
4
|
+
label(frame: number): string;
|
|
5
|
+
seek(frame: number): void;
|
|
6
|
+
}
|
|
7
|
+
export interface TrackPickLook {
|
|
8
|
+
/** Pointer distance, in CSS pixels, within which the track counts as hit. */
|
|
9
|
+
hitRadius: number;
|
|
10
|
+
markerRadius: number;
|
|
11
|
+
markerWeight: number;
|
|
12
|
+
color: string;
|
|
13
|
+
}
|
|
14
|
+
export interface TrackPickerDeps {
|
|
15
|
+
L: typeof Leaflet;
|
|
16
|
+
map: Leaflet.Map;
|
|
17
|
+
/** The element that receives pointer input over the visible map. */
|
|
18
|
+
surface: HTMLElement;
|
|
19
|
+
handlers: TrackPickHandlers;
|
|
20
|
+
latlngs: () => readonly Leaflet.LatLngTuple[];
|
|
21
|
+
playhead: () => number;
|
|
22
|
+
look: () => TrackPickLook;
|
|
23
|
+
}
|
|
24
|
+
export declare class TrackPicker {
|
|
25
|
+
private readonly deps;
|
|
26
|
+
private points;
|
|
27
|
+
private pointer;
|
|
28
|
+
private press;
|
|
29
|
+
private hovered;
|
|
30
|
+
private marker;
|
|
31
|
+
constructor(deps: TrackPickerDeps);
|
|
32
|
+
/** Drops what depends on the map view or look; call after a re-layout or restyle. */
|
|
33
|
+
invalidate(): void;
|
|
34
|
+
/** Re-picks under a resting pointer once the map has moved beneath it. */
|
|
35
|
+
refresh(): void;
|
|
36
|
+
dispose(): void;
|
|
37
|
+
private readonly onMove;
|
|
38
|
+
private readonly onLeave;
|
|
39
|
+
private readonly onDown;
|
|
40
|
+
private readonly onClick;
|
|
41
|
+
private pickAt;
|
|
42
|
+
private show;
|
|
43
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { pickTrackFrame } from './trackpick.js';
|
|
2
|
+
/** A press that travels farther than this is a drag, not a click-to-seek. */
|
|
3
|
+
const CLICK_SLOP_PX = 4;
|
|
4
|
+
export class TrackPicker {
|
|
5
|
+
deps;
|
|
6
|
+
points = null;
|
|
7
|
+
pointer = null;
|
|
8
|
+
press = null;
|
|
9
|
+
hovered = null;
|
|
10
|
+
marker = null;
|
|
11
|
+
constructor(deps) {
|
|
12
|
+
this.deps = deps;
|
|
13
|
+
const { surface } = deps;
|
|
14
|
+
surface.addEventListener('pointermove', this.onMove);
|
|
15
|
+
surface.addEventListener('pointerleave', this.onLeave);
|
|
16
|
+
surface.addEventListener('pointerdown', this.onDown);
|
|
17
|
+
surface.addEventListener('click', this.onClick);
|
|
18
|
+
}
|
|
19
|
+
/** Drops what depends on the map view or look; call after a re-layout or restyle. */
|
|
20
|
+
invalidate() {
|
|
21
|
+
this.points = null;
|
|
22
|
+
this.marker?.remove();
|
|
23
|
+
this.marker = null;
|
|
24
|
+
this.hovered = null;
|
|
25
|
+
}
|
|
26
|
+
/** Re-picks under a resting pointer once the map has moved beneath it. */
|
|
27
|
+
refresh() {
|
|
28
|
+
if (this.pointer)
|
|
29
|
+
this.show(this.pickAt(this.pointer));
|
|
30
|
+
}
|
|
31
|
+
dispose() {
|
|
32
|
+
const { surface } = this.deps;
|
|
33
|
+
surface.removeEventListener('pointermove', this.onMove);
|
|
34
|
+
surface.removeEventListener('pointerleave', this.onLeave);
|
|
35
|
+
surface.removeEventListener('pointerdown', this.onDown);
|
|
36
|
+
surface.removeEventListener('click', this.onClick);
|
|
37
|
+
surface.style.cursor = '';
|
|
38
|
+
this.invalidate();
|
|
39
|
+
}
|
|
40
|
+
onMove = (event) => {
|
|
41
|
+
this.pointer = event;
|
|
42
|
+
this.show(this.pickAt(event));
|
|
43
|
+
};
|
|
44
|
+
onLeave = () => {
|
|
45
|
+
this.pointer = null;
|
|
46
|
+
this.press = null;
|
|
47
|
+
this.show(null);
|
|
48
|
+
};
|
|
49
|
+
onDown = (event) => {
|
|
50
|
+
this.press = event.button === 0 ? { x: event.clientX, y: event.clientY } : null;
|
|
51
|
+
};
|
|
52
|
+
onClick = (event) => {
|
|
53
|
+
const press = this.press;
|
|
54
|
+
this.press = null;
|
|
55
|
+
if (!press || Math.hypot(event.clientX - press.x, event.clientY - press.y) > CLICK_SLOP_PX)
|
|
56
|
+
return;
|
|
57
|
+
const frame = this.pickAt(event);
|
|
58
|
+
if (frame !== null)
|
|
59
|
+
this.deps.handlers.seek(frame);
|
|
60
|
+
};
|
|
61
|
+
pickAt(event) {
|
|
62
|
+
const { map, latlngs, playhead, look } = this.deps;
|
|
63
|
+
this.points ??= latlngs().map((ll) => map.latLngToContainerPoint(ll));
|
|
64
|
+
return pickTrackFrame(this.points, map.mouseEventToContainerPoint(event), look().hitRadius, playhead());
|
|
65
|
+
}
|
|
66
|
+
show(frame) {
|
|
67
|
+
const { surface } = this.deps;
|
|
68
|
+
surface.style.cursor = frame === null ? '' : 'pointer';
|
|
69
|
+
if (frame === this.hovered)
|
|
70
|
+
return;
|
|
71
|
+
this.hovered = frame;
|
|
72
|
+
if (frame === null) {
|
|
73
|
+
this.marker?.remove();
|
|
74
|
+
this.marker = null;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const at = this.deps.latlngs()[frame];
|
|
78
|
+
const text = this.deps.handlers.label(frame);
|
|
79
|
+
if (this.marker) {
|
|
80
|
+
this.marker.setLatLng(at).setTooltipContent(text);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const { L, map, look } = this.deps;
|
|
84
|
+
const { markerRadius, markerWeight, color } = look();
|
|
85
|
+
this.marker = L.circleMarker(at, {
|
|
86
|
+
radius: markerRadius,
|
|
87
|
+
color,
|
|
88
|
+
weight: markerWeight,
|
|
89
|
+
fillColor: '#ffffff',
|
|
90
|
+
fillOpacity: 1,
|
|
91
|
+
interactive: false,
|
|
92
|
+
})
|
|
93
|
+
.bindTooltip(text, {
|
|
94
|
+
permanent: true,
|
|
95
|
+
direction: 'top',
|
|
96
|
+
offset: [0, -(markerRadius + markerWeight)],
|
|
97
|
+
className: 'track-pick-time',
|
|
98
|
+
})
|
|
99
|
+
.addTo(map);
|
|
100
|
+
}
|
|
101
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drone-path-engine",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Plan and render flight-path map overlays from drone telemetry.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@types/leaflet": "^1.9.23",
|
|
44
|
-
"drone-path-core": "^2.0
|
|
44
|
+
"drone-path-core": "^2.2.0",
|
|
45
45
|
"leaflet": "^1.9.4",
|
|
46
46
|
"p-queue": "^10.0.0",
|
|
47
|
-
"playwright-core": "^1.65.
|
|
47
|
+
"playwright-core": "^1.65.2",
|
|
48
48
|
"zod": "^4.6.7"
|
|
49
49
|
}
|
|
50
50
|
}
|