|
1 | | -// Marker icon rendering. Prefers tar1090's per-type silhouette when the |
2 | | -// bundle is loaded and the aircraft's ICAO type code has a match; |
3 | | -// otherwise falls back to a generic triangular arrow. |
| 1 | +// Marker icon rendering. Prefers tar1090's per-type silhouette via the |
| 2 | +// four-tier fallback in `resolveSilhouette` (designator → description → |
| 3 | +// category); falls back to a generic triangular arrow when none match |
| 4 | +// or the bundles haven't loaded yet. |
4 | 5 | // |
5 | | -// tar1090_shapes.js is loaded asynchronously (it's a big static file |
6 | | -// and failing to fetch it shouldn't stop the app from running). Until |
7 | | -// it resolves we render the generic arrow for everyone; once it does, |
8 | | -// subsequent planeIcon() calls light up. |
| 6 | +// tar1090_shapes.js and icao_aircraft_types.js are loaded asynchronously |
| 7 | +// (they're big static files and failing to fetch them shouldn't stop the |
| 8 | +// app from running). Until they resolve we render the generic arrow for |
| 9 | +// everyone; once they do, subsequent planeIcon() calls light up. |
| 10 | + |
| 11 | +import { resolveSilhouette } from './silhouette.js'; |
9 | 12 |
|
10 | 13 | let tar1090Shapes = null; |
11 | 14 | let tar1090TypeIcons = null; |
| 15 | +let tar1090TypeDescIcons = null; |
| 16 | +let tar1090CategoryIcons = null; |
| 17 | +let typeDesignatorMeta = null; |
12 | 18 |
|
13 | 19 | import('./tar1090_shapes.js').then(mod => { |
14 | 20 | tar1090Shapes = mod.shapes; |
15 | 21 | tar1090TypeIcons = mod.TypeDesignatorIcons; |
| 22 | + tar1090TypeDescIcons = mod.TypeDescriptionIcons; |
| 23 | + tar1090CategoryIcons = mod.CategoryIcons; |
16 | 24 | }).catch(e => { |
17 | 25 | console.warn('tar1090 shapes unavailable — using generic arrow', e); |
18 | 26 | }); |
19 | 27 |
|
20 | | -function tar1090ShapeFor(typeIcao) { |
21 | | - if (!tar1090Shapes || !tar1090TypeIcons || !typeIcao) return null; |
22 | | - const entry = tar1090TypeIcons[typeIcao.toUpperCase()]; |
| 28 | +import('./icao_aircraft_types.js').then(mod => { |
| 29 | + typeDesignatorMeta = mod.TypeDesignatorMeta; |
| 30 | +}).catch(e => { |
| 31 | + console.warn('ICAO type metadata unavailable — silhouette fallback narrowed', e); |
| 32 | +}); |
| 33 | + |
| 34 | +function tar1090ShapeFor(typeIcao, category, categorySet) { |
| 35 | + if (!tar1090Shapes) return null; |
| 36 | + const entry = resolveSilhouette({ |
| 37 | + typeIcao, category, categorySet, |
| 38 | + typeDesignatorIcons: tar1090TypeIcons, |
| 39 | + typeDescriptionIcons: tar1090TypeDescIcons, |
| 40 | + categoryIcons: tar1090CategoryIcons, |
| 41 | + typeDesignatorMeta, |
| 42 | + }); |
23 | 43 | if (!entry) return null; |
24 | 44 | const [shapeName, scaleFactor] = entry; |
25 | 45 | const shape = tar1090Shapes[shapeName]; |
@@ -86,8 +106,8 @@ function tar1090Icon(track, color, selected, emergency, relayed, shape, scaleFac |
86 | 106 | const GENERIC_ARROW_PATH = 'M0,-10 L7,8 L0,4 L-7,8 Z'; |
87 | 107 | const GENERIC_ARROW_SIZE = 26; |
88 | 108 |
|
89 | | -export function planeIcon(track, color, selected, emergency, relayed, typeIcao) { |
90 | | - const tar = tar1090ShapeFor(typeIcao); |
| 109 | +export function planeIcon(track, color, selected, emergency, relayed, typeIcao, category, categorySet) { |
| 110 | + const tar = tar1090ShapeFor(typeIcao, category, categorySet); |
91 | 111 | if (tar) return tar1090Icon(track, color, selected, emergency, relayed, tar.shape, tar.scaleFactor); |
92 | 112 |
|
93 | 113 | const rot = track == null ? 0 : track; |
|
0 commit comments