add cityCoords

params for city chnaged
add 'center city' in settings
This commit is contained in:
2023-11-28 15:15:03 +00:00
parent e3bf5855ab
commit 74fec075be
11 changed files with 66 additions and 37 deletions
+35 -9
View File
@@ -5,17 +5,13 @@ import * as map from './map.js'
import * as dt from './datetime.js'
import {loadAll, showChart, setNoUTC} from './showcharts.js'
import { DateTime } from './luxon.min.js'
import {setCurrentTab, getCurrentTab, showError, fetchfromserver} from "./chart_utilities.js";
import {setCurrentTab, getCurrentTab, showError, fetchfromserver, cityCoords} from "./chart_utilities.js";
(async () => {
// global constants
const Stuttgart = [48.779, 9.16]
// END global constants
// global variables
const params = { // set defaults
center: Stuttgart,
center: {name: 'Stuttgart', coords: [48.778, 9.180]},
zoom: 10,
span: 1,
peak: 70,
@@ -25,11 +21,17 @@ import {setCurrentTab, getCurrentTab, showError, fetchfromserver} from "./chart_
refreshRate: 5,
sid: -1
}
// END global variables
// localStorage.clear()
// Check new map center
const checkNewCenter = (oldC, newC) => {
if((oldC[0] !== newC[0]) || (oldC[1] !== newC[1])) {
map.setNewCenter(newC)
}
}
// Register events
// Every input with value check
@@ -59,6 +61,12 @@ import {setCurrentTab, getCurrentTab, showError, fetchfromserver} from "./chart_
params.span = parseInt(document.getElementById('nbrofdays').value)
params.peak = parseInt(document.getElementById('peaklim').value)
params.weeks = parseInt(document.getElementById('olderthan').value)
const city = document.getElementById('centercity').value
const oldCoords = params.center
params.center.coords = await cityCoords(city)
params.center.name = city
checkNewCenter(oldCoords, params.center.coords)
localStorage.setItem('centercity',JSON.stringify(params.center))
let newlng = document.querySelector('#sellan input:checked').id
let oldlng = localStorage.getItem('curlang')
localStorage.setItem('curlang', newlng)
@@ -95,13 +103,17 @@ import {setCurrentTab, getCurrentTab, showError, fetchfromserver} from "./chart_
document.getElementById('nbrofdays').value = params.span
document.getElementById('peaklim').value = params.peak
document.getElementById('olderthan').value = params.weeks
const centercity = JSON.parse(localStorage.getItem('centercity'))
document.getElementById('centercity').value = centercity.name
// select different infos depoending on the selcted tab
// first clear all
document.querySelector('#ccity').style.display = 'none'
document.querySelector('#stday').style.display = 'inline'
document.querySelector('#nbday').style.display = 'none'
document.querySelector('#pklim').style.display = 'none'
document.querySelector('#odth').style.display = 'none'
if(curtab === 'maptab') {
document.querySelector('#ccity').style.display = 'inline'
document.querySelector('#stday').style.display = 'none'
document.querySelector('#odth').style.display = 'inline'
}
@@ -127,7 +139,21 @@ import {setCurrentTab, getCurrentTab, showError, fetchfromserver} from "./chart_
async function main() {
setNoUTC() // no UTC for HighCharts
// set correct language
const currentLang = localStorage.getItem('curlang')
let currentLang = localStorage.getItem('curlang')
if ((currentLang === null) || (currentLang === '')) {
currentLang = 'de'
localStorage.setItem('curlang', currentLang)
}
let centercity
try {
centercity = JSON.parse(localStorage.getItem('centercity'))
} catch (e) {
centercity = params.center
}
if((centercity === null) || (centercity.name === '')) {
centercity = params.center
}
localStorage.setItem('centercity', JSON.stringify(centercity))
if(currentLang === 'en') {
document.querySelector('#en').checked = true
params.seldate = 'today'