Merge branch 'dev'

This commit is contained in:
Alexis
2024-05-07 23:09:01 +02:00
4 changed files with 1509 additions and 984 deletions

2400
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,14 +10,14 @@
"astro": "astro" "astro": "astro"
}, },
"dependencies": { "dependencies": {
"@astrojs/sitemap": "^3.1.1", "@astrojs/sitemap": "^3.1.4",
"@astrojs/vue": "^4.0.8", "@astrojs/vue": "^4.1.0",
"@types/leaflet": "^1.9.8", "@types/leaflet": "^1.9.12",
"@vueuse/core": "^10.8.0", "@vueuse/core": "^10.9.0",
"astro": "^4.4.5", "astro": "^4.7.1",
"vue": "^3.4.20" "vue": "^3.4.27"
}, },
"devDependencies": { "devDependencies": {
"sass": "^1.71.1" "sass": "^1.77.0"
} }
} }

View File

@@ -457,6 +457,84 @@ function removeCustomMarker(marker, markerTitle) {
saveCustomMarkers() saveCustomMarkers()
} }
/**
* URL PARAMETERS
*/
/**
* From the leaflet setup, get a working param config
*
* @returns Latitude, Longitude and zoom level of the map
*/
function getURLFromSetup() {
const centerOfMap = map.getCenter()
const lat = centerOfMap.lat
const lon = centerOfMap.lng
const zoom = parseFloat(map.getZoom().toFixed(1))
return { lat, lon, zoom }
}
/**
* Get leaflet coords from URL params
*
* @returns URLSearchParams
*/
function getCoordsSetupFromURL() {
const params = new URL(document.location).searchParams
return params
}
/**
* Check if the params in the URL can be parsed as leaflet coordinates
*
* @return boolean
*/
function hasInitialSetup() {
const params = new URL(document.location).searchParams
return params.has('lat') && params.has('lon')
}
/**
* Function to refresh the URL params
*
* @returns void
*/
function setupToURL() {
const setup = getURLFromSetup()
const newParams = new URLSearchParams(setup)
const newUrl = new URL(window.location.href)
newUrl.search = newParams.toString()
window.history.replaceState(null, '', newUrl.toString())
}
/**
* Uses the URL params to setup the leaflet map
*/
function setupFromURL() {
const setup = getCoordsSetupFromURL()
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()
} else {
setupToURL()
}
// When the map stops moving, update the URL to keep it up to date
map.on('moveend', () => {
setupToURL()
})
/** /**
* UTILITIES * UTILITIES
*/ */

1
src/env.d.ts vendored
View File

@@ -1 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" /> /// <reference types="astro/client" />