-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
196 lines (171 loc) · 6.19 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Interactive Web Mapping: Covid Cases Per 10k by WA County</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.5.0/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v2.5.0/mapbox-gl.js"></script>
<style>
h2, h3 {
margin: 10px;
font-size: 18px;
}
h3 {
font-size: 16px;
}
p {
margin: 10px;
}
#map {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
}
.map-overlay {
position: absolute;
bottom: 0;
left: 0;
background: rgba(255, 255, 255, 0.8);
border-style: solid;
border-width: 1px;
border-color: rgba(0, 0, 0, 0.2);
margin-left: 20px;
font-family: Arial, sans-serif;
overflow: auto;
border-radius: 3px;
}
#features {
top: 0;
height: 100px;
margin-top: 20px;
width: 250px;
}
#legend {
padding: 10px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
line-height: 18px;
height: 210px;
margin-bottom: 40px;
width: 150px;
}
.legend-key {
display: inline-block;
border-radius: 20%;
width: 10px;
height: 10px;
margin-right: 5px;
}
.mapboxgl-canvas-container.mapboxgl-interactive,
.mapboxgl-ctrl-group button.mapboxgl-ctrl-compass {
cursor: unset;
}
</style>
</head>
<body>
<div id="map"></div>
<div class='map-overlay' id='features'>
<h2>WA COVID cases per 10k</h2>
<div id='text-escription'>
<p>Hover over a county!</p>
</div>
</div>
<div class='map-overlay' id='legend'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoibGlhbWdlYXJ5dXciLCJhIjoiY2t2YmRzOTd1Mnd2bTJubm5pZjZ2dWN6NCJ9.MSvwXgu6CcpGE5Zw4ukudw';
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/light-v10', // style URL
zoom: 6.5, // starting zoom
center: [-120.5, 47.4] // starting center
}
);
async function geojsonFetch() {
let response = await fetch('assets/wa-covid-data-102521.geojson');
let covidData = await response.json();
map.on('load', function loadingData() {
// add layer
map.addSource('covidData', {
type: 'geojson',
data: covidData
});
map.addLayer({
'id': 'covidData-layer',
'type': 'fill',
'source': 'covidData',
'paint': {
'fill-color': [
'step',
['get', 'casePer10k'],
'#FFEDA0', // stop_output_0
500, // stop_input_0
'#FED976', // stop_output_1
700, // stop_input_1
'#FEB24C', // stop_output_2
900, // stop_input_2
'#FD8D3C', // stop_output_3
1100, // stop_input_3
'#FC4E2A', // stop_output_4
1300, // stop_input_4
'#E31A1C', // stop_output_5
1500, // stop_input_5
'#BD0026', // stop_output_6
1700, // stop_input_6
"#800026" // stop_output_7
],
'fill-outline-color': '#BBBBBB',
'fill-opacity': 0.7,
}
});
// add legend
const layers = [
'0-499',
'500-699',
'700-899',
'900-1099',
'1100-1299',
'1300-1499',
'1500-1699',
'1700 and more'
];
const colors = [
'#FFEDA070',
'#FED97670',
'#FEB24C70',
'#FD8D3C70',
'#FC4E2A70',
'#E31A1C70',
'#BD002670',
'#80002670'
];
const legend = document.getElementById('legend');
legend.innerHTML = "<b>COVID Cases<br>(per 10k)</b><br><br>";
layers.forEach((layer, i) => {
const color = colors[i];
const item = document.createElement('div');
const key = document.createElement('span');
key.className = 'legend-key';
key.style.backgroundColor = color;
const value = document.createElement('span');
value.innerHTML = `${layer}`;
item.appendChild(key);
item.appendChild(value);
legend.appendChild(item);
});
map.on('mousemove', ({point}) => {
const county = map.queryRenderedFeatures(point, {
layers: ['covidData-layer']
});
document.getElementById('text-escription').innerHTML = county.length ?
`<h3>${county[0].properties.name}</h3><p><strong><em>${county[0].properties.casePer10k}</strong> cases per 10k</em></p>` :
`<p>Hover over a county!</p>`;
});
});
};
geojsonFetch();
</script>
</body>
</html>