From 8da145039cebf69681114839e7f048a2797a87eb Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 23 Mar 2025 17:12:28 +0100 Subject: [PATCH 1/9] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dbabcad7..0f52ac46 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "leim-maps", "type": "module", - "version": "1.4.5", + "version": "1.4.6", "scripts": { "dev": "astro dev", "start": "astro dev", From 769391fad0ff391886f6abd6b9b6bb9076ead57e Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 23 Mar 2025 17:16:58 +0100 Subject: [PATCH 2/9] Removed unused import --- src/components/maps/Map.astro | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/maps/Map.astro b/src/components/maps/Map.astro index 2e3c6f98..842e7e8d 100644 --- a/src/components/maps/Map.astro +++ b/src/components/maps/Map.astro @@ -4,7 +4,6 @@ import type { MapProps } from '@/types/Map'; import MarkerCreator from './overlay/MarkerCreator.vue'; import { t } from '@/i18n/store'; import { getLangFromUrl } from '@/i18n/utils'; -import MapActions from './MapActions.astro'; interface Props extends MapProps {} From 98e65fe6e158e29dd6622f042a750499cc57e74b Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 23 Mar 2025 18:10:38 +0100 Subject: [PATCH 3/9] Added point parameter for initial setup --- src/components/maps/Map.astro | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/maps/Map.astro b/src/components/maps/Map.astro index 842e7e8d..0ed2b8d6 100644 --- a/src/components/maps/Map.astro +++ b/src/components/maps/Map.astro @@ -130,6 +130,12 @@ const layerGroups = { quests: L.layerGroup(), } +// Prepare initial fly to coords in case of ?p= query param +let initialFlyToMarker = false; +// Get ?p= query param +const urlParams = new URLSearchParams(window.location.search) +const initialPoint = urlParams.get('p') + /** * Build all markers and their related info */ @@ -269,6 +275,18 @@ for (let i = 0; i < markers.length; i++) { marker.openPopup() }, flyToDuration * 1000) }) + + /** + * In case the initial point is set, prepare event name for fly to + */ + // First we parse the marker title to : + // - Change special characters (not accentuated characters) and spaces to hyphens + // - Lowercase the string + const parsedMarkerTitle = m.title.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-zA-Z0-9]/g, "-").toLowerCase() + + if (initialPoint && parsedMarkerTitle === initialPoint) { + initialFlyToMarker = m.title + } } /** @@ -571,7 +589,7 @@ function getCoordsSetupFromURL() { function hasInitialSetup() { const params = new URL(document.location).searchParams - return params.has('lat') && params.has('lon') + return params.has('lat') && params.has('lon') || params.has('p') } /** @@ -592,16 +610,20 @@ function setupToURL() { /** * Uses the URL params to setup the leaflet map */ -function setupFromURL() { +function setupFromURL(p) { const setup = getCoordsSetupFromURL() - map.setView({ lat: setup.get('lat'), lng: setup.get('lon') }, setup.get('zoom') | minZoom, { animate: false }) + if (setup.has('p')) { + document.dispatchEvent(new CustomEvent(`fly-to-${p}`)) + } else { + map.setView({ lat: setup.get('lat'), lng: setup.get('lon') }, setup.get('zoom') | minZoom, { animate: false }) + } } // Check if the map has initial params in the URL // If not, just setup the default URL if (hasInitialSetup()) { - setupFromURL() + setupFromURL(initialFlyToMarker) } else { setupToURL() } From 78c1991f6a34343e5713085e08ac4c6e91880c95 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 23 Mar 2025 18:41:51 +0100 Subject: [PATCH 4/9] Normalize string function --- src/components/maps/Map.astro | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/maps/Map.astro b/src/components/maps/Map.astro index 0ed2b8d6..91e5e959 100644 --- a/src/components/maps/Map.astro +++ b/src/components/maps/Map.astro @@ -50,6 +50,16 @@ const seeMapText = t('maps.go-to-map', lang) }} defer > +/** UTILITIES */ +/** + * Normalize a string to be used as a key + * @param str + */ +function normalizeString(str) { + if (!str) return '' + return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-zA-Z0-9]/g, '-').toLowerCase() +} + /** * LEAFLET MAP SETUP */ @@ -134,7 +144,7 @@ const layerGroups = { let initialFlyToMarker = false; // Get ?p= query param const urlParams = new URLSearchParams(window.location.search) -const initialPoint = urlParams.get('p') +const initialPoint = normalizeString(urlParams.get('p')) /** * Build all markers and their related info @@ -282,7 +292,7 @@ for (let i = 0; i < markers.length; i++) { // First we parse the marker title to : // - Change special characters (not accentuated characters) and spaces to hyphens // - Lowercase the string - const parsedMarkerTitle = m.title.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-zA-Z0-9]/g, "-").toLowerCase() + const parsedMarkerTitle = normalizeString(m.title) if (initialPoint && parsedMarkerTitle === initialPoint) { initialFlyToMarker = m.title From 3460689d3dcd0f15daf9a58ed7085f7520235494 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 23 Mar 2025 21:19:13 +0100 Subject: [PATCH 5/9] Changed marker builder They're in the DOM now, so much easier to manage --- src/assets/scss/_leaflet.scss | 2 +- src/components/maps/Map.astro | 78 ++++++++++++++--------------------- src/i18n/ui.ts | 2 +- 3 files changed, 32 insertions(+), 50 deletions(-) diff --git a/src/assets/scss/_leaflet.scss b/src/assets/scss/_leaflet.scss index 82547362..396f8291 100644 --- a/src/assets/scss/_leaflet.scss +++ b/src/assets/scss/_leaflet.scss @@ -121,7 +121,7 @@ } } - > * + * { + .tooltip-content > * + * { margin: 0; margin-top: .4em; } diff --git a/src/components/maps/Map.astro b/src/components/maps/Map.astro index 91e5e959..883e5719 100644 --- a/src/components/maps/Map.astro +++ b/src/components/maps/Map.astro @@ -32,6 +32,33 @@ const seeMapText = t('maps.go-to-map', lang) + + {markers.map((m, index) => ( + + ))} + + diff --git a/src/components/maps/Map.astro b/src/components/maps/Map.astro index 883e5719..ad059353 100644 --- a/src/components/maps/Map.astro +++ b/src/components/maps/Map.astro @@ -4,6 +4,8 @@ import type { MapProps } from '@/types/Map'; import MarkerCreator from './overlay/MarkerCreator.vue'; import { t } from '@/i18n/store'; import { getLangFromUrl } from '@/i18n/utils'; +import { normalizeString } from '@/utils/Strings'; +import CopyText from '../global/CopyText.astro'; interface Props extends MapProps {} @@ -33,32 +35,44 @@ const seeMapText = t('maps.go-to-map', lang) - {markers.map((m, index) => ( - - ))} +
+ {markers.map((m, index) => ( + + ))} +