added timeline with satellite tracking

This commit is contained in:
Vasilisk9812 2025-12-11 23:30:32 +09:00
parent 60fe848b0c
commit eb7066ac6b
3 changed files with 491 additions and 28 deletions

View file

@ -13,6 +13,7 @@
let map: MapLibreMap; let map: MapLibreMap;
let mapContainer: HTMLDivElement; let mapContainer: HTMLDivElement;
let markers: Marker[] = []; let markers: Marker[] = [];
let animatedMarker: Marker | null = null;
let mouseLat = 0; let mouseLat = 0;
let mouseLng = 0; let mouseLng = 0;
let isSelecting = false; let isSelecting = false;
@ -102,6 +103,9 @@
markers.forEach((marker) => marker.remove()); markers.forEach((marker) => marker.remove());
markers = []; markers = [];
// Remove animated marker
removeAnimatedMarker();
// Remove all layers and sources related to flight paths // Remove all layers and sources related to flight paths
if (map && map.getLayer("flight-path")) { if (map && map.getLayer("flight-path")) {
map.removeLayer("flight-path"); map.removeLayer("flight-path");
@ -132,7 +136,23 @@
el.style.backgroundSize = "100%"; el.style.backgroundSize = "100%";
el.title = title; el.title = title;
const marker = new maplibregl.Marker({ element: el }).setLngLat([lng, lat]).addTo(map); // Create popup with coordinates
const popup = new maplibregl.Popup({ offset: 25, closeButton: false }).setHTML(
`<b>${title}</b><br>Lat: ${lat.toFixed(6)}<br>Lng: ${lng.toFixed(6)}`,
);
const marker = new maplibregl.Marker({ element: el })
.setLngLat([lng, lat])
.setPopup(popup)
.addTo(map);
// Show popup on hover
el.addEventListener("mouseenter", () => {
marker.togglePopup();
});
el.addEventListener("mouseleave", () => {
marker.togglePopup();
});
markers.push(marker); markers.push(marker);
return marker; return marker;
@ -147,7 +167,23 @@
el.style.backgroundSize = "100%"; el.style.backgroundSize = "100%";
el.title = title; el.title = title;
const marker = new maplibregl.Marker({ element: el }).setLngLat([lng, lat]).addTo(map); // Create popup with coordinates
const popup = new maplibregl.Popup({ offset: 25, closeButton: false }).setHTML(
`<b>${title}</b><br>Lat: ${lat.toFixed(6)}<br>Lng: ${lng.toFixed(6)}`,
);
const marker = new maplibregl.Marker({ element: el })
.setLngLat([lng, lat])
.setPopup(popup)
.addTo(map);
// Show popup on hover
el.addEventListener("mouseenter", () => {
marker.togglePopup();
});
el.addEventListener("mouseleave", () => {
marker.togglePopup();
});
markers.push(marker); markers.push(marker);
return marker; return marker;
@ -319,6 +355,39 @@
export const getMap = () => { export const getMap = () => {
return map; return map;
}; };
export const updateAnimatedMarker = (lat: number, lng: number) => {
if (!map) return;
if (!animatedMarker) {
// Create animated marker
const el = document.createElement("div");
el.className = "animated-marker";
el.innerHTML = `
<svg width="32" height="32" viewBox="0 0 32 32">
<circle cx="16" cy="16" r="14" fill="#FF6B6B" opacity="0.3" class="pulse-ring"/>
<circle cx="16" cy="16" r="8" fill="#FF1744" stroke="white" stroke-width="2"/>
</svg>
`;
animatedMarker = new maplibregl.Marker({ element: el, anchor: "center" })
.setLngLat([lng, lat])
.addTo(map);
} else {
// Update position
animatedMarker.setLngLat([lng, lat]);
}
// Pan to marker
map.panTo([lng, lat], { duration: 100 });
};
export const removeAnimatedMarker = () => {
if (animatedMarker) {
animatedMarker.remove();
animatedMarker = null;
}
};
</script> </script>
<div class="map-container" bind:this={mapContainer}> <div class="map-container" bind:this={mapContainer}>
@ -336,30 +405,24 @@
{/if} {/if}
</div> </div>
<!-- <style> <style>
.map-container { :global(.animated-marker) {
position: relative;
width: 100%;
height: 100%;
}
.coordinates-display {
position: absolute;
top: 10px;
right: 10px;
z-index: 1000;
padding: 8px 12px;
background: rgba(255, 255, 255, 0.9);
border-radius: 4px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.card-text {
margin: 0;
font-size: 12px;
}
:global(.custom-marker) {
cursor: pointer; cursor: pointer;
} }
</style> -->
:global(.animated-marker .pulse-ring) {
animation: pulse 2s ease-out infinite;
transform-origin: center;
}
@keyframes :global(pulse) {
0% {
r: 8;
opacity: 0.8;
}
100% {
r: 14;
opacity: 0;
}
}
</style>

View file

@ -0,0 +1,393 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import type { Prediction } from "$lib/types";
let { prediction }: { prediction: Prediction | null } = $props();
const dispatch = createEventDispatcher<{
timeUpdate: { index: number; lat: number; lng: number; alt: number; datetime: Date };
}>();
let isPlaying = $state(false);
let currentIndex = $state(0);
let playbackSpeed = $state(1);
let animationFrame: number | null = null;
let lastUpdateTime = 0;
$effect(() => {
if (prediction && currentIndex >= flightPathLength) {
currentIndex = 0;
}
});
const flightPathLength = $derived(prediction?.flight_path?.length || 0);
const progress = $derived(flightPathLength > 0 ? (currentIndex / flightPathLength) * 100 : 0);
const currentPosition = $derived.by(() => {
if (!prediction || !prediction.flight_path[currentIndex]) return null;
const point = prediction.flight_path[currentIndex];
let lat: number, lng: number, alt: number;
if (Array.isArray(point)) {
lat = point[0];
lng = point[1];
alt = point[2] || 0;
} else {
lat = point.lat;
lng = point.lng;
alt = point.alt || 0;
}
const totalTime = prediction.flight_time;
const timeProgress = (currentIndex / flightPathLength) * totalTime;
const launchTime = prediction.launch.datetime instanceof Date
? prediction.launch.datetime.getTime()
: new Date(prediction.launch.datetime).getTime();
const datetime = new Date(launchTime + timeProgress * 1000);
return { lat, lng, alt, datetime };
});
const timeElapsed = $derived.by(() => {
if (!prediction || !currentPosition) return "00:00:00";
const launchTime = prediction.launch.datetime instanceof Date
? prediction.launch.datetime.getTime()
: new Date(prediction.launch.datetime).getTime();
const totalSeconds = Math.floor(
(currentPosition.datetime.getTime() - launchTime) / 1000,
);
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
return `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
});
function animate(timestamp: number) {
if (!isPlaying) return;
if (!lastUpdateTime) lastUpdateTime = timestamp;
const deltaTime = timestamp - lastUpdateTime;
if (deltaTime >= 50 / playbackSpeed) {
if (currentIndex < flightPathLength - 1) {
currentIndex++;
if (currentPosition) {
dispatch("timeUpdate", { ...currentPosition, index: currentIndex });
}
} else {
stop();
}
lastUpdateTime = timestamp;
}
animationFrame = requestAnimationFrame(animate);
}
function play() {
if (!prediction) return;
if (currentIndex >= flightPathLength - 1) {
currentIndex = 0;
}
isPlaying = true;
lastUpdateTime = 0;
animationFrame = requestAnimationFrame(animate);
}
function pause() {
isPlaying = false;
if (animationFrame !== null) {
cancelAnimationFrame(animationFrame);
animationFrame = null;
}
}
function stop() {
pause();
currentIndex = 0;
if (currentPosition) {
dispatch("timeUpdate", { ...currentPosition, index: currentIndex });
}
}
function handleSliderChange(event: Event) {
const target = event.target as HTMLInputElement;
currentIndex = parseInt(target.value);
if (currentPosition) {
dispatch("timeUpdate", { ...currentPosition, index: currentIndex });
}
}
function changeSpeed() {
const speeds = [1, 2, 5, 10];
const currentSpeedIndex = speeds.indexOf(playbackSpeed);
playbackSpeed = speeds[(currentSpeedIndex + 1) % speeds.length];
}
$effect(() => {
return () => {
if (animationFrame !== null) {
cancelAnimationFrame(animationFrame);
}
};
});
</script>
<div class="timeline-container">
<div class="timeline-info">
<div class="info-section">
<span class="label">Time:</span>
<span class="value">{timeElapsed}</span>
</div>
{#if currentPosition}
<div class="info-section">
<span class="label">Altitude:</span>
<span class="value">{Math.round(currentPosition.alt)} m</span>
</div>
<div class="info-section">
<span class="label">Position:</span>
<span class="value"
>{currentPosition.lat.toFixed(4)}, {currentPosition.lng.toFixed(4)}</span
>
</div>
{/if}
</div>
<div class="timeline-controls">
<div class="control-buttons">
<button
class="control-btn"
on:click={stop}
disabled={!prediction || currentIndex === 0}
title="Start"
>
<i class="bi bi-skip-start-fill"></i>
</button>
{#if !isPlaying}
<button class="control-btn play-btn" on:click={play} disabled={!prediction} title="Play">
<i class="bi bi-play-fill"></i>
</button>
{:else}
<button class="control-btn" on:click={pause} title="Pause">
<i class="bi bi-pause-fill"></i>
</button>
{/if}
<button
class="control-btn speed-btn"
on:click={changeSpeed}
disabled={!prediction}
title="Speed"
>
{playbackSpeed}x
</button>
</div>
<div class="progress-container">
<input
type="range"
min="0"
max={flightPathLength - 1}
value={currentIndex}
on:input={handleSliderChange}
disabled={!prediction}
class="timeline-slider"
/>
<div class="progress-bar" style="width: {progress}%"></div>
</div>
</div>
</div>
<style>
.timeline-container {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(255, 255, 255, 0.95);
border-radius: 12px;
padding: 16px 20px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
min-width: 600px;
max-width: 800px;
z-index: 1000;
backdrop-filter: blur(10px);
}
.timeline-info {
display: flex;
justify-content: space-around;
margin-bottom: 12px;
gap: 16px;
}
.info-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
}
.label {
font-size: 11px;
color: #666;
text-transform: uppercase;
font-weight: 600;
letter-spacing: 0.5px;
}
.value {
font-size: 14px;
color: #000;
font-weight: 600;
font-family: monospace;
}
.timeline-controls {
display: flex;
align-items: center;
gap: 12px;
}
.control-buttons {
display: flex;
gap: 8px;
align-items: center;
}
.control-btn {
width: 40px;
height: 40px;
border: none;
border-radius: 50%;
background: #007bff;
color: white;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
transition: all 0.2s ease;
}
.control-btn:hover:not(:disabled) {
background: #0056b3;
transform: scale(1.1);
}
.control-btn:disabled {
background: #ccc;
cursor: not-allowed;
opacity: 0.5;
}
.play-btn {
width: 48px;
height: 48px;
font-size: 22px;
background: #28a745;
}
.play-btn:hover:not(:disabled) {
background: #218838;
}
.speed-btn {
border-radius: 8px;
width: 50px;
font-size: 12px;
font-weight: 700;
}
.progress-container {
flex: 1;
position: relative;
height: 40px;
display: flex;
align-items: center;
}
.timeline-slider {
width: 100%;
height: 6px;
border-radius: 3px;
outline: none;
background: #e0e0e0;
-webkit-appearance: none;
appearance: none;
cursor: pointer;
position: relative;
z-index: 2;
}
.timeline-slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: #007bff;
cursor: pointer;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.timeline-slider::-moz-range-thumb {
width: 18px;
height: 18px;
border-radius: 50%;
background: #007bff;
cursor: pointer;
border: none;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.timeline-slider:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.progress-bar {
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 6px;
background: linear-gradient(90deg, #007bff 0%, #0056b3 100%);
border-radius: 3px;
transition: width 0.05s linear;
pointer-events: none;
z-index: 1;
}
@media (max-width: 768px) {
.timeline-container {
min-width: 90%;
max-width: 90%;
padding: 12px 16px;
}
.timeline-info {
flex-direction: column;
gap: 8px;
margin-bottom: 8px;
}
.info-section {
flex-direction: row;
justify-content: space-between;
}
.control-btn {
width: 36px;
height: 36px;
font-size: 16px;
}
.play-btn {
width: 42px;
height: 42px;
font-size: 20px;
}
}
</style>

View file

@ -6,6 +6,7 @@
import ScenarioPanel from "$lib/components/ScenarioPanel.svelte"; import ScenarioPanel from "$lib/components/ScenarioPanel.svelte";
import TabComponent from "$lib/components/TabComponent.svelte"; import TabComponent from "$lib/components/TabComponent.svelte";
import PointEditor from "$lib/components/PointEditor.svelte"; import PointEditor from "$lib/components/PointEditor.svelte";
import TimeLine from "$lib/components/TimeLine.svelte";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { PredictionStore } from "$lib/stores"; import { PredictionStore } from "$lib/stores";
import { addToast, removeToast } from "$lib/components/Toast.svelte"; import { addToast, removeToast } from "$lib/components/Toast.svelte";
@ -69,7 +70,10 @@
} }
} }
function handleTimeUpdate(event: CustomEvent<{ index: number; lat: number; lng: number; alt: number; datetime: Date }>) {
const { lat, lng } = event.detail;
map?.updateAnimatedMarker(lat, lng);
}
</script> </script>
@ -101,5 +105,8 @@
</div> </div>
</PanelContainer> </PanelContainer>
<ToastContainer /> <ToastContainer />
{#if $PredictionStore}
<TimeLine prediction={$PredictionStore} on:timeUpdate={handleTimeUpdate} />
{/if}
</Map> </Map>
</main> </main>