From c6bdd38b61f410f8b1ee82e53882506eac1d8f62 Mon Sep 17 00:00:00 2001 From: Manjunath Paparaju Date: Mon, 16 Nov 2026 15:13:28 -0800 Subject: [PATCH 1/5] Show a flight's photo, route, model and cockpit view in its Context card The card's hero tile now previews what was picked. A flight shows its photo when Contacts has one, its route on a small globe from origin to destination with the plane on it, its 3D model turning with callouts of what can be worked out about the flight (phase, flight level, Mach, squawk, signal age), and the view ahead from its cockpit with speed and altitude tapes. The model and the cockpit view take turns, the route hands over to the cockpit view after twenty seconds, and a switch picks one and holds it. Under reduced motion nothing swaps by itself. A satellite shows the ground beneath it and graphs its altitude and speed. Each preview draws in a small scene of its own and frees its graphics context as it closes, so flicking through cards never pushes out the globe's. Co-authored-by: Sameh Khamis --- src/ui/previewWidget.js | 30 + src/ui/styles/entity-card.css | 1082 +++++++++++++++++++ src/ui/views/ContextView.vue | 2 +- src/ui/views/panels/AircraftModelHero.vue | 277 +++++ src/ui/views/panels/AltitudeGraph.vue | 25 +- src/ui/views/panels/EntityCard.vue | 145 ++- src/ui/views/panels/FlightCockpitView.vue | 123 +++ src/ui/views/panels/PreviewHud.vue | 93 ++ src/ui/views/panels/RouteGlobe.vue | 326 ++++++ src/ui/views/panels/SatelliteGroundView.vue | 107 ++ 10 files changed, 2196 insertions(+), 14 deletions(-) create mode 100644 src/ui/previewWidget.js create mode 100644 src/ui/views/panels/AircraftModelHero.vue create mode 100644 src/ui/views/panels/FlightCockpitView.vue create mode 100644 src/ui/views/panels/PreviewHud.vue create mode 100644 src/ui/views/panels/RouteGlobe.vue create mode 100644 src/ui/views/panels/SatelliteGroundView.vue diff --git a/src/ui/previewWidget.js b/src/ui/previewWidget.js new file mode 100644 index 000000000..58d57fe16 --- /dev/null +++ b/src/ui/previewWidget.js @@ -0,0 +1,30 @@ +// The card previews (the turning model, the route globe) each draw in a +// small Cesium scene of their own, so each holds a WebGL context. A browser +// keeps only a handful of those open, and when there are too many it drops +// the oldest, which is the main globe's. A destroyed widget's context is +// otherwise freed only when garbage is collected, so flicking through cards +// can push the globe's context out. Losing a preview's context on purpose as +// it closes frees it at once. + +/** + * Destroy a preview's Cesium widget and free its WebGL context. + * @param {object|null} widget a Cesium CesiumWidget + */ +export function destroyPreviewWidget(widget) { + if (!widget || widget.isDestroyed?.()) return; + let gl = null; + try { + gl = + widget.scene?.context?._gl ?? + widget.canvas?.getContext?.('webgl2') ?? + null; + } catch { + gl = null; + } + widget.destroy(); + try { + gl?.getExtension?.('WEBGL_lose_context')?.loseContext(); + } catch { + // Nothing more can be done; the context goes when it is collected. + } +} diff --git a/src/ui/styles/entity-card.css b/src/ui/styles/entity-card.css index 2f8f09840..3603932a2 100644 --- a/src/ui/styles/entity-card.css +++ b/src/ui/styles/entity-card.css @@ -1768,3 +1768,1085 @@ .view-context__live { margin: 0.6rem 0 0.7rem; } + +/* ── Card previews: the photo, route globe, turning model, cockpit view and + satellite ground view in the hero tile ─────────────────────────────── */ + +.aircraft-hero { + position: relative; + height: 150px; + margin: 0.55rem -0.25rem 0.2rem; + overflow: hidden; + background: + radial-gradient( + ellipse 60% 55% at 50% 58%, + rgba(54, 220, 255, 0.14), + transparent 70% + ), + linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0)); + border-radius: 8px; +} + +.aircraft-hero__scene, +.aircraft-hero__scene .cesium-widget, +.aircraft-hero__scene canvas { + width: 100% !important; + height: 100% !important; +} + +.aircraft-hero__scene canvas { + display: block; +} +.aircraft-hero__callout { + position: absolute; + top: 8px; + left: 10px; + z-index: 1; + display: grid; + gap: 1px; + max-width: 62%; + pointer-events: none; +} + +.aircraft-hero__label, +.aircraft-hero__value { + opacity: 0; + animation: aircraft-hero-text 700ms ease-out 200ms forwards; +} + +.aircraft-hero__value { + animation-delay: 1650ms; +} + +.aircraft-hero__label { + color: rgba(54, 220, 255, 0.75); + font-family: var(--font-mono); + font-size: 0.5rem; + letter-spacing: 0.1rem; + text-transform: uppercase; +} + +.aircraft-hero__value { + overflow: hidden; + color: #e8fbff; + font-family: var(--font-mono); + font-size: 0.74rem; + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; + text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); +} + +.aircraft-hero-callout-leave-active { + transition: + opacity 600ms ease-in, + filter 600ms ease-in; +} + +.aircraft-hero-callout-leave-to { + opacity: 0; + filter: blur(2px); +} + +@keyframes aircraft-hero-draw { + to { + stroke-dashoffset: 0; + } +} + +@keyframes aircraft-hero-dot { + from { + opacity: 0; + transform: scale(0); + } + to { + opacity: 1; + transform: scale(1); + } +} + +@keyframes aircraft-hero-text { + from { + opacity: 0; + transform: translateX(-4px); + } + to { + opacity: 1; + transform: none; + } +} + +@media (prefers-reduced-motion: reduce) { + .aircraft-hero__label, + .aircraft-hero__value { + animation: none; + opacity: 1; + stroke-dashoffset: 0; + } + .aircraft-hero-callout-leave-active { + transition: none; + } +} +.aircraft-hero__scan { + position: absolute; + right: 10px; + bottom: 8px; + z-index: 1; + margin: 0; + pointer-events: none; +} + +.aircraft-hero__scan { + color: #36dcff; + font-family: var(--font-mono); + font-size: 0.52rem; + letter-spacing: 0.14rem; + text-transform: uppercase; + animation: aircraft-hero-blink 1.1s steps(1, end) infinite; +} + +@keyframes aircraft-hero-blink { + 50% { + opacity: 0.35; + } +} + +.aircraft-hero-legend-enter-active, +.aircraft-hero-legend-leave-active { + transition: opacity 500ms ease; +} + +.aircraft-hero-legend-enter-from, +.aircraft-hero-legend-leave-to { + opacity: 0; +} +#entity-card .aircraft-hero { + height: 168px; + margin: 0.55rem 0 0.6rem; + border-top: 1px solid rgba(255, 255, 255, 0.05); + border-bottom: 1px solid rgba(255, 255, 255, 0.05); + border-radius: 0; +} +.aircraft-hero__label { + display: flex; + align-items: baseline; + gap: 0.45rem; +} + +.aircraft-hero__label em { + color: rgba(199, 214, 222, 0.4); + font-style: normal; + letter-spacing: 0.04rem; +} + +.aircraft-hero__timer { + display: block; + width: 100%; + height: 1px; + margin-top: 4px; + background: + linear-gradient(90deg, rgba(54, 220, 255, 0.7), rgba(54, 220, 255, 0.7)) + left / 0 100% no-repeat, + rgba(255, 255, 255, 0.08); + opacity: 0; + animation: + aircraft-hero-text 300ms ease-out 2000ms forwards, + aircraft-hero-timer 2900ms linear 2300ms forwards; +} + +.aircraft-hero__label, +.aircraft-hero__value { + animation-name: aircraft-hero-slide; +} +.aircraft-hero-callout-leave-active .aircraft-hero__label, +.aircraft-hero-callout-leave-active .aircraft-hero__value, +.aircraft-hero-callout-leave-active .aircraft-hero__timer { + opacity: 1; + animation: aircraft-hero-fade-out 350ms ease-in forwards; +} + +.aircraft-hero-callout-leave-active .aircraft-hero__timer { + background-size: + 100% 100%, + auto; +} + +.aircraft-hero-callout-leave-active, +.aircraft-hero-callout-leave-to { + transition: none; + opacity: 1; + filter: none; +} + +@keyframes aircraft-hero-slide { + from { + opacity: 0; + transform: translateX(-6px); + } + to { + opacity: 1; + transform: none; + } +} + +@keyframes aircraft-hero-timer { + to { + background-size: + 100% 100%, + auto; + } +} + +@keyframes aircraft-hero-breathe { + 50% { + opacity: 0.45; + } +} + +@keyframes aircraft-hero-fade-out { + to { + opacity: 0; + transform: translateX(-4px); + } +} + +@keyframes aircraft-hero-retract { + from { + stroke-dashoffset: 0; + } + to { + stroke-dashoffset: 1; + } +} + +@keyframes aircraft-hero-dot-out { + to { + opacity: 0; + transform: scale(0); + } +} + +@media (prefers-reduced-motion: reduce) { + .aircraft-hero__timer, + .aircraft-hero-callout-leave-active .aircraft-hero__label, + .aircraft-hero-callout-leave-active .aircraft-hero__value { + animation: none; + } + .aircraft-hero__timer { + opacity: 1; + } +} +.route-globe { + position: relative; + height: 168px; + margin: 0.35rem 0 0.6rem; + overflow: hidden; + background: radial-gradient( + ellipse 55% 60% at 50% 55%, + rgba(54, 220, 255, 0.1), + transparent 70% + ); + border-top: 1px solid rgba(255, 255, 255, 0.05); + border-bottom: 1px solid rgba(255, 255, 255, 0.05); +} + +.route-globe__scene, +.route-globe__scene .cesium-widget, +.route-globe__scene canvas { + width: 100% !important; + height: 100% !important; +} + +.route-globe__codes { + position: absolute; + top: 8px; + left: 10px; + display: flex; + gap: 0.4rem; + align-items: baseline; + color: rgba(199, 214, 222, 0.6); + font-family: var(--font-mono); + font-size: 0.62rem; + pointer-events: none; +} + +.route-globe__codes strong { + color: #e8fbff; + font-size: 0.8rem; +} + +.entity-card__preview-switch { + display: inline-flex; + gap: 2px; + margin-top: 0.55rem; + padding: 2px; + background: rgba(255, 255, 255, 0.04); + border: 1px solid rgba(255, 255, 255, 0.07); + border-radius: 7px; +} + +.entity-card__preview-switch button { + padding: 0.22rem 0.6rem; + color: rgba(199, 214, 222, 0.65); + font-size: 0.6rem; + letter-spacing: 0.06rem; + text-transform: uppercase; + background: none; + border: 0; + border-radius: 5px; + cursor: pointer; +} + +.entity-card__preview-switch button.active { + color: #36dcff; + background: rgba(54, 220, 255, 0.12); +} +.route-globe__codes { + align-items: flex-start; + gap: 0.5rem; + padding: 0.3rem 0.5rem 0.35rem; + background: rgba(6, 12, 16, 0.62); + border: 1px solid rgba(255, 255, 255, 0.06); + border-radius: 6px; + backdrop-filter: blur(6px); + -webkit-backdrop-filter: blur(6px); +} + +.route-globe__end { + display: grid; + gap: 1px; +} + +.route-globe__end small { + max-width: 7.5rem; + overflow: hidden; + color: rgba(199, 214, 222, 0.7); + font-family: var(--font-sans, inherit); + font-size: 0.56rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.route-globe__arrow { + padding-top: 0.05rem; + color: rgba(54, 220, 255, 0.8); +} +.route-globe__compass { + position: absolute; + top: 8px; + right: 8px; + display: grid; + justify-items: center; + gap: 2px; + pointer-events: auto; +} + +.route-globe__compass svg { + width: 46px; + height: 46px; + overflow: visible; + filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6)); +} + +.route-globe__compass-ring { + fill: rgba(6, 12, 16, 0.6); + stroke: rgba(199, 214, 222, 0.35); + stroke-width: 1; +} + +.route-globe__compass-ticks line { + stroke: rgba(199, 214, 222, 0.55); + stroke-width: 1; +} + +.route-globe__compass-n { + fill: #ff6b5e; + font: 700 7px var(--font-mono); + text-anchor: middle; +} + +.route-globe__compass-needle path { + fill: #36dcff; + filter: drop-shadow(0 0 2px rgba(54, 220, 255, 0.8)); +} + +.route-globe__compass-needle { + transition: transform 600ms ease; +} + +.route-globe__compass-hub { + fill: #e8fbff; +} + +.route-globe__compass span { + padding: 0 0.3rem; + color: rgba(225, 236, 242, 0.85); + font-family: var(--font-mono); + font-size: 0.52rem; + background: rgba(6, 12, 16, 0.6); + border-radius: 3px; +} + +.entity-hero:is([data-hero='flight'], [data-hero='satellite']) { + height: 168px; + background: radial-gradient( + ellipse 55% 60% at 50% 55%, + rgba(54, 220, 255, 0.1), + rgba(255, 255, 255, 0.02) 70% + ); + border: 1px solid rgba(255, 255, 255, 0.07); +} +.entity-hero .entity-hero__layer { + position: absolute; + inset: 0; + height: auto; + margin: 0; + border: 0; + border-radius: 0; + visibility: hidden; +} + +.entity-hero .entity-hero__layer.is-shown { + visibility: visible; +} + +.entity-hero__photo img { + display: block; + width: 100%; + height: 100%; + object-fit: cover; +} + +.entity-hero__photo small { + position: absolute; + inset-block-start: 6px; + inset-inline-end: 6px; + max-width: calc(100% - 12px); + padding: 2px 5px; + border-radius: 4px; + background: rgba(10, 14, 20, 0.86); + color: #fff; + font-size: 0.6875rem; + line-height: 1.2; + overflow-wrap: anywhere; +} + +.entity-hero__photo:focus-visible { + outline: 2px solid currentColor; + outline-offset: -2px; +} + +.entity-hero .entity-card__preview-switch { + position: absolute; + z-index: 2; + bottom: 6px; + left: 6px; + margin: 0; + background: rgba(10, 14, 20, 0.78); + border-color: rgba(255, 255, 255, 0.12); + backdrop-filter: blur(8px); + -webkit-backdrop-filter: blur(8px); +} +.satellite-ground { + overflow: hidden; + background: #05080b; +} + +.satellite-ground__map { + position: absolute; + top: 50%; + left: 50%; + width: 0; + height: 0; + filter: grayscale(1) brightness(0.78) contrast(1.2); + transform-origin: 0 0; +} + +.satellite-ground__map.is-drifting { + animation: satellite-ground-drift 9s ease-out both; +} + +@keyframes satellite-ground-drift { + from { + transform: scale(1.18); + } + to { + transform: scale(1); + } +} + +.satellite-ground__tile { + position: absolute; + top: 0; + left: 0; + width: 256px; + height: 256px; + max-width: none; + user-select: none; +} + +.satellite-ground__rings { + position: absolute; + top: 50%; + left: 50%; + width: 150px; + height: 150px; + overflow: visible; + transform: translate(-50%, -50%); + pointer-events: none; +} + +.satellite-ground__ring { + fill: none; + stroke: rgba(150, 236, 220, 0.85); + vector-effect: non-scaling-stroke; +} + +.satellite-ground__ring--inner { + fill: rgba(150, 236, 220, 0.06); + stroke-width: 1.5; + animation: satellite-ground-pulse 2.4s ease-in-out infinite; +} + +.satellite-ground__ring--middle, +.satellite-ground__ring--outer { + stroke: rgba(150, 236, 220, 0.5); + stroke-dasharray: 1 4; + stroke-linecap: round; + stroke-width: 1.5; + transform-origin: 0 0; + animation: satellite-ground-turn 40s linear infinite; +} + +.satellite-ground__ring--outer { + stroke: rgba(150, 236, 220, 0.3); + animation-direction: reverse; +} + +@keyframes satellite-ground-pulse { + 50% { + stroke: rgba(150, 236, 220, 0.5); + } +} + +@keyframes satellite-ground-turn { + to { + transform: rotate(360deg); + } +} + +.satellite-ground__label { + position: absolute; + top: 8px; + left: 10px; + display: grid; + gap: 1px; + color: rgba(54, 220, 255, 0.75); + font-family: var(--font-mono); + font-size: 0.5rem; + letter-spacing: 0.1rem; + text-transform: uppercase; +} + +.satellite-ground__label strong { + color: #e8fbff; + font-size: 0.74rem; + font-weight: 600; + letter-spacing: 0.04rem; + text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); +} + +.satellite-ground__credit { + position: absolute; + right: 8px; + bottom: 5px; + color: rgba(225, 236, 242, 0.5); + font-size: 0.48rem; +} + +@media (prefers-reduced-motion: reduce) { + .satellite-ground__map.is-drifting, + .satellite-ground__ring { + animation: none; + } +} +.preview-hud { + position: absolute; + inset: 0; + z-index: 1; + pointer-events: none; + --hud-line: rgba(200, 236, 248, 0.55); + --hud-dim: rgba(200, 236, 248, 0.22); +} + +.preview-hud__corner { + position: absolute; + width: 10px; + height: 10px; + border: 0 solid var(--hud-line); + animation: preview-hud-breathe 3.2s ease-in-out infinite; +} + +.preview-hud__corner--tl { + top: 5px; + left: 5px; + border-top-width: 1px; + border-left-width: 1px; +} +.preview-hud__corner--tr { + top: 5px; + right: 5px; + border-top-width: 1px; + border-right-width: 1px; +} +.preview-hud__corner--bl { + bottom: 5px; + left: 5px; + border-bottom-width: 1px; + border-left-width: 1px; +} +.preview-hud__corner--br { + right: 5px; + bottom: 5px; + border-right-width: 1px; + border-bottom-width: 1px; + animation-delay: 1.6s; +} +.preview-hud__ruler { + position: absolute; + top: 34%; + right: 9px; + width: 5px; + height: 40%; + background: repeating-linear-gradient( + to bottom, + var(--hud-dim) 0 1px, + transparent 1px 6px + ); +} + +.preview-hud__ruler i { + position: absolute; + right: -3px; + width: 8px; + height: 1px; + background: #e8fbff; + box-shadow: 0 0 4px rgba(200, 236, 248, 0.8); + animation: preview-hud-ride 5.5s ease-in-out infinite alternate; +} +.preview-hud__scale { + position: absolute; + bottom: 9px; + left: 12px; + width: 38%; + height: 4px; + background: + repeating-linear-gradient( + to right, + var(--hud-dim) 0 1px, + transparent 1px 5px + ), + repeating-linear-gradient( + to right, + var(--hud-line) 0 1px, + transparent 1px 25px + ); + background-size: + 100% 3px, + 100% 4px; + background-repeat: repeat-x; + background-position: + 0 bottom, + 0 bottom; + mask-image: linear-gradient( + to right, + transparent, + #000 20%, + #000 80%, + transparent + ); + animation: preview-hud-crawl 6s linear infinite; +} +.preview-hud__meter { + position: absolute; + top: 9px; + right: 12px; + display: flex; + align-items: flex-end; + gap: 2px; + height: 9px; +} + +.preview-hud__meter i { + width: 2px; + height: 100%; + background: var(--hud-line); + transform-origin: bottom; + animation: preview-hud-level 1.4s ease-in-out infinite; +} + +.preview-hud__meter i:nth-child(2) { + animation-delay: 0.2s; +} +.preview-hud__meter i:nth-child(3) { + animation-delay: 0.45s; +} +.preview-hud__meter i:nth-child(4) { + animation-delay: 0.7s; +} + +.preview-hud__meter b { + width: 4px; + height: 4px; + margin: 0 0 3px 4px; + border-radius: 50%; + background: #ff5a5a; + animation: preview-hud-blink 1.2s steps(1, end) infinite; +} +.preview-hud__ring { + position: absolute; + top: 50%; + left: 50%; + width: 132px; + height: 132px; + overflow: visible; + transform: translate(-50%, -50%); +} + +.preview-hud__dash { + fill: none; + stroke: var(--hud-dim); + stroke-dasharray: 2 6; + stroke-width: 1; + vector-effect: non-scaling-stroke; + transform-origin: 0 0; + animation: preview-hud-turn 30s linear infinite; +} + +.preview-hud__ticks { + stroke: var(--hud-line); + stroke-width: 1; + vector-effect: non-scaling-stroke; +} + +.preview-hud--ground .preview-hud__ring { + display: none; +} +.preview-hud__sweep { + position: absolute; + right: 0; + left: 0; + height: 22px; + background: linear-gradient( + to bottom, + transparent, + rgba(150, 236, 220, 0.08) 80%, + rgba(150, 236, 220, 0.5) 100% + ); + animation: preview-hud-sweep 4.5s linear infinite; +} + +@keyframes preview-hud-breathe { + 50% { + opacity: 0.45; + } +} +@keyframes preview-hud-ride { + from { + top: 8%; + } + to { + top: 88%; + } +} +@keyframes preview-hud-crawl { + to { + background-position: + -25px bottom, + -25px bottom; + } +} +@keyframes preview-hud-level { + 0%, + 100% { + transform: scaleY(0.35); + } + 50% { + transform: scaleY(1); + } +} +@keyframes preview-hud-blink { + 50% { + opacity: 0.15; + } +} +@keyframes preview-hud-turn { + to { + transform: rotate(360deg); + } +} +@keyframes preview-hud-sweep { + from { + top: -22px; + } + to { + top: 100%; + } +} + +@media (prefers-reduced-motion: reduce) { + .preview-hud *, + .preview-hud__dash { + animation: none !important; + } + + .preview-hud__sweep { + display: none; + } +} +.preview-hud__grid { + position: absolute; + border: 1px solid rgba(200, 236, 248, 0.14); + background: + repeating-linear-gradient( + to right, + rgba(200, 236, 248, 0.14) 0 1px, + transparent 1px 22px + ), + repeating-linear-gradient( + to bottom, + rgba(200, 236, 248, 0.14) 0 1px, + transparent 1px 22px + ); +} + +.preview-hud__cell { + position: absolute; + top: 0; + left: 0; + width: 23px; + height: 23px; + border: 1px solid rgba(150, 236, 220, 0.85); + background: rgba(150, 236, 220, 0.16); + box-shadow: 0 0 6px rgba(150, 236, 220, 0.35); + transition: opacity 160ms linear; +} +.preview-hud--ground { + opacity: 0.4; +} + +.preview-hud--ground .preview-hud__grid { + opacity: 0.6; +} + +.preview-hud--ground .preview-hud__cell { + border-color: rgba(150, 236, 220, 0.5); + background: rgba(150, 236, 220, 0.08); + box-shadow: none; +} + +.satellite-ground__rings { + opacity: 0.45; +} +.flight-cockpit { + overflow: hidden; + background: #05080b; +} + +.flight-cockpit__scene, +.flight-cockpit__scene .cesium-widget, +.flight-cockpit__scene canvas { + position: absolute; + inset: 0; + width: 100%; + height: 100%; +} +.flight-cockpit__horizon { + position: absolute; + top: 50%; + left: 50%; + width: 46px; + height: 1px; + transform: translate(-50%, -50%); + background: linear-gradient( + to right, + rgba(232, 251, 255, 0.7) 0 16px, + transparent 16px 30px, + rgba(232, 251, 255, 0.7) 30px + ); +} + +.flight-cockpit__horizon i { + position: absolute; + top: 50%; + left: 50%; + width: 10px; + height: 10px; + border: 1px solid rgba(232, 251, 255, 0.75); + border-radius: 50%; + transform: translate(-50%, -50%); +} + +.flight-cockpit__label { + position: absolute; + top: 8px; + left: 10px; + z-index: 2; + display: grid; + gap: 1px; + color: rgba(54, 220, 255, 0.85); + font-family: var(--font-mono); + font-size: 0.5rem; + letter-spacing: 0.1rem; + text-transform: uppercase; + text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); +} + +.flight-cockpit__label strong { + color: #e8fbff; + font-size: 0.74rem; + font-weight: 600; + letter-spacing: 0.04rem; +} + +.flight-cockpit__credit { + position: absolute; + right: 8px; + bottom: 5px; + z-index: 2; + color: rgba(225, 236, 242, 0.6); + font-size: 0.48rem; + text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); +} +.preview-hud--cockpit { + opacity: 0.45; +} + +.preview-hud--cockpit .preview-hud__ring { + display: none; +} +.flight-cockpit__tape { + position: absolute; + top: 50%; + z-index: 2; + display: grid; + justify-items: center; + width: 44px; + height: 92px; + transform: translateY(-50%); + pointer-events: none; +} + +.flight-cockpit__tape--speed { + left: 12px; +} + +.flight-cockpit__tape--alt { + right: 12px; + width: 52px; +} + +.flight-cockpit__ticks { + position: absolute; + inset: 0; + background-image: repeating-linear-gradient( + to bottom, + rgba(232, 251, 255, 0.55) 0 1px, + transparent 1px 8px + ); + background-size: 9px 100%; + background-repeat: repeat-y; + mask-image: linear-gradient( + to bottom, + transparent, + #000 25%, + #000 75%, + transparent + ); + transition: background-position-y 1.2s linear; + animation: flight-cockpit-jitter 2.6s ease-in-out infinite; +} + +.flight-cockpit__tape--speed .flight-cockpit__ticks { + background-position-x: right; + border-right: 1px solid rgba(232, 251, 255, 0.35); +} + +.flight-cockpit__tape--alt .flight-cockpit__ticks { + border-left: 1px solid rgba(232, 251, 255, 0.35); +} + +.flight-cockpit__tape b { + position: relative; + align-self: center; + grid-row: 1; + grid-column: 1; + min-width: 34px; + padding: 1px 4px; + border: 1px solid rgba(232, 251, 255, 0.8); + background: rgba(5, 8, 11, 0.7); + color: #e8fbff; + font-family: var(--font-mono); + font-size: 0.6rem; + font-weight: 600; + text-align: center; + font-variant-numeric: tabular-nums; +} + +.flight-cockpit__tape em { + position: absolute; + bottom: -12px; + color: rgba(54, 220, 255, 0.85); + font-family: var(--font-mono); + font-size: 0.45rem; + font-style: normal; + letter-spacing: 0.1rem; +} + +@keyframes flight-cockpit-jitter { + 50% { + transform: translateY(2px); + } +} + +.preview-hud--cockpit .preview-hud__ruler { + display: none; +} + +@media (prefers-reduced-motion: reduce) { + .flight-cockpit__ticks { + animation: none; + transition: none; + } +} +.entity-card__preview-switch button { + display: grid; + place-items: center; + width: 26px; + height: 22px; + padding: 0; +} + +.entity-card__preview-switch button .material-symbols-outlined { + font-size: 15px; +} + +.entity-card__preview-switch button:not(:has(.material-symbols-outlined)) { + width: auto; + padding: 0 0.5rem; + font-family: var(--font-mono); + font-size: 0.62rem; + font-weight: 600; +} +.satellite-ground__credit, +.flight-cockpit__credit { + left: 8px; + max-width: none; + line-height: 1.25; + text-align: right; +} +.satellite-ground__credit, +.flight-cockpit__credit { + left: auto; + max-width: calc(100% - 110px); +} diff --git a/src/ui/views/ContextView.vue b/src/ui/views/ContextView.vue index 461774c22..9ff07fb3a 100644 --- a/src/ui/views/ContextView.vue +++ b/src/ui/views/ContextView.vue @@ -248,7 +248,7 @@ watch(
- + diff --git a/src/ui/views/panels/AircraftModelHero.vue b/src/ui/views/panels/AircraftModelHero.vue new file mode 100644 index 000000000..8ad53ef25 --- /dev/null +++ b/src/ui/views/panels/AircraftModelHero.vue @@ -0,0 +1,277 @@ + + + diff --git a/src/ui/views/panels/AltitudeGraph.vue b/src/ui/views/panels/AltitudeGraph.vue index bf2719b79..7fab7773e 100644 --- a/src/ui/views/panels/AltitudeGraph.vue +++ b/src/ui/views/panels/AltitudeGraph.vue @@ -2,7 +2,8 @@ import { computed, ref, watch } from 'vue'; import { formatNumber, t } from '../../../i18n/index.js'; -// A height as a filled graph (an aircraft's altitude, the camera's height): +// A figure as a filled graph (an aircraft's altitude, the camera's height, a +// satellite's altitude and speed): // each reading since it opened, left to right. The scale fits the readings (never less than about // 2,000 ft tall), so a climb or descent shows as a slope, and the fill // fades from the line down to the baseline. @@ -13,7 +14,11 @@ const props = defineProps({ tick: { type: Number, default: 0 }, /** The caption; 'Altitude' when not given. */ label: { type: String, default: '' }, - /** 'feet' for aircraft; 'metric' reads in metres and kilometres. */ + /** + * 'feet' for aircraft; 'metric' reads in metres and kilometres on a log + * scale (the camera); 'km' is a height in kilometres and 'km/s' a speed + * (given in m/s), both on a straight scale (a satellite). + */ unit: { type: String, default: 'feet' }, /** Only the caption, the current figure and the line: no scale or change. */ compact: { type: Boolean, default: false }, @@ -43,7 +48,14 @@ const metric = (m) => : m >= 1000 ? t('{n} km', { n: formatNumber(m / 1000, { minimumFractionDigits: 1, maximumFractionDigits: 1 }) }) : t('{n} m', { n: number(Math.round(m)) }); -const shown = (m) => (props.unit === 'metric' ? metric(m) : t('{n} ft', { n: number(feet(m)) })); +const SHOW = { + metric, + km: (m) => t('{n} km', { n: number(Math.round(m / 100) / 10) }), + 'km/s': (m) => t('{n} km/s', { n: formatNumber(m / 1000, { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }), +}; +const shown = (m) => (SHOW[props.unit] || ((value) => t('{n} ft', { n: number(feet(value)) })))(m); +/** The least each scale spans, so a steady figure still reads as a line. */ +const LEAST = { feet: MIN_RANGE_M, km: 2000, 'km/s': 20 }; const graph = computed(() => { const list = readings.value; @@ -60,7 +72,7 @@ const graph = computed(() => { const low = Math.min(...heights); // The least the scale spans: about 2,000 ft for aircraft, half a decade // for the camera. - const least = log ? 0.5 : MIN_RANGE_M; + const least = log ? 0.5 : LEAST[props.unit] || MIN_RANGE_M; const pad = Math.max((least - (high - low)) / 2, (high - low) * 0.15); const bottom = Math.max(0, low - pad); const top = Math.max(high + pad, bottom + least); @@ -71,8 +83,9 @@ const graph = computed(() => { const points = list.length > 1 ? list.map((item) => [x(item.at), y(item.m)]) : [[0, y(first.m)], [WIDTH, y(first.m)]]; const line = points.map(([px, py], index) => `${index ? 'L' : 'M'}${px.toFixed(2)} ${py.toFixed(2)}`).join(' '); const moved = last.m - first.m; - const change = props.unit === 'metric' ? (Math.abs(moved) >= Math.max(1, last.m * 0.005) ? moved : 0) : feet(last.m) - feet(first.m); - const changeText = props.unit === 'metric' ? metric(Math.abs(moved)) : t('{n} ft', { n: number(Math.abs(change)) }); + const feetScale = !SHOW[props.unit]; + const change = feetScale ? feet(last.m) - feet(first.m) : Math.abs(moved) >= Math.max(1, last.m * 0.0005) ? moved : 0; + const changeText = feetScale ? t('{n} ft', { n: number(Math.abs(change)) }) : shown(Math.abs(moved)); const minutes = Math.floor((last.at - first.at) / 60_000); return { line, diff --git a/src/ui/views/panels/EntityCard.vue b/src/ui/views/panels/EntityCard.vue index 9c05adbbd..3bca36f40 100644 --- a/src/ui/views/panels/EntityCard.vue +++ b/src/ui/views/panels/EntityCard.vue @@ -1,10 +1,14 @@ + + diff --git a/src/ui/views/panels/PreviewHud.vue b/src/ui/views/panels/PreviewHud.vue new file mode 100644 index 000000000..4ff0599e1 --- /dev/null +++ b/src/ui/views/panels/PreviewHud.vue @@ -0,0 +1,93 @@ + + + diff --git a/src/ui/views/panels/RouteGlobe.vue b/src/ui/views/panels/RouteGlobe.vue new file mode 100644 index 000000000..01906237b --- /dev/null +++ b/src/ui/views/panels/RouteGlobe.vue @@ -0,0 +1,326 @@ + + + diff --git a/src/ui/views/panels/SatelliteGroundView.vue b/src/ui/views/panels/SatelliteGroundView.vue new file mode 100644 index 000000000..77021ff49 --- /dev/null +++ b/src/ui/views/panels/SatelliteGroundView.vue @@ -0,0 +1,107 @@ + + + From 3a0842c103837799f31e3aae0dc37a20aefb73f0 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 15:44:31 -0800 Subject: [PATCH 2/5] Draw the card previews through the renderer, and show vessel photos too - The route globe, turning model and cockpit view are the renderer's: the Cesium plugin hands them over as its `cardPreviews` application hook (src/render/cesium/cardPreviews.js), and the card's tiles keep only the words, figures and HUD laid over them. Nothing in the UI reaches Cesium, and a renderer without the hook leaves the card its photo and figures. - The turning model is the fleet model the globe draws for the aircraft's type, from the set loaded at startup, so opening a card fetches nothing. The flights layer's record now carries the type code and emitter category that pick it. - The photo comes from the item's own layer: the flights layer's Planespotters photo for the plane it tracks, and the vessels layer's Open Vessel Photos photo for the vessel selected, with its credit. It no longer waits for Contacts to follow the same aircraft. - The satellite models are left out: the card shows a satellite's ground view and graphs its altitude and speed. - The route globe's airport codes are drawn into its own small scene, the compass reads its course in the active language, the callouts no longer speak to screen readers every six seconds, and figures use the app's number format. Esri's tile address and credit live in one place. Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 13 + index.html | 2 +- scripts/package-boundaries.json | 52 +- src/data/entityContext.js | 40 ++ src/data/entityContext.test.mjs | 325 ++++++++- src/data/flights.test.mjs | 4 + src/data/inputOwnership.test.mjs | 6 +- src/layers/flights/queries.js | 3 + src/maps/attribution.js | 9 +- src/maps/globeEngine.js | 8 +- src/render/applicationHooks.js | 5 + src/render/cesium/appRenderer.js | 4 + src/render/cesium/cardPreviews.js | 725 ++++++++++++++++++++ src/render/cesium/mapImagery.js | 4 +- src/render/contract/renderer.d.ts | 69 ++ src/stories/thumbs.js | 2 +- src/ui/entityContextBridge.js | 5 +- src/ui/previewWidget.js | 30 - src/ui/stores/entityCard.js | 3 + src/ui/styles/entity-card.css | 2 +- src/ui/views/ContextView.vue | 2 +- src/ui/views/panels/AircraftModelHero.vue | 262 ++----- src/ui/views/panels/EntityCard.vue | 48 +- src/ui/views/panels/FlightCockpitView.vue | 96 +-- src/ui/views/panels/RouteGlobe.vue | 299 +------- src/ui/views/panels/SatelliteGroundView.vue | 5 +- 26 files changed, 1347 insertions(+), 676 deletions(-) create mode 100644 src/render/cesium/cardPreviews.js delete mode 100644 src/ui/previewWidget.js diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 166e537b9..285ff5a88 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -933,6 +933,19 @@ come through the regional brief service; earthquakes, tropical storms and fire perimeters come from the same feeds as their layers, cached for five minutes; satellite fire hits only while the FIRMS layer is on. +The card's top tile previews what is picked. A flight shows its +Planespotters photo once the flights layer has looked one up for the plane +it tracks, its route on a small globe (origin to destination, flown part +solid, the plane on it), its fleet model turning with callouts of what can +be worked out about the flight, and the view ahead from its cockpit with +speed and altitude tapes; the model and the cockpit view take turns. A +vessel shows its Open Vessel Photos photo, a satellite the ground beneath it +from Esri World Imagery with its altitude and speed graphed. The globe, model +and cockpit view are drawn by the renderer through its `cardPreviews` +application hook (`src/render/cesium/cardPreviews.js`), each in a small scene +of its own that frees its graphics context as it closes; the model comes from +the fleet set loaded at startup, so opening a card fetches no model. + ## Wikidata cities pack — November 15, 2026 `src/data/local_data/wikidata_cities/cities.json` bundles 31,827 settlements of diff --git a/index.html b/index.html index fcc5f79cf..c159503c1 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,7 @@ with the sources: src/materialSymbolsSubset.test.mjs fails when a source names a glyph this list is missing, because a missing glyph does not draw a box — the ligature never forms and the element renders the literal word. --> - +
diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 8db0d6c70..a5a719033 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -276,7 +276,16 @@ "src/ui/views/panels/EntityCard.vue", "src/data/aircraftEmergency.js", "src/data/aircraftClass.js", - "src/data/entityRecords.js" + "src/data/entityRecords.js", + "src/ui/views/panels/RouteGlobe.vue", + "src/maps/attribution.js", + "src/ui/views/panels/FlightCockpitView.vue", + "src/ui/views/panels/PreviewHud.vue", + "src/data/fleetTrailAnchors.js", + "src/ui/views/panels/SatelliteGroundView.vue", + "src/data/vesselTypes.js", + "src/data/fleetModels.js", + "src/ui/views/panels/AircraftModelHero.vue" ], "external": ["vue", "pinia", "vue-i18n"] }, @@ -1636,7 +1645,8 @@ "src/ui/stores/entityCard.js", "src/ui/entityContextBridge.js", "src/data/trackingClickGesture.js", - "src/ui/stores/sceneSharing.js" + "src/ui/stores/sceneSharing.js", + "src/maps/attribution.js" ], "external": [ "cesium", @@ -2422,7 +2432,8 @@ "src/render/vectorBase/paint.js", "src/layers/wind/streamlines.js", "src/layers/wind/model.js", - "src/sky/assets.js" + "src/sky/assets.js", + "src/render/cesium/cardPreviews.js" ], "external": ["cesium", "pbf", "@mapbox/vector-tile", "kdbush"] }, @@ -2571,7 +2582,8 @@ "src/render/applicationHooks.js", "src/maps/globeEngine.js", "src/maps/engine.js", - "src/maps/keylessTerrain.js" + "src/maps/keylessTerrain.js", + "src/maps/attribution.js" ], "external": ["cesium"] }, @@ -5216,37 +5228,13 @@ "src/library/entries/wri-global-power-plants.json", "src/library/entries/wv-statewide-imagery.json", "src/library/formats.js", - "src/library/entries/gvp-holocene-volcanoes.json", - "src/library/entries/nasa-black-marble.json", - "src/library/entries/nasa-eonet-events.json", "src/library/catalog.js", "src/library/source.js", "src/library/layers.js", "src/library/controller.js", "src/library/extent.js", "src/library/camera.js", - "src/library/entries/imf-portwatch-disruptions.json", - "src/library/entries/imf-portwatch-chokepoints.json", - "src/library/entries/noaa-tide-stations.json", - "src/library/entries/nws-active-alerts.json", - "src/library/entries/wri-global-power-plants.json", - "src/library/entries/fema-usa-structures.json", - "src/library/entries/epc-england-wales.json", "src/library/parquet.js", - "src/library/entries/bkg-topplus-open.json", - "src/library/entries/epa-superfund-sites.json", - "src/library/entries/epa-toxic-release-facilities.json", - "src/library/entries/gbif-occurrence-density.json", - "src/library/entries/gdacs-disaster-alerts.json", - "src/library/entries/gsi-japan-map.json", - "src/library/entries/ign-orthophotos-france.json", - "src/library/entries/gsi-japan-photo.json", - "src/library/entries/jrc-surface-water.json", - "src/library/entries/ntad-national-bridges.json", - "src/library/entries/usgs-hydrography.json", - "src/library/entries/macrostrat-geology.json", - "src/library/entries/swisstopo-swissimage.json", - "src/library/entries/usgs-topo.json", "src/library/outlines.js", "src/library/relief.js", "src/sceneCommandRelease.js", @@ -5444,7 +5432,8 @@ "src/ui/stores/omnibar.js", "src/data/entityContext.js", "src/ui/stores/entityCard.js", - "src/ui/entityContextBridge.js" + "src/ui/entityContextBridge.js", + "src/render/cesium/cardPreviews.js" ], "external": [ "hls.js", @@ -6213,8 +6202,6 @@ "src/layers/osmPlaces/index.js", "src/app/layers/osmPlaces.js", "src/layers/awareness/rangeRing.js", - "src/data/feedState.js", - "src/loadingFeedback.js", "src/data/firmsIntensity.js", "src/data/firmsHeatRaster.js", "src/layers/firms/heatImagery.js", @@ -6272,7 +6259,8 @@ "src/layers/flights/placed.js", "src/data/placementProvider.js", "src/data/courseFromFixes.js", - "src/time/frameWait.js" + "src/time/frameWait.js", + "src/maps/attribution.js" ], "external": [ "hls.js", diff --git a/src/data/entityContext.js b/src/data/entityContext.js index dd38908e9..065d06188 100644 --- a/src/data/entityContext.js +++ b/src/data/entityContext.js @@ -949,6 +949,36 @@ export function aircraftInsights(record, { nowMs = Date.now() } = {}) { return out; } +/** + * The item's photo, once its layer has looked one up: the tracked airliner's + * Planespotters photo, or the selected vessel's Open Vessel Photos photo. + * @returns {{src: string, link: string, photographer: string, + * licence: string}|null} + */ +function cardPhoto(dataManager, layerId, record) { + let photo = null; + try { + const layer = dataManager?.layers?.get?.(layerId)?.module; + if (layerId === 'ais-live-vessels') + photo = layer?.getVesselPhoto?.(text(record?.vesselId)); + else if (layerId === 'flights') { + // Looked up only for the plane the layer tracks. + const tracked = layer?.getTrackedSubject?.(); + if (tracked && text(tracked.id) === text(record?.icao24)) + photo = tracked.photo; + } + } catch { + photo = null; + } + if (!text(photo?.src)) return null; + return { + src: text(photo.src), + link: text(photo.link), + photographer: text(photo.photographer), + licence: text(photo.licence), + }; +} + export function describeEntity( dataManager, identity, @@ -1024,6 +1054,16 @@ export function describeEntity( warningWords: warnings.map((entry) => entry.words), // For the aircraft card's model and route line. aircraftClass, + // What picks the fleet model the globe draws this aircraft with. + aircraftModel: + kind.kind === 'aircraft' && record + ? { + typeCode: text(record.typeCode ?? record.type) || null, + category: record.category ?? null, + callsign: text(record.callsign) || null, + } + : null, + photo: cardPhoto(dataManager, layerId, record), // Its class's English name, for the UI to translate; null when unknown. aircraftClassName: AIRCRAFT_CLASS_LABELS[aircraftClass] || null, insights: diff --git a/src/data/entityContext.test.mjs b/src/data/entityContext.test.mjs index 8a04c7294..c18d76c39 100644 --- a/src/data/entityContext.test.mjs +++ b/src/data/entityContext.test.mjs @@ -37,8 +37,20 @@ const flights = Array.from({ length: 2500 }, (_, i) => ({ altitudeM: 10000, })); const dams = [ - { id: 'Grand Coulee Dam', name: 'Grand Coulee Dam', lat: 47.957, lon: -118.981, operator: 'Bureau of Reclamation' }, - { id: '123456', name: null, lat: 47.9, lon: -118.9, operator: 'Some Utility' }, + { + id: 'Grand Coulee Dam', + name: 'Grand Coulee Dam', + lat: 47.957, + lon: -118.981, + operator: 'Bureau of Reclamation', + }, + { + id: '123456', + name: null, + lat: 47.9, + lon: -118.9, + operator: 'Some Utility', + }, ]; const dm = manager({ flights: { name: 'Live Flights', records: flights }, @@ -46,7 +58,12 @@ const dm = manager({ }); test('a click identity finds its record by key, past the first 2000 records', () => { - const record = findRecord(dm, { layerId: 'flights', id: 'a02400', lat: 0, lon: 0 }); + const record = findRecord(dm, { + layerId: 'flights', + id: 'a02400', + lat: 0, + lon: 0, + }); assert.equal(record?.callsign, 'FLT2400'); }); @@ -74,7 +91,9 @@ test('a transit click finds its vehicle by the layer key and reads its state', ( lon: -97.71, }); assert.equal(card?.title, 'M634'); - const facts = Object.fromEntries(card.facts.map((fact) => [fact.label, fact.value])); + const facts = Object.fromEntries( + card.facts.map((fact) => [fact.label, fact.value]), + ); assert.equal(facts.Operator, 'CapMetro'); assert.equal(facts.Status, 'Heading to next stop'); assert.equal(facts.Key, undefined, 'the layer key is not shown'); @@ -86,8 +105,20 @@ test('transit vehicles break down by motion, mode and reported state', () => { transit: { name: 'Transit', records: [ - { id: '1', mode: 'bus', motion: 'moving', status: 'IN_TRANSIT_TO', ...at }, - { id: '2', mode: 'bus', motion: 'stopped', status: 'STOPPED_AT', ...at }, + { + id: '1', + mode: 'bus', + motion: 'moving', + status: 'IN_TRANSIT_TO', + ...at, + }, + { + id: '2', + mode: 'bus', + motion: 'stopped', + status: 'STOPPED_AT', + ...at, + }, { id: '3', mode: 'rail', motion: 'moving', occupancy: 'FULL', ...at }, ], }, @@ -95,15 +126,28 @@ test('transit vehicles break down by motion, mode and reported state', () => { const breakdown = layerBreakdown(buses, 'transit'); assert.equal(breakdown.total, 3); const split = (title) => - Object.fromEntries(breakdown.splits.find((item) => item.title === title).parts.map((part) => [part.label, part.count])); + Object.fromEntries( + breakdown.splits + .find((item) => item.title === title) + .parts.map((part) => [part.label, part.count]), + ); assert.deepEqual(split('Motion'), { Moving: 2, Stopped: 1 }); assert.deepEqual(split('Mode'), { Bus: 2, Rail: 1 }); - assert.deepEqual(split('Last reported'), { 'Heading to next stop': 1, 'Stopped at a stop': 1 }); + assert.deepEqual(split('Last reported'), { + 'Heading to next stop': 1, + 'Stopped at a stop': 1, + }); assert.deepEqual(split('Crowding'), { Full: 1 }); }); test('a moving item never borrows a nearby craft when its key is unknown', () => { - const record = findRecord(dm, { layerId: 'flights', id: 'zzzzzz', label: 'NOPE', lat: 34.0004, lon: -118.05 }); + const record = findRecord(dm, { + layerId: 'flights', + id: 'zzzzzz', + label: 'NOPE', + lat: 34.0004, + lon: -118.05, + }); assert.equal(record, null); }); @@ -115,12 +159,19 @@ test('a card lists facts with units and keeps the title out of them', () => { const card = describeEntity(dm, { layerId: 'flights', id: 'a00001' }); assert.equal(card.title, 'FLT1'); assert.equal(card.kind, 'aircraft'); - assert.ok(card.facts.some((fact) => fact.label === 'Altitude' && fact.value === '32,808 ft')); + assert.ok( + card.facts.some( + (fact) => fact.label === 'Altitude' && fact.value === '32,808 ft', + ), + ); assert.ok(!card.facts.some((fact) => fact.value === 'FLT1')); }); test('nearby lists the closest of the same kind and one of each other layer', () => { - const card = describeEntity(dm, { layerId: 'local-dams', id: 'Grand Coulee Dam' }); + const card = describeEntity(dm, { + layerId: 'local-dams', + id: 'Grand Coulee Dam', + }); const { same, other } = nearbyEntities(dm, card, { radiusKm: 2000 }); assert.equal(same[0].title, 'Some Utility'); assert.equal(other.length, 1); @@ -138,7 +189,10 @@ test('fact formatting follows the field suffix', () => { assert.equal(formatFact('speedMps', 100).value, '194 kt'); // Orbital speeds read in km/s, road and rail in km/h. assert.equal(formatFact('speedMps', 7670).value, '7.67 km/s'); - assert.equal(formatFact('speedMps', 10, { kind: 'vehicle' }).value, '36 km/h'); + assert.equal( + formatFact('speedMps', 10, { kind: 'vehicle' }).value, + '36 km/h', + ); // Units follow the field's suffix; feed codes and bare words read as words. assert.equal(formatFact('containedPct', 96).value, '96%'); assert.equal(formatFact('windKt', 30).value, '30 kt'); @@ -148,21 +202,54 @@ test('fact formatting follows the field suffix', () => { assert.equal(formatFact('icao24', 'abcdef').value, 'abcdef'); assert.equal(formatFact('shipType', 70).value, 'Cargo'); assert.equal(formatFact('shipType', 'Tanker').value, 'Tanker'); - assert.equal(formatFact('discoveredTime', Date.UTC(2026, 5, 29)).value, '29 Jun 2026'); - assert.equal(formatFact('updatedTime', 1_700_000_000_000, { nowMs: 1_700_000_060_000 }).age, 60_000); + assert.equal( + formatFact('discoveredTime', Date.UTC(2026, 5, 29)).value, + '29 Jun 2026', + ); + assert.equal( + formatFact('updatedTime', 1_700_000_000_000, { nowMs: 1_700_000_060_000 }) + .age, + 60_000, + ); assert.equal(formatFact('altitudeM', 420000).value, '420 km'); assert.equal(formatFact('confidence', 0.82).value, '82%'); assert.equal(formatFact('onGround', false), null); - assert.equal(formatFact('lastContactAtMs', 1_700_000_000_000, { nowMs: 1_700_000_060_000 }).age, 60_000); + assert.equal( + formatFact('lastContactAtMs', 1_700_000_000_000, { + nowMs: 1_700_000_060_000, + }).age, + 60_000, + ); }); test('warnings lead with an emergency, then the squawk code, and stay out of the facts', () => { - assert.deepEqual(recordWarnings({ emergency: true, emergencyKind: 'medical' }), ['Emergency: medical']); - assert.deepEqual(recordWarnings({ squawk: '7600' }), ['Radio failure (squawk 7600)']); - assert.deepEqual(recordWarnings({ squawk: '1200', emergencyKind: 'none' }), []); + assert.deepEqual( + recordWarnings({ emergency: true, emergencyKind: 'medical' }), + ['Emergency: medical'], + ); + assert.deepEqual(recordWarnings({ squawk: '7600' }), [ + 'Radio failure (squawk 7600)', + ]); + assert.deepEqual( + recordWarnings({ squawk: '1200', emergencyKind: 'none' }), + [], + ); assert.deepEqual(recordWarnings({ tsunami: 1 }), ['Tsunami warning issued']); const urgent = manager({ - flights: { name: 'Live Flights', records: [{ id: 'X1', icao24: 'x00001', callsign: 'X1', lat: 1, lon: 1, emergency: true, emergencyKind: 'fuel' }] }, + flights: { + name: 'Live Flights', + records: [ + { + id: 'X1', + icao24: 'x00001', + callsign: 'X1', + lat: 1, + lon: 1, + emergency: true, + emergencyKind: 'fuel', + }, + ], + }, }); const card = describeEntity(urgent, { layerId: 'flights', id: 'x00001' }); assert.deepEqual(card.warnings, ['Emergency: fuel']); @@ -184,7 +271,13 @@ test('the view summary counts each layer inside the view, closest to the middle test('flight insights work out phase, flight level, Mach, squawk meaning and signal age', () => { const insights = aircraftInsights( - { altitudeM: 10668, verticalRateMps: 0, speedMps: 230, squawk: '7000', lastContactAtMs: 1_000_000 }, + { + altitudeM: 10668, + verticalRateMps: 0, + speedMps: 230, + squawk: '7000', + lastContactAtMs: 1_000_000, + }, { nowMs: 1_012_000 }, ); const value = (label) => insights.find((item) => item.label === label)?.value; @@ -192,20 +285,57 @@ test('flight insights work out phase, flight level, Mach, squawk meaning and sig assert.equal(value('Flight level'), 'FL350'); assert.equal(value('Mach'), 'M 0.78'); assert.equal(value('Squawk {code}'), 'VFR conspicuity'); - assert.deepEqual(insights.find((item) => item.label === 'Squawk {code}').labelValues, { code: '7000' }); + assert.deepEqual( + insights.find((item) => item.label === 'Squawk {code}').labelValues, + { code: '7000' }, + ); assert.equal(value('Signal'), '12 s ago'); assert.equal(aircraftInsights({ onGround: true })[0].value, 'On the ground'); - assert.match(aircraftInsights({ verticalRateMps: -8 })[0].value, /^Descending 1600 ft\/min$/); + assert.match( + aircraftInsights({ verticalRateMps: -8 })[0].value, + /^Descending 1600 ft\/min$/, + ); }); test('a layer breakdown splits aircraft by status and type, inside a view when given', () => { const craft = [ - { id: 'A', lat: 10, lon: 10, onGround: false, military: false, aircraftClass: 'airliner' }, - { id: 'B', lat: 10, lon: 11, onGround: false, military: true, aircraftClass: 'fastjet' }, - { id: 'C', lat: 10, lon: 12, onGround: true, military: true, aircraftClass: 'airliner' }, - { id: 'D', lat: 60, lon: 12, onGround: false, military: false, aircraftClass: 'airliner' }, + { + id: 'A', + lat: 10, + lon: 10, + onGround: false, + military: false, + aircraftClass: 'airliner', + }, + { + id: 'B', + lat: 10, + lon: 11, + onGround: false, + military: true, + aircraftClass: 'fastjet', + }, + { + id: 'C', + lat: 10, + lon: 12, + onGround: true, + military: true, + aircraftClass: 'airliner', + }, + { + id: 'D', + lat: 60, + lon: 12, + onGround: false, + military: false, + aircraftClass: 'airliner', + }, ]; - const data = manager({ flights: { name: 'Live Flights', records: craft }, 'local-dams': { name: 'Dams', records: dams } }); + const data = manager({ + flights: { name: 'Live Flights', records: craft }, + 'local-dams': { name: 'Dams', records: dams }, + }); const all = layerBreakdown(data, 'flights'); assert.equal(all.total, 4); assert.deepEqual(all.splits[0].parts, [ @@ -217,23 +347,52 @@ test('a layer breakdown splits aircraft by status and type, inside a view when g { label: 'Airliners', count: 3 }, { label: 'Fast jets', count: 1 }, ]); - const near = layerBreakdown(data, 'flights', { rect: { west: 9, east: 13, south: 9, north: 11 } }); + const near = layerBreakdown(data, 'flights', { + rect: { west: 9, east: 13, south: 9, north: 11 }, + }); assert.equal(near.total, 3); assert.equal(layerBreakdown(data, 'local-dams'), null); }); test('a moving item with an unknown key is not matched to a craft right beside it', () => { // About 110 m from FLT0: well inside any nearest-item reach. - assert.equal(findRecord(dm, { layerId: 'flights', id: 'zzzzzz', label: 'NOPE', lat: 34.001, lon: -118 }), null); + assert.equal( + findRecord(dm, { + layerId: 'flights', + id: 'zzzzzz', + label: 'NOPE', + lat: 34.001, + lon: -118, + }), + null, + ); }); test('sites that share a key are told apart by where the identity says they are', () => { const sites = [ - { id: 'Amazon Web Services', name: 'Amazon Web Services', lat: -52.942, lon: -70.849 }, - { id: 'Amazon Web Services', name: 'Amazon Web Services', lat: -33.557, lon: -70.813 }, + { + id: 'Amazon Web Services', + name: 'Amazon Web Services', + lat: -52.942, + lon: -70.849, + }, + { + id: 'Amazon Web Services', + name: 'Amazon Web Services', + lat: -33.557, + lon: -70.813, + }, ]; - const data = manager({ 'local-datacenters': { name: 'Datacenters', records: sites } }); - const identity = { layerId: 'local-datacenters', id: 'Amazon Web Services', label: 'Amazon Web Services', lat: -33.557, lon: -70.813 }; + const data = manager({ + 'local-datacenters': { name: 'Datacenters', records: sites }, + }); + const identity = { + layerId: 'local-datacenters', + id: 'Amazon Web Services', + label: 'Amazon Web Services', + lat: -33.557, + lon: -70.813, + }; assert.equal(findRecord(data, identity), sites[1]); const card = describeEntity(data, identity); assert.equal(card.lat, -33.557); @@ -242,16 +401,106 @@ test('sites that share a key are told apart by where the identity says they are' }); test('a link is built only from a language code, and a level is not a warning', () => { - const site = { id: 'X', name: 'X', lat: 1, lon: 1, wikipedia: 'evil.example/a#:Y' }; + const site = { + id: 'X', + name: 'X', + lat: 1, + lon: 1, + wikipedia: 'evil.example/a#:Y', + }; const data = manager({ 'local-dams': { name: 'Dams', records: [site] } }); - assert.deepEqual(describeEntity(data, { layerId: 'local-dams', id: 'X', lat: 1, lon: 1 }).links, []); + assert.deepEqual( + describeEntity(data, { layerId: 'local-dams', id: 'X', lat: 1, lon: 1 }) + .links, + [], + ); assert.deepEqual(recordWarnings({ alert: 'green' }), []); }); test('a breakdown names "Other" once', () => { - const ships = [30, 30, 70, 70, 70, 80, 80, 60, 37, 52, 52, 90, 90, 90].map((shipType, i) => ({ id: `S${i}`, mmsi: String(i), lat: 1, lon: 1 + i * 0.01, shipType })); - const data = manager({ 'ais-live-vessels': { name: 'Vessels', records: ships } }); - const labels = layerBreakdown(data, 'ais-live-vessels').splits[0].parts.map((part) => part.label); + const ships = [30, 30, 70, 70, 70, 80, 80, 60, 37, 52, 52, 90, 90, 90].map( + (shipType, i) => ({ + id: `S${i}`, + mmsi: String(i), + lat: 1, + lon: 1 + i * 0.01, + shipType, + }), + ); + const data = manager({ + 'ais-live-vessels': { name: 'Vessels', records: ships }, + }); + const labels = layerBreakdown(data, 'ais-live-vessels').splits[0].parts.map( + (part) => part.label, + ); assert.equal(labels.filter((label) => label === 'Other').length <= 1, true); assert.equal(new Set(labels).size, labels.length); }); + +test('a card shows the photo its layer looked up: the tracked airliner, the selected vessel', () => { + const photo = { + src: 'https://cdn.example/p.jpg', + link: 'https://example/p', + photographer: 'A. Spotter', + width: 640, + }; + const planes = manager({ + flights: { + name: 'Live Flights', + records: [ + { + id: 'DAL1', + icao24: 'aa0001', + callsign: 'DAL1', + lat: 34, + lon: -118, + typeCode: 'B739', + category: 'A3', + }, + { id: 'DAL2', icao24: 'aa0002', callsign: 'DAL2', lat: 35, lon: -118 }, + ], + }, + 'ais-live-vessels': { + name: 'Vessels', + records: [ + { + id: 'EVER GIVEN', + vesselId: 'v1', + mmsi: '353136000', + lat: 30, + lon: 32, + }, + ], + }, + }); + planes.layers.get('flights').module.getTrackedSubject = () => ({ + id: 'aa0001', + photo, + }); + planes.layers.get('ais-live-vessels').module.getVesselPhoto = (id) => + id === 'v1' ? { ...photo, licence: 'CC BY 4.0' } : null; + + const tracked = describeEntity(planes, { layerId: 'flights', id: 'aa0001' }); + assert.deepEqual(tracked.photo, { + src: photo.src, + link: photo.link, + photographer: 'A. Spotter', + licence: '', + }); + // What picks the globe's fleet model for it. + assert.deepEqual(tracked.aircraftModel, { + typeCode: 'B739', + category: 'A3', + callsign: 'DAL1', + }); + // Photos are looked up for the tracked plane only. + assert.equal( + describeEntity(planes, { layerId: 'flights', id: 'aa0002' }).photo, + null, + ); + assert.equal( + describeEntity(planes, { layerId: 'ais-live-vessels', id: 'EVER GIVEN' }) + .photo.licence, + 'CC BY 4.0', + ); +}); diff --git a/src/data/flights.test.mjs b/src/data/flights.test.mjs index 72fa1ea18..81e8e5f71 100644 --- a/src/data/flights.test.mjs +++ b/src/data/flights.test.mjs @@ -91,6 +91,8 @@ const FULL_INFO = { verticalRate: -4.5, onGround: false, klass: 'airliner', + typeCode: 'B738', + category: 'A3', originCountry: 'United States', airline: 'Southwest Airlines', route: { origin: { code: 'AUS' }, destination: { code: 'LAX' } }, @@ -114,6 +116,8 @@ test('flights analyst record: full record maps every contract field', () => { onGround: false, military: false, aircraftClass: 'airliner', + typeCode: 'B738', + category: 'A3', originCountry: 'United States', operator: 'Southwest Airlines', squawk: null, diff --git a/src/data/inputOwnership.test.mjs b/src/data/inputOwnership.test.mjs index aaa0cd8cd..c5c22fa82 100644 --- a/src/data/inputOwnership.test.mjs +++ b/src/data/inputOwnership.test.mjs @@ -167,8 +167,10 @@ test('pointer input, camera holds and the stock clicks go through the one dispat [ /\.enableInputs\s*=(?!=)/, 'writes enableInputs instead of suspendCamera()', - // The scene's camera-input holds, which own the flag. - ['src/render/cesium/cameraInput.js'], + // The scene's camera-input holds, which own the flag; the Context + // card's previews turn it off in their own small scenes, which take + // no input at all. + ['src/render/cesium/cameraInput.js', 'src/render/cesium/cardPreviews.js'], ], [ /(?:screenSpaceEventHandler|stockHandler)\??\.removeInputAction\(/, diff --git a/src/layers/flights/queries.js b/src/layers/flights/queries.js index 3e3074f95..365af11db 100644 --- a/src/layers/flights/queries.js +++ b/src/layers/flights/queries.js @@ -288,6 +288,9 @@ export function createQueries({ // A converted contact reports the class it RENDERS as, so an analyst // filter/superlative agrees with the triangle on screen. aircraftClass: tr3bAircraftClass(icao24, text(info?.klass)), + // What picks its fleet model, for the context card's turning model. + typeCode: text(info?.typeCode), + category: info?.category ?? null, originCountry: text(info?.originCountry), operator: text(info?.airline), squawk: text(info?.squawk), diff --git a/src/maps/attribution.js b/src/maps/attribution.js index 71f5a201e..38fa50eed 100644 --- a/src/maps/attribution.js +++ b/src/maps/attribution.js @@ -1,8 +1,15 @@ /** * @module maps/attribution - * @description The on-map credits of the map stacks' sources. + * @description The on-map credits of the map stacks' sources, and Esri + * World Imagery's tile address, which the globe and the card previews share. */ // Attribution and service rights are documented in DATA_SOURCES.md. +/** Esri World Imagery's tiles; Stories' card images draw from the same. */ +export const ESRI_TILES = + 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'; +/** Esri World Imagery's credit line, as plain text. */ +export const ESRI_IMAGERY_CREDIT = + 'Powered by Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community'; export const ESRI_ATTRIBUTION_HTML = 'Powered by Esri'; diff --git a/src/maps/globeEngine.js b/src/maps/globeEngine.js index a2088973e..76bad33ef 100644 --- a/src/maps/globeEngine.js +++ b/src/maps/globeEngine.js @@ -13,13 +13,9 @@ * photoreal base is turned off through the port and on again when shown. */ import { findFrame, findGlobe, rendererOf } from '../render/rendererOf.js'; +import { ESRI_IMAGERY_CREDIT, ESRI_TILES } from './attribution.js'; import { KEYLESS_TERRAIN_URL } from './keylessTerrain.js'; -/** Esri World Imagery's tiles; Stories' card images draw from the same. */ -export const ESRI_TILES = - 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'; -const ESRI_CREDIT = - 'Powered by Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community'; const OSM_TILES = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'; const OSM_CREDIT = '© OpenStreetMap contributors'; /** Cesium ion's world imagery assets (`MAP_STACKS`' `style`). */ @@ -136,7 +132,7 @@ export const globeMapEngine = Object.freeze({ url: ESRI_TILES, tiling: 'webMercator', maxLevel: 19, - credit: credit(ESRI_CREDIT), + credit: credit(ESRI_IMAGERY_CREDIT), }), ion(style, accessToken) { if (!String(accessToken || '').trim()) diff --git a/src/render/applicationHooks.js b/src/render/applicationHooks.js index 7f0cf0e73..c989d4801 100644 --- a/src/render/applicationHooks.js +++ b/src/render/applicationHooks.js @@ -20,6 +20,11 @@ * - `renderFailureNotice({allowReload, store})`: a recoverable notice, * published to `store`, when the renderer stops drawing * (`src/render/cesium/renderFailure.js`); returns its removal. + * - `cardPreviews`: the Context card's previews of a picked aircraft (its + * model turning, its route on a small globe, the view from its cockpit), + * each drawn into an element the card gives it + * (`src/render/cesium/cardPreviews.js`); without it the card shows its + * photo and figures only. * * A plugin hands them as its `applicationHooks(renderer)` * (`ApplicationHooks`, `contract/renderer.d.ts`); the application scene diff --git a/src/render/cesium/appRenderer.js b/src/render/cesium/appRenderer.js index 49cb009f4..94dfc8afc 100644 --- a/src/render/cesium/appRenderer.js +++ b/src/render/cesium/appRenderer.js @@ -37,6 +37,7 @@ import { configureCreditKeyboardAccess } from './creditKeyboard.js'; import { onLocaleChange } from '../../i18n/index.js'; import { cesiumViewerOf, recordViewer } from './viewers.js'; import { installRenderFailureNotice } from './renderFailure.js'; +import { cesiumCardPreviews } from './cardPreviews.js'; export { cesiumViewerOf }; @@ -226,6 +227,9 @@ export function createCesiumRendererPlugin({ // (renderFailure.js). renderFailureNotice: (options) => installRenderFailureNotice(viewer, options), + // The Context card's previews, each in a small scene of its own + // (cardPreviews.js). + cardPreviews: cesiumCardPreviews, }; }, }); diff --git a/src/render/cesium/cardPreviews.js b/src/render/cesium/cardPreviews.js new file mode 100644 index 000000000..674fdf65a --- /dev/null +++ b/src/render/cesium/cardPreviews.js @@ -0,0 +1,725 @@ +/** + * @module render/cesium/cardPreviews + * @description The Context card's previews on the Cesium renderer: an + * aircraft's model turning on its own, its route on a small globe, and the + * view ahead from its cockpit. Each draws in a small Cesium scene of its own + * inside the element it is given, and is torn down with the card. The + * application reaches them through the `cardPreviews` application hook + * (`render/applicationHooks.js`); the card's words, figures and HUD stay + * the application's. + * + * Every preview is `{setActive(active), update(values), destroy()}`: a + * hidden one stops drawing and rests on its last frame, and shown again it + * draws once straight away so there is no gap. A preview that cannot be + * made calls its `onFailed`. + */ +import * as Cesium from 'cesium'; +import { webglContext } from './internals.js'; +import { createEsriImagery } from './mapImagery.js'; + +/** + * Destroy a preview's widget and free its WebGL context. A browser keeps + * only a handful of contexts open and drops the oldest, the main globe's, + * when there are too many; a destroyed widget's context is otherwise freed + * only when garbage is collected, so flicking through cards could push the + * globe's out. + * @param {Cesium.CesiumWidget|null} widget + */ +function destroyWidget(widget) { + if (!widget || widget.isDestroyed()) return; + let gl = null; + try { + gl = webglContext(widget.scene) ?? null; + } catch { + gl = null; + } + widget.destroy(); + try { + gl?.getExtension?.('WEBGL_lose_context')?.loseContext(); + } catch { + // Nothing more can be done; the context goes when it is collected. + } +} + +/** A small widget with no input, credits or render-loop error panel. */ +function createWidget(container, options) { + const widget = new Cesium.CesiumWidget(container, { + skyBox: false, + scene3DOnly: true, + shadows: false, + showRenderLoopErrors: false, + // The globe's own credits already show; a preview's go in its corner. + creditContainer: document.createElement('div'), + ...options, + }); + widget.scene.screenSpaceCameraController.enableInputs = false; + return widget; +} + +/** + * Stops a hidden widget's render loop once `ready()` says it has something + * to rest on; shown again, it draws once at once. + */ +function renderLoopSwitch(widget, ready = () => true) { + let active = true; + const sync = () => { + if (widget.isDestroyed()) return; + const run = active || !ready(); + if (run && !widget.useDefaultRenderLoop) { + widget.resize(); + widget.render(); + } + widget.useDefaultRenderLoop = run; + }; + return { + sync, + set(next) { + active = Boolean(next); + sync(); + }, + }; +} + +const reducedMotion = () => + globalThis.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches === true; + +// ── The turning model ────────────────────────────────────────────────── + +/** How long each look lasts, and each reveal between them, in turns. */ +const PLAIN_TURNS = 1; +const SCAN_TURNS = 0.3; +const REVEAL_TURNS = 0.07; +/** How long (ms) the plain model holds after the reveal before a cycle ends. */ +const HOLD_MS = 700; + +// Model space, normalised so the craft reaches about 1.7 from its centre. +// u_reveal runs 0 to 2: from 0 to 1 the edge grows from the centre and +// leaves wire inside it; at 1 it is all wire; from 1 to 2 it grows again and +// leaves the model inside it. Outside that range the model draws as it is. +const LOOK_SHADER = ` +void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) { + if (u_reveal <= 0.0 || u_reveal >= 2.0) return; + vec3 p = fsInput.attributes.positionMC / u_half; + bool entering = u_reveal < 1.0; + float r = length(p); + float front = mix(0.0, 1.8, entering ? u_reveal : u_reveal - 1.0); + float edge = 1.0 - smoothstep(0.0, 0.05, abs(r - front)); + vec3 white = vec3(0.9, 0.96, 1.0); + bool wire = entering ? r < front : r > front; + if (!wire) { + material.emissive += white * edge * 1.4; + return; + } + // A fine grid: many small cells, hairline lines. + vec3 q = p * 18.0; + vec3 g = abs(fract(q - 0.5) - 0.5) / max(fwidth(q), vec3(1e-4)); + float line = (1.0 - clamp(min(min(g.x, g.y), g.z) * 2.4, 0.0, 1.0)) * 0.7; + vec3 base = material.diffuse; + // Opaque: a near-black body with white lines on it and its own colour + // faintly through, which reads as a wireframe against the dark card (a + // translucent model does not blend onto this scene's transparent canvas). + material.diffuse = base * 0.12 + vec3(0.015, 0.02, 0.03); + material.specular = vec3(0.0); + material.emissive = white * line + base * 0.35 + white * edge * 1.4; +}`; + +/** + * An aircraft's model turning slowly, with no globe, sky or imagery. Its + * look changes as it turns: a whole rotation as it is, then a short + * wireframe scan (under a third of a turn), then round again; each change is + * a reveal, a bright ring growing from the craft's centre to its edges. One + * custom shader does it, driven by a uniform, because a shader set on a + * model after it is ready does nothing in this Cesium. Under reduced motion + * there is no scan. + * + * `onPhase('plain'|'scan')` says when the look changes; `onCycle(ms)` when a + * look and its scan end, with the drawing time they took, so the card can + * give another view the same time. + * @param {HTMLElement} container + * @param {{gltf: Uint8Array|ArrayBuffer, basePath?: string, heading?: number, + * viewRange?: number}} model The GLB's bytes; the heading (degrees) it + * starts facing; how far the camera stands, in bounding radii. + * @param {{onPhase?: (phase: string) => void, onCycle?: (ms: number) => void, + * onFailed?: () => void}} [events] + */ +function modelPreview( + container, + { gltf, basePath, heading = 0, viewRange = 1.9 }, + { onPhase = () => {}, onCycle = () => {}, onFailed = () => {} } = {}, +) { + let widget = null; + let model = null; + let loaded = false; + let removeTick = null; + let loop = null; + const fail = () => { + if (!widget) return; + onFailed(); + }; + try { + widget = createWidget(container, { + globe: false, + skyAtmosphere: false, + baseLayer: false, + contextOptions: { webgl: { alpha: true, antialias: true } }, + }); + const { scene } = widget; + scene.backgroundColor = Cesium.Color.TRANSPARENT; + scene.light = new Cesium.DirectionalLight({ + direction: Cesium.Cartesian3.normalize( + new Cesium.Cartesian3(-0.4, -0.6, -0.7), + new Cesium.Cartesian3(), + ), + intensity: 2.4, + }); + loop = renderLoopSwitch(widget, () => loaded); + } catch { + onFailed(); + return { setActive() {}, update() {}, destroy() {} }; + } + + const shader = new Cesium.CustomShader({ + uniforms: { + u_reveal: { type: Cesium.UniformType.FLOAT, value: 0 }, + u_half: { type: Cesium.UniformType.FLOAT, value: 20 }, + }, + fragmentShaderText: LOOK_SHADER, + }); + const origin = Cesium.Cartesian3.fromDegrees(0, 0, 0); + + const start = (sphere) => { + // The craft reaches about 0.6 of its bounding radius from the centre. + shader.setUniform('u_half', sphere.radius * 0.6); + const first = Cesium.Math.toRadians(heading + 140); + let turn = first; + let phase = 'plain'; + let cycleMs = 0; + let lastFrame = performance.now(); + let holdMs = null; + const still = reducedMotion(); + const range = sphere.radius * viewRange; + const pitch = Cesium.Math.toRadians(-18); + const ease = (x) => x * x * (3 - 2 * x); + const frame = () => { + turn += 0.005; + const turns = (turn - first) / (2 * Math.PI); + // Where in the scan it is, and from that how far each reveal has gone. + const into = (turns % (PLAIN_TURNS + SCAN_TURNS)) - PLAIN_TURNS; + let reveal = 0; + if (!still && into >= 0) { + if (into < REVEAL_TURNS) reveal = ease(into / REVEAL_TURNS); + else if (into > SCAN_TURNS - REVEAL_TURNS) + reveal = + 1 + ease((into - (SCAN_TURNS - REVEAL_TURNS)) / REVEAL_TURNS); + else reveal = 1; + } + const next = reveal > 0 && reveal < 2 ? 'scan' : 'plain'; + // Only time spent drawing counts: a hidden preview stops drawing. + const now = performance.now(); + const drawn = now - lastFrame < 250 ? now - lastFrame : 0; + cycleMs += drawn; + lastFrame = now; + // The cycle ends once the reveal back to the model has finished and + // the plain model has held a moment, never mid-reveal. + if (phase === 'scan' && next === 'plain') holdMs = 0; + if (holdMs !== null && next === 'plain') { + holdMs += drawn; + if (holdMs >= HOLD_MS) { + onCycle(cycleMs); + cycleMs = 0; + holdMs = null; + } + } + if (next !== phase) { + phase = next; + onPhase(phase); + } + shader.setUniform('u_reveal', reveal); + widget.camera.lookAt( + sphere.center, + new Cesium.HeadingPitchRange(turn, pitch, range), + ); + }; + frame(); + removeTick = widget.scene.preRender.addEventListener(frame); + widget.render(); + loaded = true; + loop.sync(); + }; + + Cesium.Model.fromGltfAsync({ + gltf, + basePath, + customShader: shader, + modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(origin), + // A light rim so the mesh reads against the dark card. + silhouetteColor: Cesium.Color.WHITE.withAlpha(0.3), + silhouetteSize: 1, + }).then((made) => { + if (!widget) { + made.destroy(); + return; + } + model = widget.scene.primitives.add(made); + model.readyEvent.addEventListener(() => { + if (widget) start(model.boundingSphere); + }); + model.errorEvent?.addEventListener?.(fail); + }, fail); + + return { + setActive: (active) => loop.set(active), + update() {}, + destroy() { + removeTick?.(); + removeTick = null; + const gone = widget; + widget = null; + model = null; + destroyWidget(gone); + }, + }; +} + +// ── The route globe ──────────────────────────────────────────────────── + +const CYAN = Cesium.Color.fromCssColorString('#36dcff'); +const AMBER = Cesium.Color.fromCssColorString('#ffb86b'); +/** Height (m) the route and the plane are drawn at, clear of the globe. */ +const ROUTE_HEIGHT_M = 30_000; + +// The plane: the Material "flight" silhouette, nose up (north), white with +// a cyan glow, drawn once as an image. +const PLANE_ICON = `data:image/svg+xml;utf8,${encodeURIComponent( + '' + + '' + + '' + + '' + + '', +)}`; + +/** + * An airport's code as an image, white with a dark outline, at the page's + * pixel ratio. The preview is a small scene of its own, so its two codes are + * drawn into it rather than on the world overlay, which belongs to the globe. + * @param {string} code + * @returns {{image: HTMLCanvasElement, width: number, height: number}} + * the image and its size on screen, CSS pixels + */ +function codeImage(code) { + const ratio = Math.min(3, Math.max(1, globalThis.devicePixelRatio || 1)); + const font = `600 ${11 * ratio}px ui-monospace, monospace`; + const canvas = document.createElement('canvas'); + const context = canvas.getContext('2d'); + context.font = font; + const pad = 3 * ratio; + canvas.width = Math.ceil(context.measureText(code).width + pad * 2); + canvas.height = Math.ceil(15 * ratio); + context.font = font; + context.textBaseline = 'middle'; + context.lineJoin = 'round'; + context.lineWidth = 3 * ratio; + context.strokeStyle = '#000'; + context.fillStyle = '#fff'; + context.strokeText(code, pad, canvas.height / 2); + context.fillText(code, pad, canvas.height / 2); + return { + image: canvas, + width: canvas.width / ratio, + height: canvas.height / ratio, + }; +} + +/** The initial bearing (degrees from north) of the great circle a → b. */ +function bearing(a, b) { + const rad = Math.PI / 180; + const y = Math.sin((b.lon - a.lon) * rad) * Math.cos(b.lat * rad); + const x = + Math.cos(a.lat * rad) * Math.sin(b.lat * rad) - + Math.sin(a.lat * rad) * + Math.cos(b.lat * rad) * + Math.cos((b.lon - a.lon) * rad); + return (Math.atan2(y, x) / rad + 360) % 360; +} + +const geodesic = (a, b) => + new Cesium.EllipsoidGeodesic( + Cesium.Cartographic.fromDegrees(a.lon, a.lat), + Cesium.Cartographic.fromDegrees(b.lon, b.lat), + ); + +/** Points along the great circle from a to b, as far as `upTo` (0 to 1). */ +function arc(a, b, steps = 64, upTo = 1) { + const line = geodesic(a, b); + const out = []; + const n = Math.max(2, Math.round(steps * upTo)); + for (let i = 0; i <= n; i++) { + const c = line.interpolateUsingFraction((i / n) * upTo); + out.push( + Cesium.Cartesian3.fromRadians(c.longitude, c.latitude, ROUTE_HEIGHT_M), + ); + } + return out; +} + +/** + * The point on the great circle from `from` to `to` nearest the craft. The + * craft is drawn there and the route split there, so the path stays one + * smooth arc: a craft a little off the direct line (vectors, airways, a + * detour) would otherwise bend it into a sharp corner. + */ +function onRoute(from, to, at) { + if (!at || !Number.isFinite(at.lat) || !Number.isFinite(at.lon)) return null; + const route = geodesic(from, to); + const here = Cesium.Cartesian3.fromDegrees(at.lon, at.lat); + const point = new Cesium.Cartesian3(); + let best = null; + let bestDistance = Infinity; + const STEPS = 200; + for (let i = 0; i <= STEPS; i++) { + const c = route.interpolateUsingFraction(i / STEPS); + Cesium.Cartesian3.fromRadians( + c.longitude, + c.latitude, + 0, + Cesium.Ellipsoid.WGS84, + point, + ); + const d = Cesium.Cartesian3.distanceSquared(here, point); + if (d < bestDistance) { + bestDistance = d; + best = { + lat: Cesium.Math.toDegrees(c.latitude), + lon: Cesium.Math.toDegrees(c.longitude), + }; + } + } + return best; +} + +/** + * The plane's billboard pose, nose along `deg` from north: the icon's up is + * tied to the local north on the globe and turned from there, so it points + * the right way in this tilted view too. + */ +function planePose(at, deg) { + const position = Cesium.Cartesian3.fromDegrees( + at.lon, + at.lat, + ROUTE_HEIGHT_M, + ); + const frame = Cesium.Transforms.eastNorthUpToFixedFrame(position); + const north = Cesium.Matrix4.getColumn(frame, 1, new Cesium.Cartesian4()); + return { + position, + rotation: -Cesium.Math.toRadians(deg), + alignedAxis: new Cesium.Cartesian3(north.x, north.y, north.z), + }; +} + +/** + * A flight's route on a small globe: the great circle from origin to + * destination, solid where it has flown and dashed ahead, the two airports + * marked with their codes, and a plane where the craft is now, pointing at + * the destination. On opening, the flown part draws out from the origin to + * the craft. The globe uses Cesium's bundled Natural Earth image, so it + * fetches no map tiles. It holds still, north up and framed on the route. + * @param {HTMLElement} container + * @param {{from: {code?: string, lat: number, lon: number}, + * to: {code?: string, lat: number, lon: number}, + * at?: {lat: number, lon: number}|null}} route + * @param {{onFailed?: () => void}} [events] + */ +function routePreview(container, route, { onFailed = () => {} } = {}) { + let widget = null; + let loop = null; + let { from, to } = route; + let plane = null; + let flownLine = null; + let aheadLine = null; + let removeGrow = null; + /** True while the plane flies in from the origin; moves wait for it. */ + let flyingIn = false; + + const pose = (entity, where) => { + const next = planePose(where, bearing(where, to)); + entity.position = next.position; + entity.billboard.rotation = next.rotation; + entity.billboard.alignedAxis = next.alignedAxis; + }; + + const draw = (atNow) => { + if (!widget) return; + const at = onRoute(from, to, atNow); + const { entities, scene } = widget; + removeGrow?.(); + removeGrow = null; + entities.removeAll(); + plane = flownLine = null; + const pin = (place, color) => + entities.add({ + position: Cesium.Cartesian3.fromDegrees(place.lon, place.lat), + point: { + pixelSize: 7, + color, + outlineColor: Cesium.Color.BLACK.withAlpha(0.6), + outlineWidth: 1, + }, + ...(place.code + ? { + billboard: { + ...codeImage(place.code), + verticalOrigin: Cesium.VerticalOrigin.BOTTOM, + pixelOffset: new Cesium.Cartesian2(0, -6), + }, + } + : {}), + }); + pin(from, CYAN.withAlpha(0.9)); + pin(to, AMBER); + + // Ahead of the craft, dashed; behind it, solid, drawing out on open. + aheadLine = entities.add({ + polyline: { + positions: arc(at || from, to), + width: 1.5, + material: new Cesium.PolylineDashMaterialProperty({ + color: AMBER.withAlpha(0.8), + dashLength: 10, + }), + arcType: Cesium.ArcType.NONE, + }, + }); + if (at) { + let progress = 0; + const flown = (flownLine = entities.add({ + polyline: { + positions: new Cesium.CallbackProperty( + () => arc(from, at, 48, Math.max(0.02, progress)), + false, + ), + width: 2.5, + material: new Cesium.PolylineGlowMaterialProperty({ + color: CYAN, + glowPower: 0.25, + }), + arcType: Cesium.ArcType.NONE, + }, + })); + // The plane starts at the origin and flies out along the flown line + // as it draws, arriving where the craft is now. + const first = planePose(from, bearing(from, to)); + plane = entities.add({ + position: first.position, + billboard: { + image: PLANE_ICON, + width: 26, + height: 26, + rotation: first.rotation, + alignedAxis: first.alignedAxis, + }, + }); + const leg = geodesic(from, at); + const ease = (x) => 1 - (1 - x) ** 3; + // The fly-in waits until the globe has drawn (its imagery loads a + // moment after the card opens), at most 1.5 s, so it is seen from the + // start. Under reduced motion it is there at once. + let began = reducedMotion() ? -Infinity : null; + const opened = performance.now(); + flyingIn = true; + const grow = () => { + if (began === null) { + if (!scene.globe.tilesLoaded && performance.now() - opened < 1500) + return; + began = performance.now(); + } + const raw = Math.min(1, (performance.now() - began) / 1600); + progress = ease(raw); + const c = leg.interpolateUsingFraction(progress); + pose(plane, { + lat: Cesium.Math.toDegrees(c.latitude), + lon: Cesium.Math.toDegrees(c.longitude), + }); + if (raw >= 1) { + flyingIn = false; + flown.polyline.positions = arc(from, at, 48); + removeGrow?.(); + removeGrow = null; + } + }; + removeGrow = scene.preRender.addEventListener(grow); + } + + // Frame the whole route, north up, looking down at a slight tilt; the + // view holds still so the plane and labels keep their bearings. + const points = [from, to, ...(at ? [at] : [])].map((p) => + Cesium.Cartesian3.fromDegrees(p.lon, p.lat), + ); + const sphere = Cesium.BoundingSphere.fromPoints(points); + const range = Math.max(1_800_000, sphere.radius * 3.2); + const center = + Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(sphere.center) || + sphere.center; + widget.camera.lookAt( + center, + new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-62), range), + ); + scene.requestRender(); + }; + + try { + widget = createWidget(container, { + baseLayer: false, + skyAtmosphere: false, + contextOptions: { webgl: { alpha: true, antialias: true } }, + }); + const { scene } = widget; + scene.backgroundColor = Cesium.Color.TRANSPARENT; + scene.globe.baseColor = Cesium.Color.fromCssColorString('#0b1820'); + scene.globe.showGroundAtmosphere = false; + scene.globe.enableLighting = false; + loop = renderLoopSwitch(widget); + } catch { + onFailed(); + return { setActive() {}, update() {}, destroy() {} }; + } + Cesium.TileMapServiceImageryProvider.fromUrl( + Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII'), + ).then( + (imagery) => { + if (!widget) return; + const layer = widget.scene.imageryLayers.addImageryProvider(imagery); + // Dimmed and cooled, so the route reads over it. + layer.brightness = 0.55; + layer.saturation = 0.35; + layer.contrast = 1.1; + draw(route.at); + }, + () => widget && onFailed(), + ); + + return { + setActive: (active) => loop.set(active), + /** + * A new route redraws; the craft moving along it only moves its plane + * and the two lines, without replaying the opening draw. + */ + update(next) { + if (!widget) return; + if (next.from?.code !== from.code || next.to?.code !== to.code) { + ({ from, to } = next); + draw(next.at); + return; + } + const at = onRoute(from, to, next.at); + if (!at || !plane || flyingIn) return; + pose(plane, at); + if (flownLine) flownLine.polyline.positions = arc(from, at, 48); + if (aheadLine) aheadLine.polyline.positions = arc(at, to); + widget.scene.requestRender(); + }, + destroy() { + removeGrow?.(); + removeGrow = null; + const gone = widget; + widget = null; + destroyWidget(gone); + }, + }; +} + +// ── The cockpit view ─────────────────────────────────────────────────── + +/** A floor for the eye, so a landed or taxiing craft is not underground. */ +const MIN_EYE_M = 60; + +/** + * What the crew sees: the view ahead from the aircraft's own position, + * height and heading, a little nose down, over Esri World Imagery (the + * app's keyless basemap) on a plain ellipsoid with the sky's haze. It draws + * only when asked: a still, moved along with the craft while it shows. + * @param {HTMLElement} container + * @param {{lat: number, lon: number, altitudeM?: number|null, + * heading?: number|null}} craft + * @param {{onFailed?: () => void}} [events] + */ +function cockpitPreview(container, craft, { onFailed = () => {} } = {}) { + let widget = null; + let active = false; + let at = craft; + const place = () => { + if (!widget || !Number.isFinite(at?.lat) || !Number.isFinite(at?.lon)) + return; + const height = Math.max( + MIN_EYE_M, + Number.isFinite(at.altitudeM) ? at.altitudeM : 0, + ); + widget.camera.setView({ + destination: Cesium.Cartesian3.fromDegrees(at.lon, at.lat, height), + orientation: { + heading: Cesium.Math.toRadians( + Number.isFinite(at.heading) ? at.heading : 0, + ), + pitch: Cesium.Math.toRadians(-9), + roll: 0, + }, + }); + widget.scene.requestRender(); + }; + try { + widget = createWidget(container, { + baseLayer: false, + requestRenderMode: true, + maximumRenderTimeChange: Infinity, + contextOptions: { webgl: { alpha: false, antialias: true } }, + }); + const { scene } = widget; + scene.globe.baseColor = Cesium.Color.fromCssColorString('#0b1820'); + scene.globe.showGroundAtmosphere = true; + scene.fog.enabled = true; + scene.camera.frustum.fov = Cesium.Math.toRadians(70); + // Tiles arriving ask for a frame, so the still fills in as they load. + scene.globe.tileLoadProgressEvent.addEventListener(() => + scene.requestRender(), + ); + place(); + } catch { + onFailed(); + return { setActive() {}, update() {}, destroy() {} }; + } + createEsriImagery().then( + (imagery) => { + if (!widget) return; + widget.scene.imageryLayers.addImageryProvider(imagery); + widget.scene.requestRender(); + }, + () => widget && onFailed(), + ); + return { + setActive(next) { + active = Boolean(next); + if (active) place(); + }, + /** While it shows, the view keeps up with the craft. */ + update(next) { + at = next; + if (active) place(); + }, + destroy() { + const gone = widget; + widget = null; + destroyWidget(gone); + }, + }; +} + +/** + * The card previews, as the `cardPreviews` application hook hands them. + * @type {Readonly<{model: typeof modelPreview, route: typeof routePreview, + * cockpit: typeof cockpitPreview}>} + */ +export const cesiumCardPreviews = Object.freeze({ + model: modelPreview, + route: routePreview, + cockpit: cockpitPreview, +}); diff --git a/src/render/cesium/mapImagery.js b/src/render/cesium/mapImagery.js index bd07a4ea4..217606b09 100644 --- a/src/render/cesium/mapImagery.js +++ b/src/render/cesium/mapImagery.js @@ -4,6 +4,7 @@ * World Imagery and Cesium ion's world imagery (Bing over HTTPS). */ import * as Cesium from 'cesium'; +import { ESRI_IMAGERY_CREDIT } from '../../maps/attribution.js'; export { ESRI_ATTRIBUTION_HTML } from '../../maps/attribution.js'; @@ -18,8 +19,7 @@ export function createEsriImagery() { return Cesium.ArcGisMapServerImageryProvider.fromUrl( 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer', { - credit: - 'Powered by Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community', + credit: ESRI_IMAGERY_CREDIT, enablePickFeatures: false, }, ); diff --git a/src/render/contract/renderer.d.ts b/src/render/contract/renderer.d.ts index a8ce9f499..5d8da3c44 100644 --- a/src/render/contract/renderer.d.ts +++ b/src/render/contract/renderer.d.ts @@ -67,6 +67,75 @@ export interface ApplicationHooks { allowReload: boolean; store: RenderFailureStore; }): () => void; + /** The Context card's previews of a picked aircraft. */ + cardPreviews?: CardPreviews; +} + +/** + * Previews the Context card draws into an element of its own. Each returns + * at once; one that cannot be made calls its `onFailed`. + */ +export interface CardPreviews { + /** + * A model turning on its own, from its GLB's bytes, starting to face + * `heading` (degrees); `viewRange` is the camera's distance in bounding + * radii. `onPhase` says when it turns to wire for its scan and back; + * `onCycle` when a look and its scan end, with the drawing time they took. + */ + model( + container: HTMLElement, + model: { + gltf: Uint8Array | ArrayBuffer; + basePath?: string; + heading?: number; + viewRange?: number; + }, + events?: { + onPhase?(phase: 'plain' | 'scan'): void; + onCycle?(ms: number): void; + onFailed?(): void; + }, + ): CardPreview; + /** A flight's route from `from` to `to` on a small globe, the craft `at`. */ + route( + container: HTMLElement, + route: CardRoute, + events?: { onFailed?(): void }, + ): CardPreview; + /** The view ahead from an aircraft's position, height and heading. */ + cockpit( + container: HTMLElement, + craft: CardCraft, + events?: { onFailed?(): void }, + ): CardPreview; +} + +/** A place on a card's route: an airport's code and position, degrees. */ +export interface CardPlace { + code?: string; + lat: number; + lon: number; +} + +export interface CardRoute { + from: CardPlace; + to: CardPlace; + at?: { lat: number; lon: number } | null; +} + +/** An aircraft's position (degrees), height (metres) and heading (degrees). */ +export interface CardCraft { + lat: number; + lon: number; + altitudeM?: number | null; + heading?: number | null; +} + +/** One preview: hidden, it rests on its last frame. */ +export interface CardPreview { + setActive(active: boolean): void; + update(values: Values): void; + destroy(): void; } /** Where a renderer's failure notice is published for the application to show. */ diff --git a/src/stories/thumbs.js b/src/stories/thumbs.js index a024c4989..5c79fe3d7 100644 --- a/src/stories/thumbs.js +++ b/src/stories/thumbs.js @@ -4,7 +4,7 @@ * the same tiles, from the same host, that GEV's Esri map draws (and credits * on screen); no other host is asked. */ -import { ESRI_TILES } from '../maps/globeEngine.js'; +import { ESRI_TILES } from '../maps/attribution.js'; const WIDTH = 320; const HEIGHT = 180; diff --git a/src/ui/entityContextBridge.js b/src/ui/entityContextBridge.js index 6bfa6b24f..eea7e72c2 100644 --- a/src/ui/entityContextBridge.js +++ b/src/ui/entityContextBridge.js @@ -6,7 +6,8 @@ import { isTrackingClickGesture, isTrackingSelectionGesture, } from '../data/trackingClickGesture.js'; -import { findCamera } from '../render/rendererOf.js'; +import { applicationHooksOf } from '../render/applicationHooks.js'; +import { findCamera, rendererOf } from '../render/rendererOf.js'; import { useCockpitStore } from './stores/cockpit.js'; import { useEntityCardStore } from './stores/entityCard.js'; import { useOmnibarStore } from './stores/omnibar.js'; @@ -200,6 +201,8 @@ export function installEntityContext({ letGo, isOpen, regionalBrief, + // The renderer's card previews, when it has them. + previews: () => applicationHooksOf(rendererOf(viewer)).cardPreviews ?? null, ask, askText, cockpit, diff --git a/src/ui/previewWidget.js b/src/ui/previewWidget.js deleted file mode 100644 index 58d57fe16..000000000 --- a/src/ui/previewWidget.js +++ /dev/null @@ -1,30 +0,0 @@ -// The card previews (the turning model, the route globe) each draw in a -// small Cesium scene of their own, so each holds a WebGL context. A browser -// keeps only a handful of those open, and when there are too many it drops -// the oldest, which is the main globe's. A destroyed widget's context is -// otherwise freed only when garbage is collected, so flicking through cards -// can push the globe's context out. Losing a preview's context on purpose as -// it closes frees it at once. - -/** - * Destroy a preview's Cesium widget and free its WebGL context. - * @param {object|null} widget a Cesium CesiumWidget - */ -export function destroyPreviewWidget(widget) { - if (!widget || widget.isDestroyed?.()) return; - let gl = null; - try { - gl = - widget.scene?.context?._gl ?? - widget.canvas?.getContext?.('webgl2') ?? - null; - } catch { - gl = null; - } - widget.destroy(); - try { - gl?.getExtension?.('WEBGL_lose_context')?.loseContext(); - } catch { - // Nothing more can be done; the context goes when it is collected. - } -} diff --git a/src/ui/stores/entityCard.js b/src/ui/stores/entityCard.js index fa8a148ec..611065ac2 100644 --- a/src/ui/stores/entityCard.js +++ b/src/ui/stores/entityCard.js @@ -304,6 +304,8 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => { ? shell.value.regionalBrief(lat, lon) : Promise.resolve(null); const canFollow = () => Boolean(shell.value?.canFollow?.(card.value)); + /** The renderer's card previews (`CardPreviews`), or null without them. */ + const previews = () => shell.value?.previews?.() ?? null; /** Loaded items whose name or id matches typed text, for the omnibar. */ const search = (query, options) => shell.value @@ -325,6 +327,7 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => { follow, ask, readBrief, + previews, canFollow, isFollowing, following, diff --git a/src/ui/styles/entity-card.css b/src/ui/styles/entity-card.css index 3603932a2..640c0670f 100644 --- a/src/ui/styles/entity-card.css +++ b/src/ui/styles/entity-card.css @@ -2187,7 +2187,7 @@ border-radius: 3px; } -.entity-hero:is([data-hero='flight'], [data-hero='satellite']) { +.entity-hero:is([data-hero='flight'], [data-hero='satellite'], [data-hero='photo']) { height: 168px; background: radial-gradient( ellipse 55% 60% at 50% 55%, diff --git a/src/ui/views/ContextView.vue b/src/ui/views/ContextView.vue index 9ff07fb3a..461774c22 100644 --- a/src/ui/views/ContextView.vue +++ b/src/ui/views/ContextView.vue @@ -248,7 +248,7 @@ watch(
- + diff --git a/src/ui/views/panels/AircraftModelHero.vue b/src/ui/views/panels/AircraftModelHero.vue index 8ad53ef25..d3fb78bce 100644 --- a/src/ui/views/panels/AircraftModelHero.vue +++ b/src/ui/views/panels/AircraftModelHero.vue @@ -1,26 +1,16 @@ @@ -267,7 +113,7 @@ onBeforeUnmount(() => { -
+
{{ shown.label }}{{ pad(shown.index + 1) }} / {{ pad(shown.total) }} {{ shown.value }} diff --git a/src/ui/views/panels/EntityCard.vue b/src/ui/views/panels/EntityCard.vue index 3bca36f40..c81f42b26 100644 --- a/src/ui/views/panels/EntityCard.vue +++ b/src/ui/views/panels/EntityCard.vue @@ -21,8 +21,6 @@ import { countryName, nearestCity } from '../../../data/wikidataCities.js'; const props = defineProps({ /** Contacts follows this same aircraft, and its list sits inside the card. */ withContacts: Boolean, - /** The aircraft's photo from Contacts (`{src, link, credit}`), when it has one. */ - aircraftPhoto: { type: Object, default: null }, }); const store = useEntityCardStore(); const { card, lost, tick } = storeToRefs(store); @@ -203,9 +201,10 @@ watch( { immediate: true }, ); -// The hero tile at the top of every card. A flight shows its photo (from -// Contacts), its route on a small globe, its 3D model and the view from its -// cockpit; a satellite, the ground beneath it; a camera, its latest frame. +// The hero tile at the top of every card. A flight shows its photo, its route +// on a small globe, its 3D model and the view from its cockpit; a vessel, its +// photo; a satellite, the ground beneath it; a camera, its latest frame. +// The globe, model and cockpit view are the renderer's (`store.previews()`). // Anything else gets a quiet placeholder with its icon and its headline // figures until it has imagery of its own. Previews stay mounted so switching // shows the next one at once. @@ -214,10 +213,26 @@ const modelFailed = ref(false); const cockpitFailed = ref(false); const hasPosition = computed(() => Number.isFinite(card.value?.lat) && Number.isFinite(card.value?.lon)); const cockpitKnown = computed(() => card.value?.kind === 'aircraft' && hasPosition.value && !cockpitFailed.value); -const modelKnown = computed(() => Boolean(card.value?.aircraftClass) && !modelFailed.value); +const modelKnown = computed(() => Boolean(card.value?.aircraftModel) && !modelFailed.value); const preview = ref(null); +// The photo the item's layer looked up (Planespotters for a tracked +// airliner, Open Vessel Photos for a selected vessel), with its credit. const failedPhoto = ref(''); -const photoAvailable = computed(() => Boolean(props.aircraftPhoto?.src && props.aircraftPhoto.src !== failedPhoto.value)); +const photo = computed(() => { + const found = card.value?.photo; + if (!found?.src || found.src === failedPhoto.value) return null; + const { photographer, licence } = found; + const credit = licence + ? photographer + ? t('Photo: {photographer} · {licence}', { photographer, licence }) + : t('Photo · {licence}', { licence }) + : photographer + ? t('Photo © {photographer}', { photographer }) + : ''; + return { ...found, credit }; +}); +const photoAvailable = computed(() => Boolean(photo.value)); +const onPhotoError = (event) => (failedPhoto.value = event.currentTarget.getAttribute('src')); watch(() => props.withContacts, () => (preview.value = null)); // The model and the cockpit view take turns: after each of the model's // cycles, the view ahead from the cockpit shows for as long as that cycle @@ -250,7 +265,8 @@ function showOtherView(ms) { } const heroKind = computed(() => { - if (photoAvailable.value || routeKnown.value || modelKnown.value) return 'flight'; + if (card.value?.kind === 'aircraft' && (photoAvailable.value || routeKnown.value || modelKnown.value)) return 'flight'; + if (card.value?.kind === 'vessel' && photoAvailable.value) return 'photo'; if (card.value?.layerId === 'satellites' && hasPosition.value) return 'satellite'; if (card.value?.layerId === 'cctv') return 'camera'; return 'none'; @@ -332,18 +348,18 @@ watch( + + + {{ photo.credit }} + diff --git a/src/ui/views/panels/FlightCockpitView.vue b/src/ui/views/panels/FlightCockpitView.vue index 4cba68e5f..675437f5a 100644 --- a/src/ui/views/panels/FlightCockpitView.vue +++ b/src/ui/views/panels/FlightCockpitView.vue @@ -1,19 +1,17 @@