add Overpass POI website as wpt link

This commit is contained in:
vcoppe
2025-06-04 18:55:14 +02:00
parent 018e638ae3
commit a9deb681e0

View File

@@ -7,10 +7,11 @@
import { dbUtils } from '$lib/db'; import { dbUtils } from '$lib/db';
import type { PopupItem } from '$lib/components/MapPopup'; import type { PopupItem } from '$lib/components/MapPopup';
import { ScrollArea } from '$lib/components/ui/scroll-area/index.js'; import { ScrollArea } from '$lib/components/ui/scroll-area/index.js';
import type { WaypointType } from 'gpx';
export let poi: PopupItem<any>; export let poi: PopupItem<any>;
let tags = {}; let tags: { [key: string]: string } = {};
let name = ''; let name = '';
$: if (poi) { $: if (poi) {
tags = JSON.parse(poi.item.tags); tags = JSON.parse(poi.item.tags);
@@ -20,6 +21,30 @@
name = $_(`layers.label.${poi.item.query}`); name = $_(`layers.label.${poi.item.query}`);
} }
} }
function addToFile() {
const desc = Object.entries(tags)
.map(([key, value]) => `${key}: ${value}`)
.join('\n');
let wpt: WaypointType = {
attributes: {
lat: poi.item.lat,
lon: poi.item.lon,
},
name: name,
desc: desc,
cmt: desc,
sym: poi.item.sym,
};
if (tags.website) {
wpt.link = {
attributes: {
href: tags.website,
},
};
}
dbUtils.addOrUpdateWaypoint(wpt);
}
</script> </script>
<Card.Root class="border-none shadow-md text-base p-2 max-w-[50dvw]"> <Card.Root class="border-none shadow-md text-base p-2 max-w-[50dvw]">
@@ -73,21 +98,7 @@
class="mt-2" class="mt-2"
variant="outline" variant="outline"
disabled={$selection.size === 0} disabled={$selection.size === 0}
on:click={() => { on:click={addToFile}
let desc = Object.entries(tags)
.map(([key, value]) => `${key}: ${value}`)
.join('\n');
dbUtils.addOrUpdateWaypoint({
attributes: {
lat: poi.item.lat,
lon: poi.item.lon,
},
name: name,
desc: desc,
cmt: desc,
sym: poi.item.sym,
});
}}
> >
<MapPin size="16" class="mr-1" /> <MapPin size="16" class="mr-1" />
{$_('toolbar.waypoint.add')} {$_('toolbar.waypoint.add')}