Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSWeb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSWeb
Commits
5d90418d
Commit
5d90418d
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Render legend from JSON
parent
9843f07b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spatial/static/spatial/js/gridmap.js
+49
-1
49 additions, 1 deletion
spatial/static/spatial/js/gridmap.js
with
49 additions
and
1 deletion
spatial/static/spatial/js/gridmap.js
+
49
−
1
View file @
5d90418d
...
...
@@ -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
=
currentLayer
.
Abstract
;
document
.
getElementById
(
"
layerLegend
"
).
innerHTML
=
getLegendHTML
(
JSON
.
parse
(
currentLayer
.
Abstract
))
;
}
else
// Fallback to auto generated legend
{
...
...
@@ -67,6 +67,54 @@ async function switchLayer(dayIndex)
setCurrentDate
(
dayIndex
);
}
let
legend_tpl
=
`<ul style="list-style: none; padding: 0;">$(legendItems)</ul>`
let
legendItem_tpl
=
`<li style="margin-bottom: 5px;"><span style="background-color: #707070;"> </span> {{language.no_forecast}}</li>`
;
/**
* Build Legend HTML from Json data, for example:
{
"isWarningStatus": true,
"legendItems": [
{
"classification": 0,
"legendLabel": "Flight period ended",
"legendIconCSS": "display: inline-block; background-color: #707070;"
},
{
"classification": 2,
"legendLabel": "Flight period not started",
"legendIconCSS": "display: inline-block; background-color: #00B457;"
},
{
"classification": 3,
"legendLabel": "Flight period starting",
"legendIconCSS": "display: inline-block; background-color: #FFCC00;"
},
{
"classification": 4,
"legendLabel": "Peak flight activity",
"legendIconCSS": "display: inline-block; background-color: #FF0000;"
}
]
}
* @param {JSON} jsonData
* @returns {String} HTML to render as a legend
*/
function
getLegendHTML
(
jsonData
)
{
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
++
)
{
legendHTML
+=
`<li style="margin-bottom: 5px;"><span style="width: 25px;
${
jsonData
.
legendItems
[
i
].
legendIconCSS
}
"> </span>
${
jsonData
.
legendItems
[
i
].
legendLabel
}
</li>`
;
}
legendHTML
+=
`<ul>`
;
return
legendHTML
;
}
/**
* Given the timeseries index, figure out which date it is and display in the time slider
* @param {Integer} layerIndex
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment