From f3ba7a4855c1c664abb625342d789ac044f7cc96 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Wed, 6 Sep 2023 13:13:26 +0200 Subject: [PATCH] Check that gridded datasources cover the selected location --- ipmd/static/ipmd/js/ipmdlib.js | 3 +-- ipmd/templates/ipmd/saddlegallmidgeform.html | 23 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ipmd/static/ipmd/js/ipmdlib.js b/ipmd/static/ipmd/js/ipmdlib.js index 8536862f..3c40f2ca 100644 --- a/ipmd/static/ipmd/js/ipmdlib.js +++ b/ipmd/static/ipmd/js/ipmdlib.js @@ -176,7 +176,7 @@ async function getLocationWeatherData(endpoint, longitude, latitude, parameters, + "&latitude=" + latitude + "¶meters=" + parameters.join(",") ); - return await response.json(); + return (response.status == 200) ? await response.json() : null; } /** @@ -295,7 +295,6 @@ async function isPointCoveredByDatasource(coordinate, datasource) return true; } let geoJson = await getDatasourceFeatures(JSON.parse(datasource.spatial.geoJSON), datasource.spatial.countries); - console.info(geoJson); let retVal = false; for(let i=0; i<geoJson.features.length;i++) { diff --git a/ipmd/templates/ipmd/saddlegallmidgeform.html b/ipmd/templates/ipmd/saddlegallmidgeform.html index 91835603..932fc31c 100644 --- a/ipmd/templates/ipmd/saddlegallmidgeform.html +++ b/ipmd/templates/ipmd/saddlegallmidgeform.html @@ -355,6 +355,12 @@ else { coordinate = getLatLon(); + // Need to check that the selected datasource covers the requested location + if(! await isPointCoveredByDatasource(coordinate, currentWeatherDatasource)) + { + alert("ERROR: The selected historic datasource does not cover your selected location. Please select an appropriate location or datasource."); + return; + } weatherData = await getLocationWeatherData( getWeatherDatasourceEndpoint(currentWeatherDatasource), coordinate[0], @@ -379,6 +385,12 @@ // 2. Forecast weather data if(currentForecastWeatherDatasource != undefined) { + // Need to check that the selected datasource covers the requested location + if(! await isPointCoveredByDatasource(coordinate, currentForecastWeatherDatasource)) + { + alert("ERROR: The selected forecast datasource does not cover your selected location. Please select an appropriate location or datasource."); + return; + } forecastData = await getLocationWeatherData( getWeatherDatasourceEndpoint(currentForecastWeatherDatasource), document.getElementById("longitude").value, @@ -408,8 +420,15 @@ weatherData = mergeWeatherData(weatherData, forecastData); } } - - inputData["weatherData"] = weatherData; + if(weatherData != null) + { + inputData["weatherData"] = weatherData; + } + else + { + alert("ERROR: Could not get weather data. Please check if your datasource covers your location."); + return; + } } // Ready to call server? let result = mockResult; -- GitLab