Skip to content
Snippets Groups Projects
Commit feedcb28 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Refactor function renderWEatherData out to ipmdblib.js

parent 61c62d6e
No related branches found
No related tags found
2 merge requests!13Saddlegallmidge form idec 372,!12feat: Add test page (spatial) with mapserver layer in openlayers map
......@@ -190,6 +190,34 @@ function getPragmaticWeatherParameterList(requestedParameters, availableParamete
}
/**
* Displays the weather data in a table
* @param {Object} weatherData the weatherData in IPM Decisions format
* @param {HTMLElement} container the element to render to
* @param {String} tableClass for styling the table, e.g. using Bootstrap
*/
function renderWeatherData(weatherData, container, tableClass){
let dates = getDateArray(weatherData.timeStart, weatherData.interval, weatherData.locationWeatherData[0].length);
let html = "<table" + (tableClass != undefined ? " class=\"" + tableClass + "\"" : "") + "><thead><tr><th>Time</th>";
weatherData.weatherParameters.forEach(function(weatherParameterId){
html +="<th>" + getWeatherParameter(weatherParameterId).name + "</th>";
});
html += "</tr></thead>"
html += "<tbody>";
//console.info("Weatherdata length: " + weatherData.locationWeatherData[0].data.length);
for(let i=0;i< weatherData.locationWeatherData[0].data.length;i++)
{
html += "<tr><td>" + moment(dates[i]).format("YYYY-MM-DD HH:mm:ss") + "</td>";
weatherData.locationWeatherData[0].data[i].forEach(function(val){html+="<td>" + val + "</td>";})
html += "</tr>";
}
html += "</tbody>";
html += "</table>";
container.innerHTML = html;
}
/**
* Merges the two datasets. Keeping the primaryData if both sets have data for same time and parameter
* If a merge operation is not possible, primaryData is returned unchanged
......@@ -364,15 +392,14 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList)
map = null;
}
//console.info(countryCodeList);
//console.info(geoJson);
// If no data, no map
if((geoJson == undefined || geoJson == null || geoJson.features.length == 0) && (countryCodeList == null || countryCodeList.length == 0))
{
document.getElementById(containerId).innerHTML = "NO GEODATA PROVIDED BY WEATHER DATA SOURCE";
return;
}
else{
else
{
document.getElementById(containerId).innerHTML = "";
}
......@@ -398,8 +425,8 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList)
// center to correct map projection)
var view = new ol.View({
center: ol.proj.transform([10,65], 'EPSG:4326', map.getView().getProjection().getCode()),
zoom: 7,
maxZoom: 7
zoom: 7//,
//maxZoom: 7
});
map.setView(view);
......@@ -416,7 +443,6 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList)
});
}
// If not, we have to get geoJson mapped to the countries
else if (countryCodeList != undefined && countryCodeList != null && countryCodeList.length > 0) {
let countryBoundaries = await getCountryBoundaries(countryCodeList);
......@@ -429,16 +455,18 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList)
if(drawnFeatures != undefined)
{
//console.info(drawnFeatures);
// Create an empty layer
var featureOverlay = new ol.layer.Vector({
source: new ol.source.Vector({
features: features
})
});
// Add the stations or area
featureOverlay.getSource().addFeatures(drawnFeatures);
featureOverlay.setMap(map);
// Fit the features to the extent of the map
extent = featureOverlay.getSource().getExtent();
map.getView().fit(extent, map.getSize());
}
......
......@@ -380,28 +380,6 @@
renderWeatherData(weatherData, document.getElementById("weatherData"), "table table-striped")
}
function renderWeatherData(weatherData, container, tableClass){
let dates = getDateArray(weatherData.timeStart, weatherData.interval, weatherData.locationWeatherData[0].length);
let html = "<table" + (tableClass != undefined ? " class=\"" + tableClass + "\"" : "") + "><thead><tr><th>Time</th>";
weatherData.weatherParameters.forEach(function(weatherParameterId){
html +="<th>" + getWeatherParameter(weatherParameterId).name + "</th>";
});
html += "</tr></thead>"
html += "<tbody>";
//console.info("Weatherdata length: " + weatherData.locationWeatherData[0].data.length);
for(let i=0;i< weatherData.locationWeatherData[0].data.length;i++)
{
html += "<tr><td>" + moment(dates[i]).format("YYYY-MM-DD HH:mm:ss") + "</td>";
weatherData.locationWeatherData[0].data[i].forEach(function(val){html+="<td>" + val + "</td>";})
html += "</tr>";
}
html += "</tbody>";
html += "</table>";
container.innerHTML = html;
}
// Mock result!!! Waiting for ADAS to fix CORS issue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment