2024-07-12 15:00:33 +02:00
|
|
|
<script lang="ts">
|
2025-10-05 19:34:05 +02:00
|
|
|
// import GPXLayers from '$lib/components/map/gpx-layer/GPXLayers.svelte';
|
|
|
|
|
// import ElevationProfile from '$lib/components/ElevationProfile.svelte';
|
|
|
|
|
// import FileList from '$lib/components/file-list/FileList.svelte';
|
|
|
|
|
// import GPXStatistics from '$lib/components/GPXStatistics.svelte';
|
2025-06-21 21:07:36 +02:00
|
|
|
import Map from '$lib/components/map/Map.svelte';
|
2025-10-05 19:34:05 +02:00
|
|
|
import { map } from '$lib/components/map/utils.svelte';
|
|
|
|
|
// import LayerControl from '$lib/components/map/layer-control/LayerControl.svelte';
|
2025-02-02 11:17:22 +01:00
|
|
|
import OpenIn from '$lib/components/embedding/OpenIn.svelte';
|
|
|
|
|
import {
|
|
|
|
|
gpxStatistics,
|
|
|
|
|
slicedGPXStatistics,
|
|
|
|
|
embedding,
|
|
|
|
|
loadFile,
|
|
|
|
|
updateGPXData,
|
|
|
|
|
} from '$lib/stores';
|
2025-10-05 19:34:05 +02:00
|
|
|
import { onDestroy, onMount, setContext } from 'svelte';
|
2025-02-02 11:17:22 +01:00
|
|
|
import { readable } from 'svelte/store';
|
|
|
|
|
import type { GPXFile } from 'gpx';
|
2025-10-05 19:34:05 +02:00
|
|
|
import { ListFileItem } from '$lib/components/file-list/file-list';
|
2025-02-02 11:17:22 +01:00
|
|
|
import {
|
|
|
|
|
allowedEmbeddingBasemaps,
|
|
|
|
|
getFilesFromEmbeddingOptions,
|
|
|
|
|
type EmbeddingOptions,
|
|
|
|
|
} from './Embedding';
|
|
|
|
|
import { mode, setMode } from 'mode-watcher';
|
|
|
|
|
import { browser } from '$app/environment';
|
2025-10-05 19:34:05 +02:00
|
|
|
import { settings } from '$lib/logic/settings.svelte';
|
|
|
|
|
import { fileStateCollection } from '$lib/logic/file-state.svelte';
|
2025-02-02 11:17:22 +01:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let {
|
|
|
|
|
useHash = true,
|
|
|
|
|
options = $bindable(),
|
|
|
|
|
hash,
|
|
|
|
|
}: { useHash?: boolean; options: EmbeddingOptions; hash: string } = $props();
|
|
|
|
|
|
|
|
|
|
setContext('embedding', true);
|
2025-02-02 11:17:22 +01:00
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
currentBasemap,
|
|
|
|
|
distanceUnits,
|
|
|
|
|
velocityUnits,
|
|
|
|
|
temperatureUnits,
|
|
|
|
|
fileOrder,
|
|
|
|
|
distanceMarkers,
|
|
|
|
|
directionMarkers,
|
|
|
|
|
} = settings;
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let prevSettings: {
|
|
|
|
|
distanceMarkers: boolean;
|
|
|
|
|
directionMarkers: boolean;
|
|
|
|
|
distanceUnits: 'metric' | 'imperial' | 'nautical';
|
|
|
|
|
velocityUnits: 'speed' | 'pace';
|
|
|
|
|
temperatureUnits: 'celsius' | 'fahrenheit';
|
|
|
|
|
theme: 'light' | 'dark' | 'system';
|
|
|
|
|
} = {
|
2025-02-02 11:17:22 +01:00
|
|
|
distanceMarkers: false,
|
|
|
|
|
directionMarkers: false,
|
|
|
|
|
distanceUnits: 'metric',
|
|
|
|
|
velocityUnits: 'speed',
|
|
|
|
|
temperatureUnits: 'celsius',
|
|
|
|
|
theme: 'system',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function applyOptions() {
|
2025-10-05 19:34:05 +02:00
|
|
|
// fileObservers.update(($fileObservers) => {
|
|
|
|
|
// $fileObservers.clear();
|
|
|
|
|
// return $fileObservers;
|
|
|
|
|
// });
|
|
|
|
|
// let downloads: Promise<GPXFile | null>[] = [];
|
|
|
|
|
// getFilesFromEmbeddingOptions(options).forEach((url) => {
|
|
|
|
|
// downloads.push(
|
|
|
|
|
// fetch(url)
|
|
|
|
|
// .then((response) => response.blob())
|
|
|
|
|
// .then((blob) => new File([blob], url.split('/').pop() ?? url))
|
|
|
|
|
// .then(loadFile)
|
|
|
|
|
// );
|
|
|
|
|
// });
|
|
|
|
|
// Promise.all(downloads).then((files) => {
|
|
|
|
|
// let ids: string[] = [];
|
|
|
|
|
// let bounds = {
|
|
|
|
|
// southWest: {
|
|
|
|
|
// lat: 90,
|
|
|
|
|
// lon: 180,
|
|
|
|
|
// },
|
|
|
|
|
// northEast: {
|
|
|
|
|
// lat: -90,
|
|
|
|
|
// lon: -180,
|
|
|
|
|
// },
|
|
|
|
|
// };
|
|
|
|
|
// fileObservers.update(($fileObservers) => {
|
|
|
|
|
// files.forEach((file, index) => {
|
|
|
|
|
// if (file === null) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// let id = `gpx-${index}-embed`;
|
|
|
|
|
// file._data.id = id;
|
|
|
|
|
// let statistics = new GPXStatisticsTree(file);
|
|
|
|
|
// $fileObservers.set(
|
|
|
|
|
// id,
|
|
|
|
|
// readable({
|
|
|
|
|
// file,
|
|
|
|
|
// statistics,
|
|
|
|
|
// })
|
|
|
|
|
// );
|
|
|
|
|
// ids.push(id);
|
|
|
|
|
// let fileBounds = statistics.getStatisticsFor(new ListFileItem(id)).global
|
|
|
|
|
// .bounds;
|
|
|
|
|
// bounds.southWest.lat = Math.min(bounds.southWest.lat, fileBounds.southWest.lat);
|
|
|
|
|
// bounds.southWest.lon = Math.min(bounds.southWest.lon, fileBounds.southWest.lon);
|
|
|
|
|
// bounds.northEast.lat = Math.max(bounds.northEast.lat, fileBounds.northEast.lat);
|
|
|
|
|
// bounds.northEast.lon = Math.max(bounds.northEast.lon, fileBounds.northEast.lon);
|
|
|
|
|
// });
|
|
|
|
|
// return $fileObservers;
|
|
|
|
|
// });
|
|
|
|
|
// $fileOrder = [...$fileOrder.filter((id) => !id.includes('embed')), ...ids];
|
|
|
|
|
// selection.update(($selection) => {
|
|
|
|
|
// $selection.clear();
|
|
|
|
|
// ids.forEach((id) => {
|
|
|
|
|
// $selection.toggle(new ListFileItem(id));
|
|
|
|
|
// });
|
|
|
|
|
// return $selection;
|
|
|
|
|
// });
|
|
|
|
|
// if (hash.length === 0) {
|
|
|
|
|
// map.subscribe(($map) => {
|
|
|
|
|
// if ($map) {
|
|
|
|
|
// $map.fitBounds(
|
|
|
|
|
// [
|
|
|
|
|
// bounds.southWest.lon,
|
|
|
|
|
// bounds.southWest.lat,
|
|
|
|
|
// bounds.northEast.lon,
|
|
|
|
|
// bounds.northEast.lat,
|
|
|
|
|
// ],
|
|
|
|
|
// {
|
|
|
|
|
// padding: 80,
|
|
|
|
|
// linear: true,
|
|
|
|
|
// easing: () => 1,
|
|
|
|
|
// }
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// if (
|
|
|
|
|
// options.basemap !== $currentBasemap &&
|
|
|
|
|
// allowedEmbeddingBasemaps.includes(options.basemap)
|
|
|
|
|
// ) {
|
|
|
|
|
// $currentBasemap = options.basemap;
|
|
|
|
|
// }
|
|
|
|
|
// if (options.distanceMarkers !== $distanceMarkers) {
|
|
|
|
|
// $distanceMarkers = options.distanceMarkers;
|
|
|
|
|
// }
|
|
|
|
|
// if (options.directionMarkers !== $directionMarkers) {
|
|
|
|
|
// $directionMarkers = options.directionMarkers;
|
|
|
|
|
// }
|
|
|
|
|
// if (options.distanceUnits !== $distanceUnits) {
|
|
|
|
|
// $distanceUnits = options.distanceUnits;
|
|
|
|
|
// }
|
|
|
|
|
// if (options.velocityUnits !== $velocityUnits) {
|
|
|
|
|
// $velocityUnits = options.velocityUnits;
|
|
|
|
|
// }
|
|
|
|
|
// if (options.temperatureUnits !== $temperatureUnits) {
|
|
|
|
|
// $temperatureUnits = options.temperatureUnits;
|
|
|
|
|
// }
|
|
|
|
|
// if (options.theme !== $mode) {
|
|
|
|
|
// setMode(options.theme);
|
|
|
|
|
// }
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
2025-10-05 19:34:05 +02:00
|
|
|
prevSettings.distanceMarkers = distanceMarkers.value;
|
|
|
|
|
prevSettings.directionMarkers = directionMarkers.value;
|
|
|
|
|
prevSettings.distanceUnits = distanceUnits.value;
|
|
|
|
|
prevSettings.velocityUnits = velocityUnits.value;
|
|
|
|
|
prevSettings.temperatureUnits = temperatureUnits.value;
|
|
|
|
|
prevSettings.theme = mode.current ?? 'system';
|
2025-02-02 11:17:22 +01:00
|
|
|
});
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
// $: if (browser && options) {
|
|
|
|
|
// applyOptions();
|
|
|
|
|
// }
|
2025-02-02 11:17:22 +01:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
// $: if ($fileOrder) {
|
|
|
|
|
// updateGPXData();
|
|
|
|
|
// }
|
2025-02-02 11:17:22 +01:00
|
|
|
|
|
|
|
|
onDestroy(() => {
|
2025-10-05 19:34:05 +02:00
|
|
|
if (distanceMarkers.value !== prevSettings.distanceMarkers) {
|
|
|
|
|
distanceMarkers.value = prevSettings.distanceMarkers;
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
if (directionMarkers.value !== prevSettings.directionMarkers) {
|
|
|
|
|
directionMarkers.value = prevSettings.directionMarkers;
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
if (distanceUnits.value !== prevSettings.distanceUnits) {
|
|
|
|
|
distanceUnits.value = prevSettings.distanceUnits;
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
if (velocityUnits.value !== prevSettings.velocityUnits) {
|
|
|
|
|
velocityUnits.value = prevSettings.velocityUnits;
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
if (temperatureUnits.value !== prevSettings.temperatureUnits) {
|
|
|
|
|
temperatureUnits.value = prevSettings.temperatureUnits;
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
if (mode.current !== prevSettings.theme) {
|
2025-02-02 11:17:22 +01:00
|
|
|
setMode(prevSettings.theme);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
// $selection.clear();
|
|
|
|
|
// $fileObservers.clear();
|
|
|
|
|
fileOrder.value = fileOrder.value.filter((id) => !id.includes('embed'));
|
2025-02-02 11:17:22 +01:00
|
|
|
});
|
2024-07-12 15:00:33 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="absolute flex flex-col h-full w-full border rounded-xl overflow-clip">
|
2025-02-02 11:17:22 +01:00
|
|
|
<div class="grow relative">
|
|
|
|
|
<Map
|
2025-10-05 19:34:05 +02:00
|
|
|
class="h-full {fileStateCollection.files.size > 1 ? 'horizontal' : ''}"
|
2025-02-02 11:17:22 +01:00
|
|
|
accessToken={options.token}
|
|
|
|
|
geocoder={false}
|
|
|
|
|
geolocate={false}
|
|
|
|
|
hash={useHash}
|
|
|
|
|
/>
|
2025-10-05 19:34:05 +02:00
|
|
|
<OpenIn files={options.files} ids={options.ids} />
|
|
|
|
|
<!-- <LayerControl /> -->
|
|
|
|
|
<!-- <GPXLayers /> -->
|
|
|
|
|
{#if fileStateCollection.files.size > 1}
|
2025-02-02 11:17:22 +01:00
|
|
|
<div class="h-10 -translate-y-10 w-full pointer-events-none absolute z-30">
|
2025-10-05 19:34:05 +02:00
|
|
|
<!-- <FileList orientation="horizontal" /> -->
|
2025-02-02 11:17:22 +01:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
class="{options.elevation.show ? '' : 'h-10'} flex flex-row gap-2 px-2 sm:px-4"
|
|
|
|
|
style={options.elevation.show ? `height: ${options.elevation.height}px` : ''}
|
|
|
|
|
>
|
2025-10-05 19:34:05 +02:00
|
|
|
<!-- <GPXStatistics
|
2025-02-02 11:17:22 +01:00
|
|
|
{gpxStatistics}
|
|
|
|
|
{slicedGPXStatistics}
|
|
|
|
|
panelSize={options.elevation.height}
|
|
|
|
|
orientation={options.elevation.show ? 'vertical' : 'horizontal'}
|
2025-10-05 19:34:05 +02:00
|
|
|
/> -->
|
2025-02-02 11:17:22 +01:00
|
|
|
{#if options.elevation.show}
|
2025-10-05 19:34:05 +02:00
|
|
|
<!-- <ElevationProfile
|
2025-02-02 11:17:22 +01:00
|
|
|
{gpxStatistics}
|
|
|
|
|
{slicedGPXStatistics}
|
|
|
|
|
additionalDatasets={[
|
|
|
|
|
options.elevation.speed ? 'speed' : null,
|
|
|
|
|
options.elevation.hr ? 'hr' : null,
|
|
|
|
|
options.elevation.cad ? 'cad' : null,
|
|
|
|
|
options.elevation.temp ? 'temp' : null,
|
|
|
|
|
options.elevation.power ? 'power' : null,
|
|
|
|
|
].filter((dataset) => dataset !== null)}
|
|
|
|
|
elevationFill={options.elevation.fill}
|
|
|
|
|
showControls={options.elevation.controls}
|
2025-10-05 19:34:05 +02:00
|
|
|
/> -->
|
2025-02-02 11:17:22 +01:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
2024-07-12 15:00:33 +02:00
|
|
|
</div>
|