added tracking feature(not tested)

This commit is contained in:
Vasilisk9812 2026-05-23 13:04:06 +09:00
parent 7a2278a42e
commit ea61e157ab
8 changed files with 309 additions and 25 deletions

View file

@ -1,20 +1,78 @@
<script lang="ts">
import { onMount } from 'svelte';
import { Map as MapView } from '$map';
import { onMount, onDestroy } from 'svelte';
import { Map as MapView, plotAnimatedMarker, type IMap } from '$map';
import { Navbar } from '$features/auth';
import { PanelContainer } from '$ui';
import { TelemetryPanel } from '$features/tracking';
import { TelemetryPanel, telemetryStore } from '$features/tracking';
import { requireAuthenticated } from '$auth';
import { parseTelemetry } from '$domain';
let map = $state<IMap | null>(null);
// Tracks whether we've already fitted the map to the initial history load.
// Not reactive — written as a side effect inside $effect to avoid re-triggering.
let fittedBounds = false;
onMount(() => {
requireAuthenticated('/login');
});
onDestroy(() => {
map?.disposeScene('telemetry');
});
function onMapReady(m: IMap) {
map = m;
}
$effect(() => {
if (!map) return;
const points = telemetryStore.points;
const scene = map.scene('telemetry');
if (points.length === 0) {
scene.clear();
fittedBounds = false;
return;
}
let telemetry;
try {
telemetry = parseTelemetry(points);
} catch {
return;
}
const latest = points[points.length - 1];
scene.clear();
scene.addLine('path', {
coords: telemetry.flight_path,
color: '#FF1744',
width: 3,
});
scene.addMarker('launch', {
lngLat: [telemetry.launch.latlng.lng, telemetry.launch.latlng.lat],
iconUrl: '/target-blue.png',
iconSize: [12, 12],
popupHtml: `<b>Launch</b><br>${telemetry.launch.latlng.lat.toFixed(6)}, ${telemetry.launch.latlng.lng.toFixed(6)}`,
});
plotAnimatedMarker(scene, latest.longitude, latest.latitude);
if (!fittedBounds && telemetry.flight_path.length > 0) {
map.fitBounds(telemetry.flight_path, 50);
fittedBounds = true;
}
});
</script>
<main>
<Navbar />
<div style="height: var(--navbar-height);"></div>
<MapView>
<MapView {onMapReady}>
<PanelContainer position="left">
<TelemetryPanel />
</PanelContainer>