Skip to content
Snippets Groups Projects

feat: Add test page (spatial) with mapserver layer in openlayers map

Merged Lene Wasskog requested to merge feature/gridv-6-mapserver-layer into develop
2 files
+ 64
22
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -20,6 +20,7 @@
/**
* Dependencies:
* momentJS
* turf v6
*/
const ipmdDSSApiURL = "https://platform.ipmdecisions.net/api/dss/";
@@ -190,6 +191,26 @@ function getPragmaticWeatherParameterList(requestedParameters, availableParamete
}
async function isPointCoveredByDatasource(coordinate, datasource)
{
// If the geoJson is {"type":"Sphere"}, return true
if(datasource.spatial.geoJSON != null && JSON.parse(datasource.spatial.geoJSON).type.toLowerCase() == "sphere")
{
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++)
{
if(turf.booleanPointInPolygon(coordinate, geoJson.features[i]))
{
retVal = true;
}
}
return retVal;
}
/**
* Displays the weather data in a table
* @param {Object} weatherData the weatherData in IPM Decisions format
@@ -439,25 +460,14 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList, featureC
let features = new ol.Collection();
let format = new ol.format.GeoJSON();
let drawnFeatures = undefined;
// If we have geoJson available, we display that
if (geoJson != null && geoJson.features.length > 0) {
drawnFeatures = format.readFeatures(geoJson, {
dataProjection: 'EPSG:4326',
featureProjection: map.getView().getProjection().getCode()
});
}
// 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);
//console.info(countryBoundaries);
drawnFeatures = await format.readFeatures(countryBoundaries, {
let drawnFeatures = await format.readFeatures(
await getDatasourceFeatures(geoJson, countryCodeList),
{
dataProjection: 'EPSG:4326',
featureProjection: map.getView().getProjection().getCode()
});
}
}
);
let featureOverlay = undefined;
@@ -513,6 +523,22 @@ async function initDataSourceMap(containerId, geoJson, countryCodeList, featureC
});
}
/**
* Get "complete" spatial info from weather datasource, using either provided GeoJson or
* inferred from list of countries
* @param {JSON} geoJson
* @param {Array} countryCodeList
* @returns {Json} GeoJson
*/
async function getDatasourceFeatures(geoJson, countryCodeList)
{
// If we have geoJson available, we display that
if (geoJson != null && geoJson.features !== undefined && geoJson.features.length > 0) {
return geoJson;
}
return await getCountryBoundaries(countryCodeList);
}
const styleUnselected = new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(173, 173, 173, 0.5)'
@@ -580,6 +606,10 @@ function getDecimalDegrees(map, coordinate)
async function getCountryBoundaries(countryCodeList)
{
if(countryCodeList == undefined || countryCodeList == null)
{
return {};
}
const response = await fetch(ipmdWeatherApiURL + "rest/country/" + countryCodeList.join(","));
return await response.json();
}
Loading