@@ -31,28 +31,41 @@ var map = new L.Map('map', {
31
31
// define your leaflet-gridviz layer
32
32
let gridvizLayer = new L.GridvizLayer ({
33
33
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
+ },
56
69
})
57
70
58
71
// add it to the map
0 commit comments