This commit is contained in:
parent
d25eaa9334
commit
4efb776004
24
incidence.js
24
incidence.js
@ -1,34 +1,46 @@
|
|||||||
|
// Licence: Robert Koch-Institut (RKI), dl-de/by-2-0
|
||||||
const apiUrl = (location) => `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,cases7_per_100k&geometry=${location.longitude.toFixed(3)}%2C${location.latitude.toFixed(3)}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json`
|
const apiUrl = (location) => `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,cases7_per_100k&geometry=${location.longitude.toFixed(3)}%2C${location.latitude.toFixed(3)}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json`
|
||||||
|
|
||||||
let widget = await createWidget()
|
let widget = await createWidget()
|
||||||
if (!config.runsInWidget) {
|
if (!config.runsInWidget) {
|
||||||
await widget.presentSmall()
|
await widget.presentSmall()
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.setWidget(widget)
|
Script.setWidget(widget)
|
||||||
Script.complete()
|
Script.complete()
|
||||||
|
|
||||||
async function createWidget(items) {
|
async function createWidget(items) {
|
||||||
let location
|
let location
|
||||||
|
|
||||||
if(args.widgetParameter) {
|
if(args.widgetParameter) {
|
||||||
|
|
||||||
const fixedCoordinates = args.widgetParameter.split(",").map(parseFloat)
|
const fixedCoordinates = args.widgetParameter.split(",").map(parseFloat)
|
||||||
|
|
||||||
location = {
|
location = {
|
||||||
latitude: fixedCoordinates[0],
|
latitude: fixedCoordinates[0],
|
||||||
longitude: fixedCoordinates[1]
|
longitude: fixedCoordinates[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Location.setAccuracyToThreeKilometers()
|
Location.setAccuracyToThreeKilometers()
|
||||||
location = await Location.current()
|
location = await Location.current()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await new Request(apiUrl(location)).loadJSON()
|
const data = await new Request(apiUrl(location)).loadJSON()
|
||||||
|
|
||||||
if(!data || !data.features || !data.features.length) {
|
if(!data || !data.features || !data.features.length) {
|
||||||
const errorList = new ListWidget()
|
const errorList = new ListWidget()
|
||||||
errorList.addText("Keine Ergebnisse für den aktuellen Ort gefunden.")
|
errorList.addText("Keine Ergebnisse für den aktuellen Ort gefunden.")
|
||||||
return errorList
|
return errorList
|
||||||
}
|
}
|
||||||
|
|
||||||
const attr = data.features[0].attributes
|
const attr = data.features[0].attributes
|
||||||
const incidence = attr.cases7_per_100k.toFixed(1)
|
const incidence = attr.cases7_per_100k.toFixed(1)
|
||||||
const cityName = attr.GEN
|
const cityName = attr.GEN
|
||||||
const list = new ListWidget()
|
const list = new ListWidget()
|
||||||
|
|
||||||
if(Device.isUsingDarkAppearance()){
|
if(Device.isUsingDarkAppearance()){
|
||||||
const gradient = new LinearGradient()
|
const gradient = new LinearGradient()
|
||||||
gradient.locations = [0, 1]
|
gradient.locations = [0, 1]
|
||||||
@ -38,11 +50,23 @@ async function createWidget(items) {
|
|||||||
]
|
]
|
||||||
list.backgroundGradient = gradient
|
list.backgroundGradient = gradient
|
||||||
}
|
}
|
||||||
|
|
||||||
const header = list.addText("🦠 Inzidenz".toUpperCase())
|
const header = list.addText("🦠 Inzidenz".toUpperCase())
|
||||||
header.font = Font.mediumSystemFont(13)
|
header.font = Font.mediumSystemFont(13)
|
||||||
|
|
||||||
list.addSpacer()
|
list.addSpacer()
|
||||||
|
|
||||||
const label = list.addText(incidence+"")
|
const label = list.addText(incidence+"")
|
||||||
label.font = Font.boldSystemFont(24)
|
label.font = Font.boldSystemFont(24)
|
||||||
|
label.textColor = Color.green()
|
||||||
|
|
||||||
|
if(incidence >= 50) {
|
||||||
|
label.textColor = Color.red()
|
||||||
|
} else if(incidence >= 35) {
|
||||||
|
label.textColor = Color.orange()
|
||||||
|
}
|
||||||
|
|
||||||
list.addText(cityName)
|
list.addText(cityName)
|
||||||
|
|
||||||
return list
|
return list
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user