mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-25 07:49:37 +02:00
Autoadd
This commit is contained in:
parent
ea5329cf34
commit
e1a9602481
2 changed files with 51 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import type { Adventure, Point } from '$lib/types';
|
import type { Adventure, OpenStreetMapPlace, Point } from '$lib/types';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
import { addToast } from '$lib/toasts';
|
import { addToast } from '$lib/toasts';
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
import Wikipedia from '~icons/mdi/wikipedia';
|
import Wikipedia from '~icons/mdi/wikipedia';
|
||||||
import ClipboardList from '~icons/mdi/clipboard-list';
|
import ClipboardList from '~icons/mdi/clipboard-list';
|
||||||
import ActivityComplete from './ActivityComplete.svelte';
|
import ActivityComplete from './ActivityComplete.svelte';
|
||||||
|
import { appVersion } from '$lib/config';
|
||||||
|
|
||||||
let newAdventure: Adventure = {
|
let newAdventure: Adventure = {
|
||||||
id: NaN,
|
id: NaN,
|
||||||
|
@ -37,6 +38,25 @@
|
||||||
if (longitude && latitude) {
|
if (longitude && latitude) {
|
||||||
newAdventure.latitude = latitude;
|
newAdventure.latitude = latitude;
|
||||||
newAdventure.longitude = longitude;
|
newAdventure.longitude = longitude;
|
||||||
|
reverseGeocode();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reverseGeocode() {
|
||||||
|
let res = await fetch(
|
||||||
|
`https://nominatim.openstreetmap.org/search?q=${newAdventure.latitude},${newAdventure.longitude}&format=jsonv2`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'User-Agent': `AdventureLog / ${appVersion} `
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
let data = (await res.json()) as OpenStreetMapPlace[];
|
||||||
|
if (data.length > 0) {
|
||||||
|
newAdventure.name = data[0]?.name || '';
|
||||||
|
newAdventure.activity_types?.push(data[0]?.type || '');
|
||||||
|
newAdventure.location = data[0]?.display_name || '';
|
||||||
|
}
|
||||||
|
console.log(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
let image: File;
|
let image: File;
|
||||||
|
|
|
@ -30,7 +30,34 @@
|
||||||
newLatitude = e.detail.lngLat.lat;
|
newLatitude = e.detail.lngLat.lat;
|
||||||
}
|
}
|
||||||
|
|
||||||
let markers = data.props.markers;
|
let markers = [];
|
||||||
|
|
||||||
|
$: {
|
||||||
|
markers = data.props.markers;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNewAdventure(event) {
|
||||||
|
// markers = visited
|
||||||
|
// .filter((adventure) => adventure.latitude !== null && adventure.longitude !== null)
|
||||||
|
// .map((adventure) => {
|
||||||
|
// return {
|
||||||
|
// lngLat: [adventure.longitude, adventure.latitude] as [number, number],
|
||||||
|
// name: adventure.name,
|
||||||
|
// type: adventure.type
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
console.log(event.detail);
|
||||||
|
|
||||||
|
let newMarker = {
|
||||||
|
lngLat: [event.detail.longitude, event.detail.latitude],
|
||||||
|
name: event.detail.name,
|
||||||
|
type: 'planned'
|
||||||
|
};
|
||||||
|
markers = [...markers, newMarker];
|
||||||
|
clearMarkers();
|
||||||
|
console.log(markers);
|
||||||
|
createModalOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
let visitedRegions = data.props.visitedRegions;
|
let visitedRegions = data.props.visitedRegions;
|
||||||
|
|
||||||
|
@ -71,6 +98,7 @@
|
||||||
on:close={() => (createModalOpen = false)}
|
on:close={() => (createModalOpen = false)}
|
||||||
longitude={newLongitude}
|
longitude={newLongitude}
|
||||||
latitude={newLatitude}
|
latitude={newLatitude}
|
||||||
|
on:create={createNewAdventure}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
@ -82,7 +110,7 @@
|
||||||
class="relative aspect-[9/16] max-h-[70vh] w-full sm:aspect-video sm:max-h-full"
|
class="relative aspect-[9/16] max-h-[70vh] w-full sm:aspect-video sm:max-h-full"
|
||||||
standardControls
|
standardControls
|
||||||
>
|
>
|
||||||
{#each data.props.markers as { lngLat, name, type }}
|
{#each markers as { lngLat, name, type }}
|
||||||
{#if type == 'visited'}
|
{#if type == 'visited'}
|
||||||
<Marker
|
<Marker
|
||||||
{lngLat}
|
{lngLat}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue