2024-07-08 11:44:39 -04:00
|
|
|
<script>
|
|
|
|
// @ts-nocheck
|
2024-08-17 22:40:27 -04:00
|
|
|
import AdventureModal from '$lib/components/AdventureModal.svelte';
|
2024-07-24 10:40:48 -04:00
|
|
|
import {
|
|
|
|
DefaultMarker,
|
|
|
|
MapEvents,
|
|
|
|
MapLibre,
|
|
|
|
Popup,
|
|
|
|
Marker,
|
|
|
|
GeoJSON,
|
|
|
|
LineLayer,
|
|
|
|
FillLayer,
|
|
|
|
SymbolLayer
|
|
|
|
} from 'svelte-maplibre';
|
2024-07-08 11:44:39 -04:00
|
|
|
export let data;
|
|
|
|
|
2024-07-22 10:45:25 -04:00
|
|
|
let clickedName = '';
|
|
|
|
|
2024-07-27 12:46:50 -04:00
|
|
|
let showVisited = true;
|
|
|
|
let showPlanned = true;
|
|
|
|
|
2024-08-24 08:27:30 -04:00
|
|
|
$: filteredMarkers = markers.filter(
|
|
|
|
(marker) =>
|
|
|
|
(showVisited && marker.type === 'visited') || (showPlanned && marker.type === 'planned')
|
|
|
|
);
|
2024-07-27 12:46:50 -04:00
|
|
|
|
2024-07-24 18:45:49 -04:00
|
|
|
let newMarker = [];
|
|
|
|
|
|
|
|
let newLongitude = null;
|
|
|
|
let newLatitude = null;
|
|
|
|
|
|
|
|
function addMarker(e) {
|
|
|
|
newMarker = [];
|
|
|
|
newMarker = [...newMarker, { lngLat: e.detail.lngLat, name: 'Marker 1' }];
|
|
|
|
newLongitude = e.detail.lngLat.lng;
|
|
|
|
newLatitude = e.detail.lngLat.lat;
|
|
|
|
}
|
|
|
|
|
2024-07-25 18:53:55 -04:00
|
|
|
let markers = [];
|
|
|
|
|
|
|
|
$: {
|
|
|
|
markers = data.props.markers;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createNewAdventure(event) {
|
|
|
|
let newMarker = {
|
|
|
|
lngLat: [event.detail.longitude, event.detail.latitude],
|
|
|
|
name: event.detail.name,
|
2024-08-24 08:27:30 -04:00
|
|
|
type: event.detail.type
|
2024-07-25 18:53:55 -04:00
|
|
|
};
|
|
|
|
markers = [...markers, newMarker];
|
|
|
|
clearMarkers();
|
|
|
|
createModalOpen = false;
|
|
|
|
}
|
2024-07-24 10:40:48 -04:00
|
|
|
let visitedRegions = data.props.visitedRegions;
|
|
|
|
|
2024-09-11 14:56:52 -04:00
|
|
|
let allRegions = [];
|
2024-07-24 11:52:39 -04:00
|
|
|
|
2024-07-24 10:40:48 -04:00
|
|
|
let visitArray = [];
|
|
|
|
|
|
|
|
// turns in into an array of the visits
|
|
|
|
visitedRegions.forEach((el) => {
|
|
|
|
visitArray.push(el.region);
|
|
|
|
});
|
|
|
|
|
2024-07-24 18:55:40 -04:00
|
|
|
function clearMarkers() {
|
|
|
|
newMarker = [];
|
|
|
|
newLatitude = null;
|
|
|
|
newLongitude = null;
|
|
|
|
}
|
|
|
|
|
2024-07-24 11:52:39 -04:00
|
|
|
// mapped to the checkbox
|
2024-07-27 12:46:50 -04:00
|
|
|
let showGEO = false;
|
|
|
|
$: {
|
2024-09-11 14:56:52 -04:00
|
|
|
if (showGEO && allRegions.length === 0) {
|
2024-07-27 12:46:50 -04:00
|
|
|
(async () => {
|
2024-09-11 14:56:52 -04:00
|
|
|
allRegions = await fetch('/api/visitedregion/').then((res) => res.json());
|
2024-07-27 12:46:50 -04:00
|
|
|
})();
|
|
|
|
} else if (!showGEO) {
|
2024-09-11 14:56:52 -04:00
|
|
|
allRegions = [];
|
2024-07-27 12:46:50 -04:00
|
|
|
}
|
|
|
|
}
|
2024-07-24 18:45:49 -04:00
|
|
|
|
|
|
|
let createModalOpen = false;
|
2024-07-08 11:44:39 -04:00
|
|
|
</script>
|
|
|
|
|
2024-08-08 22:12:06 -04:00
|
|
|
<h1 class="text-center font-bold text-4xl">Adventure Map</h1>
|
|
|
|
|
|
|
|
<div class="m-2 flex flex-col items-center justify-center">
|
|
|
|
<div class="gap-4 border-solid border-2 rounded-lg p-2 mb-4 border-neutral max-w-4xl">
|
|
|
|
<p class="font-semibold text-center text-xl mb-2">Map Options</p>
|
|
|
|
<div class="flex flex-wrap items-center justify-center gap-4">
|
|
|
|
<label class="label cursor-pointer">
|
|
|
|
<span class="label-text mr-1">Visited</span>
|
|
|
|
<input type="checkbox" bind:checked={showVisited} class="checkbox checkbox-primary" />
|
|
|
|
</label>
|
|
|
|
<label class="label cursor-pointer">
|
|
|
|
<span class="label-text mr-1">Planned</span>
|
|
|
|
<input type="checkbox" bind:checked={showPlanned} class="checkbox checkbox-primary" />
|
|
|
|
</label>
|
|
|
|
<!-- <div class="divider divider-horizontal"></div> -->
|
2024-09-11 14:56:52 -04:00
|
|
|
<label for="show-geo">Show Visited Regions</label>
|
2024-08-08 22:12:06 -04:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
id="show-geo"
|
|
|
|
name="show-geo"
|
|
|
|
class="checkbox"
|
|
|
|
bind:checked={showGEO}
|
|
|
|
/>
|
|
|
|
<!-- <div class="divider divider-horizontal"></div> -->
|
|
|
|
{#if newMarker.length > 0}
|
|
|
|
<button type="button" class="btn btn-primary mb-2" on:click={() => (createModalOpen = true)}
|
|
|
|
>Add New Adventure at Marker</button
|
|
|
|
>
|
|
|
|
<button type="button" class="btn btn-neutral mb-2" on:click={clearMarkers}
|
|
|
|
>Clear Marker</button
|
|
|
|
>
|
|
|
|
{:else}
|
|
|
|
<button type="button" class="btn btn-primary mb-2" on:click={() => (createModalOpen = true)}
|
|
|
|
>Add New Adventure</button
|
|
|
|
>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-07-24 18:45:49 -04:00
|
|
|
|
|
|
|
{#if createModalOpen}
|
2024-08-17 22:40:27 -04:00
|
|
|
<AdventureModal
|
2024-07-24 18:45:49 -04:00
|
|
|
on:close={() => (createModalOpen = false)}
|
2024-08-17 22:40:27 -04:00
|
|
|
on:save={createNewAdventure}
|
2024-07-24 18:45:49 -04:00
|
|
|
latitude={newLatitude}
|
2024-08-17 22:40:27 -04:00
|
|
|
longitude={newLongitude}
|
2024-07-24 18:45:49 -04:00
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
|
2024-07-08 11:44:39 -04:00
|
|
|
<MapLibre
|
|
|
|
style="https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json"
|
|
|
|
class="relative aspect-[9/16] max-h-[70vh] w-full sm:aspect-video sm:max-h-full"
|
|
|
|
standardControls
|
|
|
|
>
|
2024-08-24 08:27:30 -04:00
|
|
|
{#each filteredMarkers as { lngLat, name, type }}
|
2024-07-22 10:45:25 -04:00
|
|
|
{#if type == 'visited'}
|
|
|
|
<Marker
|
|
|
|
{lngLat}
|
|
|
|
on:click={() => (clickedName = name)}
|
2024-08-06 09:02:55 -04:00
|
|
|
class="grid h-8 w-8 place-items-center rounded-full border border-gray-200 bg-red-300 text-black shadow-md"
|
2024-07-22 10:45:25 -04:00
|
|
|
>
|
|
|
|
<svg
|
|
|
|
width="24"
|
|
|
|
height="24"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
fill="none"
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
>
|
|
|
|
<circle cx="12" cy="12" r="10" stroke="red" stroke-width="2" fill="red" />
|
|
|
|
</svg>
|
|
|
|
<Popup openOn="click" offset={[0, -10]}>
|
2024-07-27 09:29:47 -04:00
|
|
|
<div class="text-lg text-black font-bold">{name}</div>
|
|
|
|
<p class="font-semibold text-black text-md">Visited</p>
|
2024-07-22 10:45:25 -04:00
|
|
|
</Popup>
|
|
|
|
</Marker>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if type == 'planned'}
|
|
|
|
<Marker
|
|
|
|
{lngLat}
|
|
|
|
on:click={() => (clickedName = name)}
|
|
|
|
class="grid h-8 w-8 place-items-center rounded-full border border-gray-200 bg-blue-300 text-black shadow-2xl focus:outline-2 focus:outline-black"
|
|
|
|
>
|
|
|
|
<svg
|
|
|
|
width="24"
|
|
|
|
height="24"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
fill="none"
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
>
|
|
|
|
<circle cx="12" cy="12" r="10" stroke="blue" stroke-width="2" fill="blue" />
|
|
|
|
</svg>
|
|
|
|
<Popup openOn="click" offset={[0, -10]}>
|
2024-07-27 09:29:47 -04:00
|
|
|
<div class="text-lg text-black font-bold">{name}</div>
|
|
|
|
<p class="font-semibold text-black text-md">Planned</p>
|
2024-07-22 10:45:25 -04:00
|
|
|
</Popup>
|
|
|
|
</Marker>
|
|
|
|
{/if}
|
2024-07-08 11:44:39 -04:00
|
|
|
{/each}
|
2024-09-11 14:56:52 -04:00
|
|
|
|
2024-07-24 18:45:49 -04:00
|
|
|
<MapEvents on:click={addMarker} />
|
|
|
|
{#each newMarker as marker}
|
|
|
|
<DefaultMarker lngLat={marker.lngLat} />
|
|
|
|
{/each}
|
2024-09-11 14:56:52 -04:00
|
|
|
|
|
|
|
{#each allRegions as { longitude, latitude, name, region }}
|
|
|
|
<Marker
|
|
|
|
lngLat={[longitude, latitude]}
|
|
|
|
on:click={() => (clickedName = name)}
|
|
|
|
class="grid h-8 w-8 place-items-center rounded-full border border-gray-200 bg-green-300 text-black shadow-md"
|
|
|
|
>
|
|
|
|
<svg
|
|
|
|
width="24"
|
|
|
|
height="24"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
fill="none"
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
>
|
|
|
|
<!-- green circle -->
|
|
|
|
<circle cx="12" cy="12" r="10" stroke="green" stroke-width="2" fill="green" />
|
|
|
|
</svg>
|
|
|
|
<Popup openOn="click" offset={[0, -10]}>
|
|
|
|
<div class="text-lg text-black font-bold">{name}</div>
|
|
|
|
<p class="font-semibold text-black text-md">{region}</p>
|
|
|
|
</Popup>
|
|
|
|
</Marker>
|
|
|
|
{/each}
|
2024-07-08 11:44:39 -04:00
|
|
|
</MapLibre>
|
|
|
|
|
2024-08-06 08:50:15 -04:00
|
|
|
<svelte:head>
|
|
|
|
<title>Travel Map</title>
|
|
|
|
<meta name="description" content="View your travels on a map." />
|
|
|
|
</svelte:head>
|
|
|
|
|
2024-07-08 11:44:39 -04:00
|
|
|
<style>
|
|
|
|
:global(.map) {
|
|
|
|
height: 500px;
|
|
|
|
}
|
|
|
|
</style>
|