-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwidthQuantileLegendViewScale.html
More file actions
53 lines (48 loc) · 1.7 KB
/
widthQuantileLegendViewScale.html
File metadata and controls
53 lines (48 loc) · 1.7 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
52
53
<div id="map" style="height: 100%; width: 100%"></div>
<script src="../../dist/gridviz.js"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-array@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-format@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/'
),
{ preprocess: (cell) => +cell.TOT_P_2021 > 0 }
)
//define style
const classNumber = 5
const style = new gridviz.SegmentStyle({
width: (cell, resolution, z, viewScale) => viewScale(cell.TOT_P_2021),
viewScale: gridviz.viewScaleQuantile({
valueFunction: (c) => +c.TOT_P_2021,
classNumber: classNumber,
minSizePix: 1,
maxSizeFactor: 0.8,
}),
orientation: () => 0,
color: () => 'black',
length: (cell, resolution) => resolution,
})
//define legends
style.legends = gridviz.sizeDiscreteViewScaleLegend(classNumber, {
title: 'Population',
shape: 'line',
color: 'black',
length: (resolution) => 2 * resolution,
labelFormat: Math.round,
})
//add layer to map
map.layers = [new gridviz.GridLayer(dataset, [style], { minPixelsPerCell: 6 })]
</script>