diff options
Diffstat (limited to 'src/static/main.js')
| -rw-r--r-- | src/static/main.js | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/static/main.js b/src/static/main.js index 102862f..0ee92ef 100644 --- a/src/static/main.js +++ b/src/static/main.js @@ -141,7 +141,6 @@ async function fetchChains() { const urlParams = new URLSearchParams(queryString); const category_url_param = urlParams.get('category') const country_url_param = urlParams.get('country') - //console.log(country_url_param) const category_field_value = CategoryField.value const country_field_value = CountryField.value // Retains saved value from input field on reload @@ -209,13 +208,21 @@ function drawHeatmap() { } async function fetchAll(country, category) { - if (CountryField.value == "Denmark") { - console.log('Focusing Copenhagen') - map.setView([55.68, 12.57], 13); - } else if(CountryField.value == "Germany") { - console.log('Focusing Hamburg') - map.setView([53.56, 10.01], 12); - } + const lat = urlParams.get('lat') ?? 55.68; + const lon = urlParams.get('lon') ?? 12.57; + const zoom = urlParams.get('zoom') ?? 13; + + if ((urlParams.has('lat') && urlParams.has('lon'))) { + map.setView([lat, lon], zoom); + } else { + if (CountryField.value == "Denmark") { + console.log('Focusing Copenhagen') + map.setView([55.68, 12.57], 13); + } else if(CountryField.value == "Germany") { + console.log('Focusing Hamburg') + map.setView([53.56, 10.01], 12); + } + } let response; try { @@ -241,3 +248,22 @@ async function fetchAll(country, category) { fetchChains(); fetchCategories(); +// Pan/drag finished +map.on('moveend', () => { + const c = map.getCenter(); + console.log(c) + const url = new URL(location); + url.searchParams.set("lat", c.lat); + url.searchParams.set("lon", c.lng); + history.pushState({}, "", url); +}); + +// Zoom finished +map.on('zoomend', () => { + console.log(map.getZoom()) + const url = new URL(location); + url.searchParams.set("zoom", map.getZoom()); + history.pushState({}, "", url); + +}); + |
