Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
document.addEventListener('DOMContentLoaded', async () => {
const loader = document.getElementById('loading-container');
const resultContainer = document.getElementById('result-container');
try {
loader.textContent = 'Loading...';
const getBuienRadarData = async () => {
const response = await fetch('https://data.buienradar.nl/2.0/feed/json');
const data = await response.json();
console.log(data)
return data;
};
const data = await getBuienRadarData();
// Clear loader
loader.textContent = '';
// Display the data
displayWeatherData(data);
} catch (error) {
console.error('Error fetching BuienRadar data:', error);
loader.textContent = '';
resultContainer.textContent = 'Error loading BuienRadar data. Please try again later.';
}
});
function displayWeatherData(data) {
const resultContainer = document.getElementById('result-container');
// Create main sections
const html = `
<div class="weather-container">
<div class="current-weather">
<h2>Current Weather</h2>
<div class="station-grid">
${data.actual.stationmeasurements
.map(station => `
<div class="station-card">
<h3>${station.stationname}</h3>
<img src="${station.fullIconUrl}">
<div class="station-details">
<p>Temperature: ${station.temperature}°C</p>
<p>Feels like: ${station.feeltemperature}°C</p>
<p>Weather: ${station.weatherdescription}</p>
<p>Wind: ${station.windspeed} km/h ${station.winddirection}</p>
<p>Humidity: ${station.humidity}%</p>
</div>
</div>
`).join('')}
</div>
</div>
<div class="forecast">
<h2>5-Day Forecast</h2>
<div class="forecast-grid">
${data.forecast.fivedayforecast
.map(day => `
<div class="forecast-card">
<h3>${new Date(day.day).toLocaleDateString()}</h3>
<img src="${day.iconurl}" alt="${day.weatherdescription}">
<div class="forecast-details">
<p>${day.weatherdescription}</p>
<p>Min: ${day.mintemperature}°C</p>
<p>Max: ${day.maxtemperature}°C</p>
<p>Rain chance: ${day.rainChance}%</p>
<p>Wind: ${day.wind} Bft ${day.windDirection}</p>
</div>
</div>
`).join('')}
</div>
</div>
</div>
`;
resultContainer.innerHTML = html;
}