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

Multiparam organizing works

parent f034e7df
No related branches found
No related tags found
No related merge requests found
...@@ -7,19 +7,24 @@ let layers = []; ...@@ -7,19 +7,24 @@ let layers = [];
let mapserverURL="https://testvips.nibio.no/cgi-bin/"; let mapserverURL="https://testvips.nibio.no/cgi-bin/";
let modelId = "SEPTREFHUM"; let modelId = "SEPTREFHUM";
let today = "2023-10-14"; let today = "2023-04-10";
let todayLayerIndex = undefined; let todayLayerIndex = undefined;
let timestamps = undefined; let timestamps = undefined;
let currentParameter = "WARNING_STATUS";
let WMSLayersDateBucket = {};
function switchLayer(visibleLayerIndex) function switchLayer(dayIndex)
{ {
console.info("==>" + visibleLayerIndex); console.info("==>" + dayIndex);
currentTimestamp = timestamps[dayIndex];
currentLayer = WMSLayersDateBucket[currentTimestamp][currentParameter];
currentLayerOrdering = currentLayer["ordering"];
for(let i=0;i<layers.length;i++) for(let i=0;i<layers.length;i++)
{ {
console.info(i) console.info(i)
layers[i].setVisible(i==visibleLayerIndex); layers[i].setVisible(i==currentLayerOrdering);
} }
setCurrentDate(visibleLayerIndex); setCurrentDate(dayIndex);
} }
function setCurrentDate(layerIndex) function setCurrentDate(layerIndex)
...@@ -48,18 +53,20 @@ async function initSlidingMap(lonLat, zoomLevel, mapAttribution) { ...@@ -48,18 +53,20 @@ async function initSlidingMap(lonLat, zoomLevel, mapAttribution) {
let result = parser.read(await response.text()); let result = parser.read(await response.text());
let WMSLayers = result.Capability.Layer.Layer; let WMSLayers = result.Capability.Layer.Layer;
// Analyze layers // Analyze and organize layers
let WMSLayersDateBucket = {};
for(let i=0;i<WMSLayers.length;i++){ for(let i=0;i<WMSLayers.length;i++){
// Get only WARNING_STATUS layers for now
// Sort by date ascending // Sort by date ascending
WMSLayerName = WMSLayers[i].Name; let WMSLayerName = WMSLayers[i].Name;
if(WMSLayerName.split(".")[1] == "WARNING_STATUS") let WMSLayerParam = WMSLayerName.split(".")[1]
let timestamp = moment(WMSLayerName.split(".")[2]).valueOf();
if(WMSLayersDateBucket[timestamp] == undefined)
{ {
WMSLayersDateBucket[moment(WMSLayerName.split(".")[2]).valueOf()] = WMSLayers[i]; WMSLayersDateBucket[timestamp] = {}
} }
WMSLayersDateBucket[timestamp][WMSLayerParam] = WMSLayers[i];
} }
//console.info(WMSLayersDateBucket);
timestamps = Object.keys(WMSLayersDateBucket); timestamps = Object.keys(WMSLayersDateBucket);
...@@ -71,23 +78,29 @@ async function initSlidingMap(lonLat, zoomLevel, mapAttribution) { ...@@ -71,23 +78,29 @@ async function initSlidingMap(lonLat, zoomLevel, mapAttribution) {
let dateStr = moment(parseInt(timestamps[i])).format("YYYY-MM-DD"); let dateStr = moment(parseInt(timestamps[i])).format("YYYY-MM-DD");
if(dateStr == today) if(dateStr == today)
{ {
console.info("YESS: " + i);
todayLayerIndex = i; todayLayerIndex = i;
} }
let timestampLayers = WMSLayersDateBucket[timestamps[i]];
layers.push( let params = Object.keys(timestampLayers);
new ol.layer.Image({ for(let j=0; j<params.length;j++)
source: new ol.source.ImageWMS({ {
url: mapserverURL + modelId, let currentLayer = timestampLayers[params[j]];
params: { "LAYERS": modelId + ".WARNING_STATUS." + dateStr, "TRANSPARENT": "TRUE" }, let currentLayerParam = currentLayer.Name.split(".")[1];
serverType: "mapserver", layers.push(
ratio: 1, new ol.layer.Image({
projection: ol.proj.get("EPSG:25833") source: new ol.source.ImageWMS({
}), url: mapserverURL + modelId,
visible: (i==todayLayerIndex), params: { "LAYERS": modelId + "." + currentLayerParam + "." + dateStr, "TRANSPARENT": "TRUE" },
opacity: 0.5 serverType: "mapserver",
}) ratio: 1,
); projection: ol.proj.get("EPSG:25833")
}),
visible: false,
opacity: 0.5
})
);
currentLayer["ordering"] = layers.length -1;
}
} }
let range = document.getElementById("layerDateRange"); let range = document.getElementById("layerDateRange");
...@@ -95,8 +108,9 @@ async function initSlidingMap(lonLat, zoomLevel, mapAttribution) { ...@@ -95,8 +108,9 @@ async function initSlidingMap(lonLat, zoomLevel, mapAttribution) {
range.max = timestamps.length -1; range.max = timestamps.length -1;
range.value = todayLayerIndex; range.value = todayLayerIndex;
setCurrentDate(todayLayerIndex); setCurrentDate(todayLayerIndex);
switchLayer(todayLayerIndex);
//console.info(WMSLayersDateBucket);
// Creating the map // Creating the map
map = new ol.Map({ map = new ol.Map({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment