Files
gods-eye-view/src/ui/views/panels/RouteGlobe.vue
T
Sameh KhamisandManjunath Paparaju 3a0842c103 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 <[email protected]>
2026-11-16 15:44:35 -08:00

90 lines
3.8 KiB
Vue

<script setup>
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { msg, t } from '../../../i18n/index.js';
import { useEntityCardStore } from '../../stores/entityCard.js';
// A flight's route on a small globe of its own at the top of its card: 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. The renderer draws it (the
// `cardPreviews` hook); this tile lays the compass over it. The card names
// the airports' cities under its progress bar.
const props = defineProps({
/** `{code, lat, lon}` of the origin airport. */
from: { type: Object, required: true },
/** `{code, lat, lon}` of the destination airport. */
to: { type: Object, required: true },
/** The craft's position now. */
at: { type: Object, default: null },
/** Whether the tile is the one showing; a hidden one stops drawing. */
active: { type: Boolean, default: true },
});
const store = useEntityCardStore();
const host = ref(null);
const failed = ref(false);
let preview = null;
const place = (p) => ({ code: p?.code || '', lat: Number(p?.lat), lon: Number(p?.lon) });
const at = () =>
props.at && Number.isFinite(props.at.lat) && Number.isFinite(props.at.lon) ? { lat: props.at.lat, lon: props.at.lon } : null;
const route = () => ({ from: place(props.from), to: place(props.to), at: at() });
/** 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;
}
// The compass: the view is north up, so N sits at the top; a cyan needle
// shows the course to the destination, with its bearing in degrees.
const course = computed(() => Math.round(bearing(at() || props.from, props.to)) % 360);
const POINTS = [msg('N'), msg('NE'), msg('E'), msg('SE'), msg('S'), msg('SW'), msg('W'), msg('NW')];
const courseLabel = computed(() => `${String(course.value).padStart(3, '0')}° ${t(POINTS[Math.round(course.value / 45) % 8])}`);
onMounted(() => {
const previews = store.previews();
if (!previews?.route || !host.value) {
failed.value = true;
return;
}
preview = previews.route(host.value, route(), { onFailed: () => (failed.value = true) });
preview.setActive(props.active);
});
// Watched as strings: a fresh object each card refresh would count as a
// change every two seconds.
watch(
() => `${props.from?.code}|${props.to?.code}|${props.at?.lat?.toFixed?.(4)}|${props.at?.lon?.toFixed?.(4)}`,
() => preview?.update(route()),
);
watch(
() => props.active,
(active) => preview?.setActive(active),
);
onBeforeUnmount(() => {
preview?.destroy();
preview = null;
});
</script>
<template>
<div v-if="!failed" class="route-globe">
<div ref="host" class="route-globe__scene" aria-hidden="true"></div>
<div class="route-globe__compass" :title="t('Course to {code}: {course}', { code: to.code, course: courseLabel })">
<svg viewBox="-24 -24 48 48" aria-hidden="true">
<circle r="19" class="route-globe__compass-ring" />
<g class="route-globe__compass-ticks">
<line v-for="deg in [0, 45, 90, 135, 180, 225, 270, 315]" :key="deg" :transform="`rotate(${deg})`" y1="-19" :y2="deg % 90 ? -16.5 : -15" />
</g>
<text y="-9.5" class="route-globe__compass-n">{{ t('N') }}</text>
<g :transform="`rotate(${course})`" class="route-globe__compass-needle">
<path d="M0 -14 L3 2 L0 0 L-3 2 Z" />
</g>
<circle r="1.6" class="route-globe__compass-hub" />
</svg>
<span>{{ courseLabel }}</span>
</div>
</div>
</template>