...
Code Block | ||
---|---|---|
| ||
<script> var stationLocation = "Meetstation De Bilt"; var attributes = ["rainFallLast24Hour", "temperature", "weatherdescription"]; fetch('https://data.buienradar.nl/2.0/feed/json').then(function (response) { return response.json(); }).then(function (json) { return getWeatherData(json); }); function getWeatherData(wjson) { var stations = wjson.actual.stationmeasurements; var stationData = stations.find(function (station) { return station.stationname == stationLocation; }); if (stationData) { var sqEvent = {}; sqEvent.event = "WeatherUpdate"; attributes.forEach(function (weatherattribute) { if (stationData[weatherattribute] !== undefined) { var sqAttribute = "custom_" + weatherattribute.toLowerCase(); sqEvent[sqAttribute] = stationData[weatherattribute]; } }); window._sqzl.push(sqEvent); } } </script> |
Via Squeezely personalisatie
...
Code Block | ||
---|---|---|
| ||
{{cssPrefix}} {
display: none !important;
} |
Info |
---|
Als de personalisatie niet kan renderen, voeren we de Javascript ook niet uit. Je moet dus een werkende queryselector selecteren. |
...
Code Block |
---|
let stationLocation = "Meetstation De Bilt"; let attributes = ["rainFallLast24Hour", "temperature", "weatherdescription"]; fetch('https://data.buienradar.nl/2.0/feed/json') .then((response) => response.json()) .then((json) => getWeatherData(json)); function getWeatherData(wjson) { let stations = wjson.actual.stationmeasurements; let stationData = stations.find(station => station.stationname == stationLocation); if (stationData) { let sqEvent = {}; sqEvent.event = "WeatherUpdate"; attributes.forEach((weatherattribute) => { if (stationData[weatherattribute] !== undefined) { let sqAttribute = "custom_" + weatherattribute.toLowerCase(); sqEvent[sqAttribute] = stationData[weatherattribute]; } }); window._sqzl.push(sqEvent); } } |
Eventvelden en personalisatie voorwaarden aanmaken
...