Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fordecyt_2019
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rodrigo Tapia-McClung
fordecyt_2019
Commits
ca26ff5f
Commit
ca26ff5f
authored
Aug 28, 2019
by
Rodrigo Tapia-McClung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add legend to map
parent
3a51ff91
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
9 deletions
+35
-9
grijalva_functions.js
public/js/grijalva_functions.js
+35
-9
No files found.
public/js/grijalva_functions.js
View file @
ca26ff5f
...
...
@@ -24,13 +24,15 @@ let timeParse,
glmap
,
osmLayer
,
cartoLightLayer
,
cartoDarkLayer
,
timeLayer
,
layerControl
;
layerControl
,
scale
;
// define empty objects and indicators
let
maxIndicators
=
{},
minIndicators
=
{},
indicators
=
[
"area"
,
"perimeter"
,
"costa"
,
"df"
],
indicatorsNames
=
[
"Área"
,
"Perímetro"
,
"Desarrollo de la línea de costa"
,
"Dimensión fractal"
];
indicatorsNames
=
[
"Área"
,
"Perímetro"
,
"Desarrollo de la línea de costa"
,
"Dimensión fractal"
],
indicatorsUnits
=
[
"m
\
u00B2"
,
"m"
,
""
,
""
];
let
cols
=
[];
indicators
.
forEach
(
(
indicator
)
=>
{
...
...
@@ -359,7 +361,8 @@ const updateMap = (mapData) => {
let
option
=
$
(
"#indicatorSelect"
).
val
(),
// option selected from dropdrown
min
=
values
.
minIndicators
,
max
=
values
.
maxIndicators
;
styleTiles
(
option
,
min
,
max
);
styleTiles
(
option
,
min
,
max
)
.
then
(
legend
.
addTo
(
map
));
// add legend control -> it updates
//TODO: update charts
});
...
...
@@ -422,7 +425,8 @@ const populateMap = (mapData) => {
// style currentTiles
let
option
=
$
(
"#indicatorSelect"
).
val
();
// option selected from dropdrown
styleTiles
(
option
,
minIndicators
,
maxIndicators
);
styleTiles
(
option
,
minIndicators
,
maxIndicators
)
.
then
(
legend
.
addTo
(
map
));
// add legend control -> it updates
let
baseLayers
=
{
"Carto Dark"
:
cartoDarkLayer
,
...
...
@@ -596,8 +600,8 @@ L.timeDimension.layer.Tile = (layer, options) => {
$
(
"#indicatorSelect"
).
on
(
"change"
,
function
()
{
// style currentTiles
let
option
=
this
.
value
;
// option selected from dropdrown
styleTiles
(
option
,
minIndicators
,
maxIndicators
)
;
//
.then(legend.addTo(map)); // add legend control -> it updates
styleTiles
(
option
,
minIndicators
,
maxIndicators
)
.
then
(
legend
.
addTo
(
map
));
// add legend control -> it updates
// FIXME: re-adding control updates its contents... why?
// Highlight plot title according to selected option
//indicators.forEach( indicator => {
...
...
@@ -609,7 +613,7 @@ const styleTiles = (option, minIndicators, maxIndicators) => {
// define color scale domain based on min-max values for selected indicator
let
domain
=
[
minIndicators
[
option
],
maxIndicators
[
option
]];
//console.log(domain)
let
scale
=
chroma
.
scale
(
"PuBu"
).
padding
([
0.5
,
0
]).
domain
(
domain
).
classes
(
5
);
scale
=
chroma
.
scale
(
"PuBu"
).
padding
([
0.5
,
0
]).
domain
(
domain
).
classes
(
5
);
Object
.
keys
(
currentTiles
).
forEach
(
layer
=>
{
let
color
=
[
'interpolate'
,
...
...
@@ -623,5 +627,27 @@ const styleTiles = (option, minIndicators, maxIndicators) => {
return
Promise
.
resolve
(
scale
);
}
// TODO: add layer control
let
legend
=
L
.
control
({
position
:
"bottomright"
});
legend
.
onAdd
=
()
=>
{
let
div
=
L
.
DomUtil
.
create
(
"div"
,
"info legend leaflet-bar"
);
let
option
=
$
(
"#indicatorSelect"
).
val
();
let
optionIndex
=
indicators
.
indexOf
(
option
);
let
legendText
=
indicatorsUnits
[
optionIndex
]
==
""
?
indicatorsNames
[
optionIndex
]
:
indicatorsNames
[
optionIndex
]
+
" ("
+
indicatorsUnits
[
optionIndex
]
+
")"
;
var
html
=
"<h6>"
+
legendText
+
"</h6><ul>"
;
let
classes
=
scale
.
classes
();
classes
.
forEach
(
(
c
,
idx
,
array
)
=>
{
if
(
idx
!=
array
.
length
-
1
)
{
html
+=
"<li><i style=
\"
background:"
+
scale
(
c
).
hex
()
+
"
\"
></i> "
+
" "
+
d3
.
format
(
",.4~s"
)(
classes
[
idx
])
+
" - "
+
d3
.
format
(
",.4~s"
)(
classes
[
idx
+
1
])
+
"</li>"
;
}
});
html
+=
"</ul>"
;
div
.
innerHTML
=
html
;
return
div
;
};
// TODO: add charts
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment