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
f11e008e
Commit
f11e008e
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Parse JSON string safely
parent
f9c85a8a
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
+19
-10
19 additions, 10 deletions
spatial/static/spatial/js/gridmap.js
with
19 additions
and
10 deletions
spatial/static/spatial/js/gridmap.js
+
19
−
10
View file @
f11e008e
...
@@ -56,7 +56,7 @@ async function switchLayer(dayIndex)
...
@@ -56,7 +56,7 @@ async function switchLayer(dayIndex)
// See if there is a language specific legend available
// See if there is a language specific legend available
if
(
currentLayer
.
Abstract
!=
undefined
)
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
else
// Fallback to auto generated legend
{
{
...
@@ -95,20 +95,28 @@ async function switchLayer(dayIndex)
...
@@ -95,20 +95,28 @@ async function switchLayer(dayIndex)
}
}
]
]
}
}
* @param {
JSON
} jsonData
* @param {
String
} jsonData
Str (could be other, e.g. HTML)
* @returns {String} HTML to render as a legend
* @returns {String} HTML to render as a legend
*/
*/
function
getLegendHTML
(
jsonData
)
function
getLegendHTML
(
jsonData
Str
)
{
{
console
.
info
(
jsonData
);
try
// 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>`
;
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)
...
@@ -361,6 +369,7 @@ async function displayQueryResult(evt)
let
currentWMSLayer
=
WMSLayersDateBucket
[
currentTimestamp
][
currentParameter
];
let
currentWMSLayer
=
WMSLayersDateBucket
[
currentTimestamp
][
currentParameter
];
console
.
info
(
currentWMSLayer
.
Abstract
);
// Need to get all layers for today, and combine results from querying all layers
// Need to get all layers for today, and combine results from querying all layers
let
layersForCurrentTimestamp
=
getLayersForCurrentTimestamp
();
let
layersForCurrentTimestamp
=
getLayersForCurrentTimestamp
();
...
...
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