2024-04-16 22:57:28 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import { GPXFile } from 'gpx';
|
|
|
|
|
2024-04-17 11:44:37 +02:00
|
|
|
import { map } from '$lib/stores';
|
|
|
|
|
2024-04-16 22:57:28 +02:00
|
|
|
export let file: GPXFile;
|
|
|
|
|
2024-04-17 12:21:56 +02:00
|
|
|
function addGPXLayer() {
|
|
|
|
if (!$map.getSource('gpx')) {
|
2024-04-17 11:44:37 +02:00
|
|
|
$map.addSource('gpx', {
|
2024-04-16 22:57:28 +02:00
|
|
|
type: 'geojson',
|
|
|
|
data: file.toGeoJSON()
|
|
|
|
});
|
2024-04-17 12:21:56 +02:00
|
|
|
}
|
|
|
|
$map.addLayer({
|
|
|
|
id: 'gpx',
|
|
|
|
type: 'line',
|
|
|
|
source: 'gpx',
|
|
|
|
layout: {
|
|
|
|
'line-join': 'round',
|
|
|
|
'line-cap': 'round'
|
|
|
|
},
|
|
|
|
paint: {
|
|
|
|
'line-color': '#888',
|
|
|
|
'line-width': 8
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$: if ($map) {
|
|
|
|
$map.on('style.load', () => {
|
|
|
|
addGPXLayer();
|
2024-04-16 22:57:28 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|