2024-07-08 11:44:39 -04:00
|
|
|
<script>
|
|
|
|
// @ts-nocheck
|
|
|
|
|
2024-07-24 18:45:49 -04:00
|
|
|
import NewAdventure from '$lib/components/NewAdventure.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;
|
|
|
|
|
|
|
|
$: {
|
|
|
|
if (!showVisited) {
|
|
|
|
markers = markers.filter((marker) => marker.type !== 'visited');
|
|
|
|
} else {
|
|
|
|
const visitedMarkers = data.props.markers.filter((marker) => marker.type === 'visited');
|
|
|
|
markers = [...markers, ...visitedMarkers];
|
|
|
|
}
|
|
|
|
if (!showPlanned) {
|
|
|
|
markers = markers.filter((marker) => marker.type !== 'planned');
|
|
|
|
} else {
|
|
|
|
const plannedMarkers = data.props.markers.filter((marker) => marker.type === 'planned');
|
|
|
|
markers = [...markers, ...plannedMarkers];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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' }];
|
|
|
|
console.log(newMarker);
|
|
|
|
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) {
|
|
|
|
// 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;
|
|
|
|
}
|
2024-07-24 10:40:48 -04:00
|
|
|
|
|
|
|
let visitedRegions = data.props.visitedRegions;
|
|
|
|
|
2024-07-27 12:46:50 -04:00
|
|
|
let geoJSON = [];
|
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;
|
|
|
|
$: {
|
|
|
|
if (showGEO && geoJSON.length === 0) {
|
|
|
|
(async () => {
|
2024-07-27 12:50:36 -04:00
|
|
|
geoJSON = await fetch('/api/geojson/').then((res) => res.json());
|
2024-07-27 12:46:50 -04:00
|
|
|
})();
|
|
|
|
} else if (!showGEO) {
|
|
|
|
geoJSON = [];
|
|
|
|
}
|
|
|
|
}
|
2024-07-24 18:45:49 -04:00
|
|
|
|
|
|
|
let createModalOpen = false;
|
2024-07-08 11:44:39 -04:00
|
|
|
</script>
|
|
|
|
|
2024-07-27 12:46:50 -04:00
|
|
|
<label class="label cursor-pointer">
|
|
|
|
<span class="label-text">Visited</span>
|
|
|
|
<input type="checkbox" bind:checked={showVisited} class="checkbox checkbox-primary" />
|
|
|
|
</label>
|
|
|
|
<label class="label cursor-pointer">
|
|
|
|
<span class="label-text">Planned</span>
|
|
|
|
<input type="checkbox" bind:checked={showPlanned} class="checkbox checkbox-primary" />
|
|
|
|
</label>
|
|
|
|
|
2024-07-24 18:45:49 -04:00
|
|
|
{#if newMarker.length > 0}
|
2024-07-24 18:55:40 -04:00
|
|
|
<button type="button" class="btn btn-primary mb-2" on:click={() => (createModalOpen = true)}
|
2024-07-24 18:45:49 -04:00
|
|
|
>Add New Adventure at Marker</button
|
|
|
|
>
|
2024-07-24 18:55:40 -04:00
|
|
|
<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
|
|
|
|
>
|
2024-07-24 18:45:49 -04:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if createModalOpen}
|
|
|
|
<NewAdventure
|
|
|
|
on:close={() => (createModalOpen = false)}
|
|
|
|
longitude={newLongitude}
|
|
|
|
latitude={newLatitude}
|
2024-07-25 18:53:55 -04:00
|
|
|
on:create={createNewAdventure}
|
2024-07-24 18:45:49 -04:00
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
|
2024-07-24 11:01:59 -04:00
|
|
|
<label for="show-geo">Show Borders?</label>
|
|
|
|
<input type="checkbox" id="shpw-gep" name="show-geo" class="checkbox" bind:checked={showGEO} />
|
2024-07-24 10:40:48 -04:00
|
|
|
|
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-07-25 18:53:55 -04:00
|
|
|
{#each markers as { lngLat, name, type }}
|
2024-07-22 10:45:25 -04:00
|
|
|
{#if type == 'visited'}
|
|
|
|
<Marker
|
|
|
|
{lngLat}
|
|
|
|
on:click={() => (clickedName = name)}
|
|
|
|
class="grid h-8 w-8 place-items-center rounded-full border border-gray-200 bg-red-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="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-07-24 10:40:48 -04:00
|
|
|
{#if showGEO}
|
2024-07-27 12:46:50 -04:00
|
|
|
<GeoJSON id="states" data={geoJSON} promoteId="ISOCODE">
|
2024-07-24 10:40:48 -04:00
|
|
|
<LineLayer
|
|
|
|
layout={{ 'line-cap': 'round', 'line-join': 'round' }}
|
|
|
|
paint={{ 'line-color': 'grey', 'line-width': 3 }}
|
|
|
|
beforeLayerType="symbol"
|
|
|
|
/>
|
|
|
|
<FillLayer
|
|
|
|
paint={{ 'fill-color': 'rgba(37, 244, 26, 0.15)' }}
|
2024-07-24 11:01:59 -04:00
|
|
|
filter={['in', 'ISOCODE', ...visitArray]}
|
2024-07-24 10:40:48 -04:00
|
|
|
/>
|
2024-07-30 11:34:17 -04:00
|
|
|
<SymbolLayer
|
2024-07-24 10:40:48 -04:00
|
|
|
layout={{
|
2024-07-30 11:34:17 -04:00
|
|
|
'text-field': ['get', 'name'],
|
2024-07-24 10:40:48 -04:00
|
|
|
'text-size': 12,
|
|
|
|
'text-anchor': 'center'
|
|
|
|
}}
|
|
|
|
paint={{
|
|
|
|
'text-color': 'black'
|
|
|
|
}}
|
2024-07-30 11:34:17 -04:00
|
|
|
/>
|
2024-07-24 10:40:48 -04:00
|
|
|
</GeoJSON>
|
|
|
|
{/if}
|
2024-07-24 18:45:49 -04:00
|
|
|
<MapEvents on:click={addMarker} />
|
|
|
|
{#each newMarker as marker}
|
|
|
|
<DefaultMarker lngLat={marker.lngLat} />
|
|
|
|
{/each}
|
2024-07-08 11:44:39 -04:00
|
|
|
</MapLibre>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
:global(.map) {
|
|
|
|
height: 500px;
|
|
|
|
}
|
|
|
|
</style>
|