mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-31 02:39:38 +02:00
Merge pull request #314 from seanmorley15/worldtravel-v2
WorldTravel v2
This commit is contained in:
commit
3c43f3cfad
20 changed files with 387 additions and 97 deletions
|
@ -5,6 +5,8 @@
|
|||
import { createEventDispatcher } from 'svelte';
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
import MapMarkerStar from '~icons/mdi/map-marker-star';
|
||||
|
||||
export let country: Country;
|
||||
|
||||
async function nav() {
|
||||
|
@ -21,7 +23,12 @@
|
|||
</figure>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title overflow-ellipsis">{country.name}</h2>
|
||||
<div class="badge badge-primary">{continentCodeToString(country.continent)}</div>
|
||||
{#if country.subregion}
|
||||
<div class="badge badge-primary">{country.subregion}</div>
|
||||
{/if}
|
||||
{#if country.capital}
|
||||
<div class="badge badge-secondary"><MapMarkerStar class="-ml-1 mr-1" />{country.capital}</div>
|
||||
{/if}
|
||||
<div class="card-actions justify-end">
|
||||
<!-- <button class="btn btn-info" on:click={moreInfo}>More Info</button> -->
|
||||
<button class="btn btn-primary" on:click={nav}>Open</button>
|
||||
|
|
|
@ -39,15 +39,17 @@ export type Country = {
|
|||
id: number;
|
||||
name: string;
|
||||
country_code: string;
|
||||
continent: string;
|
||||
subregion: string;
|
||||
flag_url: string;
|
||||
capital: string;
|
||||
};
|
||||
|
||||
export type Region = {
|
||||
id: number;
|
||||
name: string;
|
||||
name_en?: string;
|
||||
country: number;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
};
|
||||
|
||||
export type VisitedRegion = {
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { PageServerLoad } from './$types';
|
|||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||
import type { Adventure } from '$lib/types';
|
||||
|
||||
import type { Actions, RequestEvent } from '@sveltejs/kit';
|
||||
import type { Actions } from '@sveltejs/kit';
|
||||
import { fetchCSRFToken, tryRefreshToken } from '$lib/index.server';
|
||||
import { checkLink } from '$lib';
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
}
|
||||
let visitedRegions = data.props.visitedRegions;
|
||||
|
||||
let geoJSON = [];
|
||||
let allRegions = [];
|
||||
|
||||
let visitArray = [];
|
||||
|
||||
|
@ -72,12 +72,12 @@
|
|||
// mapped to the checkbox
|
||||
let showGEO = false;
|
||||
$: {
|
||||
if (showGEO && geoJSON.length === 0) {
|
||||
if (showGEO && allRegions.length === 0) {
|
||||
(async () => {
|
||||
geoJSON = await fetch('/api/geojson/').then((res) => res.json());
|
||||
allRegions = await fetch('/api/visitedregion/').then((res) => res.json());
|
||||
})();
|
||||
} else if (!showGEO) {
|
||||
geoJSON = [];
|
||||
allRegions = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@
|
|||
<input type="checkbox" bind:checked={showPlanned} class="checkbox checkbox-primary" />
|
||||
</label>
|
||||
<!-- <div class="divider divider-horizontal"></div> -->
|
||||
<label for="show-geo">Show Borders</label>
|
||||
<label for="show-geo">Show Visited Regions</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="show-geo"
|
||||
|
@ -183,33 +183,34 @@
|
|||
</Marker>
|
||||
{/if}
|
||||
{/each}
|
||||
{#if showGEO}
|
||||
<GeoJSON id="states" data={geoJSON} promoteId="ISOCODE">
|
||||
<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)' }}
|
||||
filter={['in', 'ISOCODE', ...visitArray]}
|
||||
/>
|
||||
<SymbolLayer
|
||||
layout={{
|
||||
'text-field': ['get', 'name'],
|
||||
'text-size': 12,
|
||||
'text-anchor': 'center'
|
||||
}}
|
||||
paint={{
|
||||
'text-color': 'black'
|
||||
}}
|
||||
/>
|
||||
</GeoJSON>
|
||||
{/if}
|
||||
|
||||
<MapEvents on:click={addMarker} />
|
||||
{#each newMarker as marker}
|
||||
<DefaultMarker lngLat={marker.lngLat} />
|
||||
{/each}
|
||||
|
||||
{#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}
|
||||
</MapLibre>
|
||||
|
||||
<svelte:head>
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
<script lang="ts">
|
||||
import RegionCard from '$lib/components/RegionCard.svelte';
|
||||
import type { Region, VisitedRegion } from '$lib/types';
|
||||
// import {
|
||||
// DefaultMarker,
|
||||
// MapEvents,
|
||||
// MapLibre,
|
||||
// Popup,
|
||||
// Marker,
|
||||
// GeoJSON,
|
||||
// LineLayer,
|
||||
// FillLayer,
|
||||
// SymbolLayer
|
||||
// } from 'svelte-maplibre';
|
||||
import type { PageData } from './$types';
|
||||
export let data: PageData;
|
||||
let regions: Region[] = data.props?.regions || [];
|
||||
|
@ -47,6 +58,23 @@
|
|||
{/each}
|
||||
</div>
|
||||
|
||||
<!-- {#if data.props && data.props.regions}
|
||||
<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
|
||||
>
|
||||
{#each data.props.regions as marker}
|
||||
<DefaultMarker lngLat={[marker.longitude, marker.latitude]}>
|
||||
<Popup openOn="click" offset={[0, -10]}>
|
||||
<div class="text-lg text-black font-bold">{marker.name}</div>
|
||||
<p class="font-semibold text-black text-md">{marker.id}</p>
|
||||
</Popup>
|
||||
</DefaultMarker>
|
||||
{/each}
|
||||
</MapLibre>
|
||||
{/if} -->
|
||||
|
||||
<svelte:head>
|
||||
<title
|
||||
>{data.props && data.props.country ? `Regions in ${data.props.country.name}` : 'Regions'}</title
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue