COVID-19 Inzidenz-Widget für iOS innerhalb Deutschlands 🇩🇪
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: cyan; icon-glyph: magic; | |
// Licence: Robert Koch-Institut (RKI), dl-de/by-2-0 | |
const fields = ['GEN', 'cases7_per_100k', 'county', 'BEZ']; | |
const apiUrl = (location) => { | |
return `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=${fields.join(',')}&geometry=${location.longitude.toFixed( | |
3 | |
)}%2C${location.latitude.toFixed( | |
3 | |
)}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json`; | |
}; | |
const widget = await createWidget(); | |
if (!config.runsInWidget) { | |
await widget.presentSmall(); | |
} | |
Script.setWidget(widget); | |
Script.complete(); | |
async function createWidget(items) { | |
const colorMap = [ | |
{ | |
min: 0, | |
colors: [new Color("01ff70"), new Color("2ecc40")] | |
}, | |
{ | |
min: 35, | |
colors: [new Color("ff4400"), new Color("ff851b")] | |
}, | |
{ | |
min: 50, | |
colors: [new Color("dd6644"), new Color("ff4136")] | |
}, | |
{ | |
min: 100, | |
colors: [new Color("85144b"), new Color("800000")] | |
}, | |
{ | |
min: 200, | |
colors: [new Color("9f5fec"), new Color("8848d5")] | |
}, | |
{ | |
min: 500, | |
colors: [new Color("624b80"), new Color("534762")] | |
}, | |
]; | |
if (args.widgetParameter) { | |
const fixedCoordinates = args.widgetParameter.split(",").map(parseFloat); | |
location = { | |
latitude: fixedCoordinates[0], | |
longitude: fixedCoordinates[1], | |
}; | |
} else { | |
Location.setAccuracyToThreeKilometers(); | |
location = await Location.current(); | |
} | |
const data = await new Request(apiUrl(location)).loadJSON(); | |
if (!data || !data.features || !data.features.length) { | |
const errorList = new ListWidget(); | |
errorList.addText("Keinen Inzidenzwert für den aktuellen Ort gefunden."); | |
return errorList; | |
} | |
const { | |
GEN: cityName, | |
BEZ: countyType, | |
cases7_per_100k: incidence, | |
} = data.features[0].attributes; | |
const list = new ListWidget(); | |
const textColor = Color.white(); | |
const headerLabel = list.addText("7-Tage-Inzidenz"); | |
headerLabel.font = Font.mediumSystemFont(13); | |
headerLabel.textColor = textColor; | |
list.addSpacer(); | |
const incidenceLabel = list.addText(incidence.toFixed(1)); | |
incidenceLabel.font = Font.boldSystemFont(24); | |
incidenceLabel.textColor = textColor; | |
const cityLabel = list.addText(cityName); | |
cityLabel.textColor = textColor; | |
const countryTypeLabel = list.addText(countyType); | |
countryTypeLabel.font = Font.mediumSystemFont(10); | |
countryTypeLabel.textColor = textColor; | |
const gradient = new LinearGradient(); | |
gradient.locations = [0, 1]; | |
colorMap.forEach(({ min, colors }) => { | |
if (min <= incidence) { | |
gradient.colors = colors; | |
} | |
}); | |
list.backgroundGradient = gradient; | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment