From 1161dff66c351ec851fe3f800b8f5b251c6cb329 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Mon, 6 May 2024 00:55:02 +0200 Subject: [PATCH 1/2] Implement locations map --- frontend/src/lib/components/BaseMap.svelte | 274 ++++++++++++++++++ frontend/src/lib/components/Map.svelte | 186 ------------ frontend/src/lib/components/MultiMap.svelte | 9 + frontend/src/lib/components/SingleMap.svelte | 15 + frontend/src/lib/components/map.ts | 58 ++++ frontend/src/lib/index.ts | 4 + frontend/src/routes/+page.svelte | 4 + frontend/src/routes/locations/+page.svelte | 21 +- .../src/routes/locations/LocationForm.svelte | 18 +- .../src/routes/locations/[id]/+page.svelte | 4 +- 10 files changed, 394 insertions(+), 199 deletions(-) create mode 100644 frontend/src/lib/components/BaseMap.svelte delete mode 100644 frontend/src/lib/components/Map.svelte create mode 100644 frontend/src/lib/components/MultiMap.svelte create mode 100644 frontend/src/lib/components/SingleMap.svelte create mode 100644 frontend/src/lib/components/map.ts diff --git a/frontend/src/lib/components/BaseMap.svelte b/frontend/src/lib/components/BaseMap.svelte new file mode 100644 index 00000000..8b11e87d --- /dev/null +++ b/frontend/src/lib/components/BaseMap.svelte @@ -0,0 +1,274 @@ + + +
+
+ +
+
diff --git a/frontend/src/lib/components/Map.svelte b/frontend/src/lib/components/Map.svelte deleted file mode 100644 index bf841fba..00000000 --- a/frontend/src/lib/components/Map.svelte +++ /dev/null @@ -1,186 +0,0 @@ - - -
-
- -
-
diff --git a/frontend/src/lib/components/MultiMap.svelte b/frontend/src/lib/components/MultiMap.svelte new file mode 100644 index 00000000..d5a9eeae --- /dev/null +++ b/frontend/src/lib/components/MultiMap.svelte @@ -0,0 +1,9 @@ + + + + diff --git a/frontend/src/lib/components/SingleMap.svelte b/frontend/src/lib/components/SingleMap.svelte new file mode 100644 index 00000000..cdd6efbc --- /dev/null +++ b/frontend/src/lib/components/SingleMap.svelte @@ -0,0 +1,15 @@ + + + + diff --git a/frontend/src/lib/components/map.ts b/frontend/src/lib/components/map.ts new file mode 100644 index 00000000..8f9bfa1b --- /dev/null +++ b/frontend/src/lib/components/map.ts @@ -0,0 +1,58 @@ +// Mapbox access token +// +// Please be fair and don't mis-use. I know that I can move this out of the source, but it's a +// free account anyways, so all you can do is annoy me if the account is banned. +export const MAPBOX_ACCESS_TOKEN = + 'pk.eyJ1IjoiZGFuaWxvIiwiYSI6ImNrMHk4bHcyaTA0OGMzcHA2aXloems2MnQifQ.YovfgNgeajD4aORTUE5aFw'; + +// Mapbox styles +export const MAPBOX_STYLE_DEFAULT = 'outdoors-v11'; +export const MAPBOX_STYLE_SATELLITE = 'satellite-v9'; +export const MAPBOX_STYLE_LIGHT = 'light-v10'; + +// Swisstopo WMS base URL (without LAYERS) +export const SWISSTOPO_WMS_BASE_URL = + 'https://wms.geo.admin.ch/?SERVICE=WMS' + + '&REQUEST=GetMap' + + '&VERSION=1.3.0' + + '&STYLES=default' + + '&CRS=EPSG:3857' + + '&BBOX={bbox-epsg-3857}' + + '&WIDTH=256' + + '&HEIGHT=256' + + '&FORMAT=image/png'; + +// The default centerpoint of the map +export const DEFAULT_MAP_CENTER = {lng: 10, lat: 47}; + +export const MARKER_COLOR = '#1496ED'; // Primary color blue + +export interface Coordinates { + readonly lon: number; + readonly lat: number; +} + +export interface NamedCoordinates extends Coordinates { + readonly name: string; +} + +// Helper function to validate a coordinate pair +export function isValidPos(pos: { + lng: number | null; + lat: number | null; +}): pos is {lng: number; lat: number} { + const {lng, lat} = pos; + if (lng === null || lat === null) { + return false; + } + if (isNaN(lng) || isNaN(lat)) { + return false; + } + if (lng < -180 || lng > 180) { + return false; + } + if (lat < -90 || lat > 90) { + return false; + } + return true; +} diff --git a/frontend/src/lib/index.ts b/frontend/src/lib/index.ts index ed810d00..6ca1b837 100644 --- a/frontend/src/lib/index.ts +++ b/frontend/src/lib/index.ts @@ -1,3 +1,7 @@ import type {RequestEvent} from '@sveltejs/kit'; export type SvelteKitFetch = RequestEvent['fetch']; + +export function notUndefined(value: T | undefined): value is T { + return value !== undefined; +} diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 43bf226d..51e21303 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -109,6 +109,10 @@

News

2024

    +
  • + 14.5. The location list now shows an overview map of all + locations you've been to (launch or landing locations). +
  • 1.4. Do you have a lot of old flights logged in a spreadsheet application (like Excel or Google Sheets), and don't want to type all this information into Flugbuech by hand? In diff --git a/frontend/src/routes/locations/+page.svelte b/frontend/src/routes/locations/+page.svelte index 471d9de8..2fd106c8 100644 --- a/frontend/src/routes/locations/+page.svelte +++ b/frontend/src/routes/locations/+page.svelte @@ -1,9 +1,11 @@ -
    +
    +
    + + diff --git a/frontend/static/css/flugbuech.css b/frontend/static/css/flugbuech.css index df44cf10..cd4c9e48 100644 --- a/frontend/static/css/flugbuech.css +++ b/frontend/static/css/flugbuech.css @@ -31,23 +31,6 @@ p + .spaced-headers { margin-top: 48px; } -.map { - height: 400px; - position: relative; -} - -.map-style-switcher { - position: absolute; - top: 0; - left: 0; - padding: 8px; - z-index: 9999; -} - -.map-style-switcher select { - font-size: 14px; -} - footer { color: #777; font-size: 0.8em;