diff --git a/spatial/static/spatial/js/gridmap.js b/spatial/static/spatial/js/gridmap.js index e9f2bdd73672e673970c95fb87bb161fff1a1f2a..3ebe69bed030bb088d31c3a184af0ca44f99f279 100644 --- a/spatial/static/spatial/js/gridmap.js +++ b/spatial/static/spatial/js/gridmap.js @@ -56,7 +56,7 @@ async function switchLayer(dayIndex) // See if there is a language specific legend available if(currentLayer.Abstract != undefined) { - document.getElementById("layerLegend").innerHTML= getLegendHTML(JSON.parse(currentLayer.Abstract)); + document.getElementById("layerLegend").innerHTML= getLegendHTML(currentLayer.Abstract); } else // Fallback to auto generated legend { @@ -95,20 +95,28 @@ async function switchLayer(dayIndex) } ] } - * @param {JSON} jsonData + * @param {String} jsonDataStr (could be other, e.g. HTML) * @returns {String} HTML to render as a legend */ -function getLegendHTML(jsonData) +function getLegendHTML(jsonDataStr) { - console.info(jsonData); - // Using Template literals (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) - let legendHTML = `<ul style="list-style: none; padding: 0;">`; - for(var i=0;i<jsonData.legendItems.length; i++) + try { - legendHTML += `<li style="margin-bottom: 5px;"><span style="width: 25px; ${jsonData.legendItems[i].legendIconCSS}"> </span> ${jsonData.legendItems[i].legendLabel}</li>`; + let jsonData = JSON.parse(jsonDataStr); + // Using Template literals (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) + let legendHTML = `<ul style="list-style: none; padding: 0;">`; + for(var i=0;i<jsonData.legendItems.length; i++) + { + legendHTML += `<li style="margin-bottom: 5px;"><span style="width: 25px; ${jsonData.legendItems[i].legendIconCSS}"> </span> ${jsonData.legendItems[i].legendLabel}</li>`; + } + legendHTML += `<ul>`; + return legendHTML; + } + catch(e) + { + // Don't know what to do with the string, return as-is + return jsonDataStr; } - legendHTML += `<ul>`; - return legendHTML; } /** @@ -361,6 +369,7 @@ async function displayQueryResult(evt) let currentWMSLayer = WMSLayersDateBucket[currentTimestamp][currentParameter]; + console.info(currentWMSLayer.Abstract); // Need to get all layers for today, and combine results from querying all layers let layersForCurrentTimestamp = getLayersForCurrentTimestamp();