-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
63 lines (56 loc) · 1.85 KB
/
index.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
57
58
59
60
61
62
63
<html>
<head>
<title>Base minimum DeckGL Choropleth</title>
<script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.css' rel='stylesheet' />
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="token.js"></script>
<style>
#container {
width: 100vw;
height: 100vh;
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="container"></div>
</body>
<script type="text/javascript">
const {DeckGL, GeoJsonLayer} = deck;
const geojsonLayer = new GeoJsonLayer({
data: 'https://raw.githubusercontent.com/umassdgithub/Sample_Data/main/MA_GeoJSON.json',
stroked: true,
filled: true,
opacity:.9,
getLineColor: [0, 0, 0],
lineWidthMinPixels: .5,
getFillColor: d=> color(d['properties']['POP2010']),
});
// http://bboxfinder.com/
// mass bbox center : -71.961823,42.182741
new DeckGL({
mapboxApiAccessToken:token,
mapStyle:'mapbox://styles/mapbox/streets-v11',
container: "container",
initialViewState: {
latitude: 42.182741,
longitude: -71.961823,
zoom: 7,
maxZoom: 16
},
controller: true,
layers: [geojsonLayer]
});
function color(population, min=75, max=617594){
let colorInterpolator = d3.interpolateRgbBasis(["blue", "steelblue", "green", "purple", "red"])
let logScale = d3.scaleLog()
.domain([min,max])
let hexColor = colorInterpolator(logScale(population))
let rgbColor = d3.rgb(hexColor)
return [rgbColor.r,rgbColor.g,rgbColor.b];
}
</script>
</html>