Skip to content

Commit 9bcadb9

Browse files
committed
migrate to gridviz V3
1 parent 403db8f commit 9bcadb9

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

README.md

+35-22
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,41 @@ var map = new L.Map('map', {
3131
// define your leaflet-gridviz layer
3232
let gridvizLayer = new L.GridvizLayer({
3333
proj: 'EPSG:3035',
34-
onLayerDidMountCallback: () => {
35-
// define our gridviz layer once the layer is mounted by accessing the app
36-
gridvizLayer.map
37-
.addMultiScaleTiledGridLayer(
38-
[1000, 2000, 5000, 10000, 20000, 50000, 100000],
39-
(r) =>
40-
'https://raw.githubusercontent.com/jgaffuri/tiledgrids/main/data/europe/population/' +
41-
r +
42-
'm/',
43-
gridviz.TanakaStyle.get('2018', {
44-
tFun: (v, r, s, zf) =>
45-
gridviz.sExpRev((v - s.min) / (s.max - s.min), -7),
46-
nb: 6,
47-
color: (t) => d3.interpolateInferno(t * 0.9 + 0.1),
48-
colDark: '#333',
49-
}),
50-
{
51-
pixNb: 6,
52-
cellInfoHTML: (c) => '<b>' + c['2018'] + '</b> inhabitant(s)',
53-
}
54-
)
55-
}
34+
onLayerDidMountCallback: (gridvizMap) => {
35+
//define multi resolution dataset
36+
const dataset = new gridviz.MultiResolutionDataset(
37+
//the resolutions
38+
[1000, 2000, 5000, 10000, 20000, 50000, 100000],
39+
//the function returning each dataset from the resolution
40+
(resolution) =>
41+
new gridviz.TiledGrid(
42+
gridvizMap,
43+
'https://raw.githubusercontent.com/jgaffuri/tiledgrids/main/data/europe/population2/' +
44+
resolution +
45+
'm/'
46+
)
47+
)
48+
49+
//define color for each cell c
50+
const colorFunction = (cell, resolution) => {
51+
const density = (1000000 * cell.TOT_P_2021) / (resolution * resolution)
52+
if (density > 1500) return '#993404'
53+
else if (density > 600) return '#d95f0e'
54+
else if (density > 200) return '#fe9929'
55+
else if (density > 60) return '#fec44f'
56+
else if (density > 15) return '#fee391'
57+
else return '#ffffd4'
58+
}
59+
60+
//define style
61+
const style = new gridviz.ShapeColorSizeStyle({ color: colorFunction })
62+
63+
//add layer to map
64+
gridvizMap.layers = [new gridviz.GridLayer(dataset, [style], {minPixelsPerCell: 5})]
65+
66+
//custom opacity
67+
gridvizLayer._canvas.style.opacity = 0.7
68+
},
5669
})
5770

5871
// add it to the map

0 commit comments

Comments
 (0)