-
-
Save pichfl/fabd10f8ce9791d0613410ac460bc404 to your computer and use it in GitHub Desktop.
COVID-19 Inzidenz-Widget für iOS innerhalb Deutschlands 🇩🇪 - Ich empfehle die Nutzung des Originals! https://gist.github.com/kevinkub/46caebfebc7e26be63403a7f0587f664
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Forked from Keven Kub. | |
// See https://gist.github.com/kevinkub/46caebfebc7e26be63403a7f0587f664 | |
// Licence: Robert Koch-Institut (RKI), dl-de/by-2-0 | |
const apiUrl = ({ longitude, latitude }) => | |
`https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,cases7_per_100k&geometry=${longitude.toFixed( | |
3 | |
)}%2C${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() { | |
let location; | |
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('Keine Ergebnisse für den aktuellen Ort gefunden.'); | |
return errorList; | |
} | |
const attr = data.features[0].attributes; | |
const incidence = attr.cases7_per_100k.toFixed(1); | |
const cityName = attr.GEN; | |
const list = new ListWidget(); | |
const bgGradient = new LinearGradient(); | |
bgGradient.locations = [0, 1]; | |
bgGradient.colors = Device.isUsingDarkAppearance() | |
? [new Color('111'), new Color('222')] | |
: [new Color('fff'), new Color('fafafa')]; | |
list.backgroundGradient = bgGradient; | |
const header = list.addText('🦠 Inzidenz'.toUpperCase()); | |
header.font = Font.mediumSystemFont(13); | |
header.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black(); | |
list.addSpacer(); | |
const label = list.addText(incidence + ''); | |
label.font = Font.boldSystemFont(24); | |
label.textColor = Color.green(); | |
if (incidence >= 50) { | |
label.textColor = Color.red() | |
} else if(incidence >= 35) { | |
label.textColor = Color.orange() | |
} | |
let text = list.addText(cityName); | |
text.textOpacity = 0.5; | |
text.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black(); | |
return list; | |
} |
@schmiddi2908 ja ist möglich. Für eine Anleitung schau am besten in das Original dieses Widgets. Im Endeffekt musst du die Koordinaten in den Widget-Einstellungen auf deinem Homescreen ergänzen.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gibt es eine Möglichkeit, den Ort fest zu hinterlegen?