-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcolorLegendViewScale.html
More file actions
51 lines (45 loc) · 1.6 KB
/
colorLegendViewScale.html
File metadata and controls
51 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<div id="map" style="height: 100%; width: 100%"></div>
<script src="../../dist/gridviz.js"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-color@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-interpolate@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-scale-chromatic@3"></script>
<script>
//define map with initial view
const map = new gridviz.Map(document.getElementById('map'), {
x: 4500000,
y: 2900000,
z: 3000,
}).addZoomButtons()
//define dataset
const dataset = new gridviz.MultiResolutionDataset(
[1000, 2000, 5000, 10000, 20000, 50000, 100000],
(resolution) =>
new gridviz.TiledGrid(
map,
'https://raw.githubusercontent.com/jgaffuri/tiledgrids/main/data/europe/population2/' +
resolution +
'm/'
)
)
//define style
const style = new gridviz.ShapeColorSizeStyle({
color: (c, r, z, viewScale) => viewScale(c.TOT_P_2021),
viewScale: gridviz.viewScaleColor({
valueFunction: (c) => +c.TOT_P_2021,
colorScale: d3.interpolateYlOrRd,
stretching: gridviz.logarithmicScale(-7),
}),
})
//define legend
const legend = new gridviz.ColorLegend({
title: 'Population',
colorScale: d3.interpolateYlOrRd,
ticks: 4,
textScale: (t, vs) => vs?.invert(t),
tickFormat: Math.round,
})
//link legend to style
style.legends = [legend]
//add layer to map
map.layers = [new gridviz.GridLayer(dataset, [style])]
</script>