mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
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]>
This commit is contained in:
1 parent
c6bdd38b61
commit
3a0842c103
26 files changed
+1347
-676
No files matched your search
@@ -1,19 +1,17 @@
|
||||
<script setup>
|
||||
import * as Cesium from 'cesium';
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { t } from '../../../i18n/index.js';
|
||||
import { ESRI_IMAGERY_CREDIT, createEsriImagery } from '../../../maps/imagery.js';
|
||||
import { destroyPreviewWidget } from '../../previewWidget.js';
|
||||
import { formatNumber, t } from '../../../i18n/index.js';
|
||||
import { ESRI_IMAGERY_CREDIT } from '../../../maps/attribution.js';
|
||||
import { useEntityCardStore } from '../../stores/entityCard.js';
|
||||
import PreviewHud from './PreviewHud.vue';
|
||||
|
||||
// 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 takes
|
||||
// turns with the turning model, as a satellite's ground view does. It draws
|
||||
// only when asked (a still, moved along with the craft while it shows) and
|
||||
// holds still while hidden. Its credit line sits in the corner. Speed and
|
||||
// altitude ride on tapes either side, as on a head-up display: the ticks
|
||||
// roll as the figures change, with the figure boxed in the middle.
|
||||
// height and heading, a little nose down, over Esri World Imagery. The
|
||||
// renderer draws it (the `cardPreviews` hook) only when asked: a still,
|
||||
// moved along with the craft while it shows. It takes turns with the turning
|
||||
// model. Speed and altitude ride on tapes either side, as on a head-up
|
||||
// display: the ticks roll as the figures change, with the figure boxed in
|
||||
// the middle. Its credit line sits in the corner.
|
||||
const props = defineProps({
|
||||
lat: { type: Number, default: null },
|
||||
lon: { type: Number, default: null },
|
||||
@@ -27,77 +25,41 @@ const props = defineProps({
|
||||
active: { type: Boolean, default: false },
|
||||
});
|
||||
const emit = defineEmits(['failed']);
|
||||
const store = useEntityCardStore();
|
||||
|
||||
const host = ref(null);
|
||||
let widget = null;
|
||||
let preview = null;
|
||||
const craft = () => ({ lat: props.lat, lon: props.lon, altitudeM: props.altitudeM, heading: props.heading });
|
||||
|
||||
/** A ground floor for the eye, so a landed or taxiing craft is not underground. */
|
||||
const MIN_EYE_M = 60;
|
||||
|
||||
function place() {
|
||||
if (!widget || !Number.isFinite(props.lat) || !Number.isFinite(props.lon)) return;
|
||||
const height = Math.max(MIN_EYE_M, Number.isFinite(props.altitudeM) ? props.altitudeM : 0);
|
||||
widget.camera.setView({
|
||||
destination: Cesium.Cartesian3.fromDegrees(props.lon, props.lat, height),
|
||||
orientation: {
|
||||
heading: Cesium.Math.toRadians(Number.isFinite(props.heading) ? props.heading : 0),
|
||||
pitch: Cesium.Math.toRadians(-9),
|
||||
roll: 0,
|
||||
},
|
||||
});
|
||||
widget.scene.requestRender();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
widget = new Cesium.CesiumWidget(host.value, {
|
||||
baseLayer: false,
|
||||
skyBox: false,
|
||||
scene3DOnly: true,
|
||||
shadows: false,
|
||||
requestRenderMode: true,
|
||||
maximumRenderTimeChange: Infinity,
|
||||
showRenderLoopErrors: false,
|
||||
contextOptions: { webgl: { alpha: false, antialias: true } },
|
||||
creditContainer: document.createElement('div'),
|
||||
});
|
||||
const scene = widget.scene;
|
||||
scene.screenSpaceCameraController.enableInputs = false;
|
||||
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();
|
||||
const imagery = await createEsriImagery();
|
||||
if (!widget) return;
|
||||
scene.imageryLayers.addImageryProvider(imagery);
|
||||
scene.requestRender();
|
||||
} catch {
|
||||
onMounted(() => {
|
||||
const previews = store.previews();
|
||||
if (!previews?.cockpit || !host.value) {
|
||||
emit('failed');
|
||||
return;
|
||||
}
|
||||
preview = previews.cockpit(host.value, craft(), { onFailed: () => emit('failed') });
|
||||
preview.setActive(props.active);
|
||||
});
|
||||
|
||||
// While it shows, the view keeps up with the craft as the card refreshes.
|
||||
watch(
|
||||
() => [props.active, props.lat, props.lon, props.altitudeM, props.heading],
|
||||
() => props.active && place(),
|
||||
() => [props.lat, props.lon, props.altitudeM, props.heading],
|
||||
() => preview?.update(craft()),
|
||||
);
|
||||
watch(
|
||||
() => props.active,
|
||||
(active) => preview?.setActive(active),
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
destroyPreviewWidget(widget);
|
||||
widget = null;
|
||||
preview?.destroy();
|
||||
preview = null;
|
||||
});
|
||||
|
||||
const feet = computed(() =>
|
||||
Number.isFinite(props.altitudeM) ? `${(Math.round((props.altitudeM * 3.28084) / 100) * 100).toLocaleString('en-US')} ft` : '',
|
||||
);
|
||||
// The tapes: one tick every 10 kt and every 100 ft, 8 px apart; the ticks
|
||||
// roll by the remainder, so a change in the figure moves them.
|
||||
const TICK_PX = 8;
|
||||
const knots = computed(() => (Number.isFinite(props.speedMps) ? Math.round(props.speedMps * 1.94384) : null));
|
||||
const altFeet = computed(() => (Number.isFinite(props.altitudeM) ? Math.round(props.altitudeM * 3.28084) : null));
|
||||
const feet = computed(() => (altFeet.value === null ? '' : t('{n} ft', { n: formatNumber(Math.round(altFeet.value / 100) * 100) })));
|
||||
const roll = (value, per) => (value === null ? 0 : ((value % per) / per) * TICK_PX);
|
||||
const speedRoll = computed(() => `${roll(knots.value, 10)}px`);
|
||||
const altRoll = computed(() => `${roll(altFeet.value, 100)}px`);
|
||||
@@ -111,11 +73,11 @@ const course = computed(() => (Number.isFinite(props.heading) ? `${String(Math.r
|
||||
<span class="flight-cockpit__horizon"><i></i></span>
|
||||
<span v-if="knots !== null" class="flight-cockpit__tape flight-cockpit__tape--speed">
|
||||
<i class="flight-cockpit__ticks" :style="{ backgroundPositionY: speedRoll }"></i>
|
||||
<b>{{ knots }}</b><em>{{ t('KT') }}</em>
|
||||
<b>{{ formatNumber(knots) }}</b><em>{{ t('KT') }}</em>
|
||||
</span>
|
||||
<span v-if="altFeet !== null" class="flight-cockpit__tape flight-cockpit__tape--alt">
|
||||
<i class="flight-cockpit__ticks" :style="{ backgroundPositionY: altRoll }"></i>
|
||||
<b>{{ altFeet.toLocaleString('en-US') }}</b><em>{{ t('FT') }}</em>
|
||||
<b>{{ formatNumber(altFeet) }}</b><em>{{ t('FT') }}</em>
|
||||
</span>
|
||||
<span class="flight-cockpit__label">{{ t('Cockpit view') }}<strong>{{ [feet, course].filter(Boolean).join(' · ') }}</strong></span>
|
||||
<span class="flight-cockpit__credit">{{ ESRI_IMAGERY_CREDIT }}</span>
|
||||
|
||||
Reference in new issue
Block a user