-
Notifications
You must be signed in to change notification settings - Fork 9
/
pillar_simple.html
56 lines (46 loc) · 2.17 KB
/
pillar_simple.html
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
54
55
56
<div id="map" style="height: 500px; width: 800px"></div>
<script src="../../dist/gridviz.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gridviz-eurostat@2.0.0"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-array@3"></script>
<script>
//define map with initial view
const map = new gridviz.Map(document.getElementById('map'), { x: 4500000, y: 2900000, z: 1500, backgroundColor: '#F3FBFF' })
.addZoomButtons()
//define multi resolution 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 style = new gridviz.PillarStyle({
viewScale: (cells) => d3.max(cells, cell => +cell.TOT_P_2021),
height: (cell, resolution, z, max) => 300 * z * cell.TOT_P_2021 / max,
simple: () => true,
color: () => '#FF3D12aa',
viewHeightFactor: 5,
width: (cell, resolution) => 0.3 * resolution,
viewSX: -0.7,
viewSY: -3,
shadowDirection: (21 * Math.PI) / 180.0,
shadowFactor: 0.5,
})
//define grid layer
const gridLayer = new gridviz.GridLayer(dataset, [style], {
minPixelsPerCell: 6,
cellInfoHTML: (c) => '<b>' + c.TOT_P_2021 + '</b> inhabitant(s)',
})
//define background layer
const backgroundLayer = new gridviz.BackgroundLayer({
url: 'https://raw.githubusercontent.com/jgaffuri/mbxyz/main/pub/elevation_shading/',
resolutions: Array.from({ length: 9 }, (_, i) => 28.00132289714475 * Math.pow(2, 10 - i)),
origin: [0, 6000000],
filterColor: (z) => '#ffffff77',
})
//define boundaries layer
const boundariesLayer = new gridviz.GeoJSONLayer(gridviz_eurostat.getEurostatBoundariesLayer())
//define label layer
const labelLayer = new gridviz.LabelLayer(gridviz_eurostat.getEuronymeLabelLayer('EUR', 50))
//add layer to map
map.layers = [backgroundLayer, gridLayer, boundariesLayer, labelLayer]
</script>