From 55dc4ee08f4177e54cd5d65caa7f020ed8fe64ea Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Fri, 9 Feb 2024 13:29:42 +0100 Subject: [PATCH] Get title and abstract from GeoServer WMS (one level below Mapserver's) --- spatial/static/spatial/js/gridmap.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/spatial/static/spatial/js/gridmap.js b/spatial/static/spatial/js/gridmap.js index a2a9c3e0..072578d8 100644 --- a/spatial/static/spatial/js/gridmap.js +++ b/spatial/static/spatial/js/gridmap.js @@ -182,7 +182,9 @@ async function initGridMap(inputModelId, wmsURL, mapAttribution) { // Get layers from WMS service let parser = new ol.format.WMSCapabilities(); //console.info(mapserverURL + modelId + "?service=WMS&version=1.3.0&request=GetCapabilities"); - let response = await fetch(wmsURL + "?service=WMS&version=1.3.0&request=GetCapabilities&language=" + settings.currentLanguage); + //let response = await fetch(wmsURL + "?service=WMS&version=1.3.0&request=GetCapabilities&language=" + settings.currentLanguage); + let response = await fetch(wmsURL + "?service=WMS&request=GetCapabilities"); + //console.info(wmsURL + "?service=WMS&request=GetCapabilities&language=en"); //console.info(response.status); // Response is 200 even if a model doesn't exist on the mapserver let txt = await response.text(); @@ -202,12 +204,24 @@ async function initGridMap(inputModelId, wmsURL, mapAttribution) { WMSLayers = WMSLayers[0].Layer; } //console.info(WMSLayers); - - document.getElementById("modelTitle").innerHTML = capabilities.Service.Title; - if(capabilities.Service.Abstract != undefined) + //console.info(capabilities); + // Get title and abstract. Could be either at top level or the level below + let modelTitle = capabilities.Service.Title; + let modelAbstract = undefined; + if(modelTitle != undefined && modelTitle.trim() != "") + { + modelAbstract = capabilities.Service.Abstract; + } + else + { + modelTitle = capabilities.Capability.Layer.Layer[0].Title; + modelAbstract = capabilities.Capability.Layer.Layer[0].Abstract; + } + document.getElementById("modelTitle").innerHTML = modelTitle; + if(modelAbstract != undefined) { // Placing the sections above/below the map - let el = new DOMParser().parseFromString(capabilities.Service.Abstract.replaceAll("\n\n",""),"text/html"); + let el = new DOMParser().parseFromString(modelAbstract.replaceAll("\n\n",""),"text/html"); let preamble = el.getElementById("preamble") != null ? el.getElementById("preamble") : el; document.getElementById("modelAbstractPreamble").innerHTML = new XMLSerializer().serializeToString(preamble); let body = el.getElementById("body") != null ? el.getElementById("body") : null; -- GitLab