-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVaccines_March22.html
More file actions
189 lines (178 loc) · 5.48 KB
/
Vaccines_March22.html
File metadata and controls
189 lines (178 loc) · 5.48 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<meta name="robots" content="noindex, nofollow" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.js"></script>
<link
href="https://api.tiles.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.css"
rel="stylesheet"
/>
<style>
body {
margin: 0;
padding: 0;
}
h2,
h3 {
margin: 10px;
font-size: 1.2em;
}
h4 {
margin: 10px;
font-size: 1em;
}
p {
font-size: 0.85em;
margin: 10px;
text-align: left;
}
.map-overlay {
position: absolute;
bottom: 0;
right: 0;
background: rgba(255, 255, 255, 0.8);
margin-right: 20px;
font-family: Arial, sans-serif;
overflow: auto;
border-radius: 3px;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
#features {
top: 0;
height: 150px;
margin-top: 20px;
margin-left: 5px;
width: 250px;
}
#legend {
padding: 10px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
line-height: 18px;
height: 100px;
margin-bottom: 40px;
width: 100px;
}
.legend-key {
display: inline-block;
border-radius: 20%;
width: 10px;
height: 10px;
margin-right: 5px;
}
.mapboxgl-popup {
max-width: 400px;
font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<div id="map"></div>
<div class="map-overlay" id="features">
<h3>Vaccines Administered</h3>
<div id="pd"><p>Hover over a state!</p></div>
</div>
<div class="map-overlay" id="legend"></div>
<script>
// define access token
mapboxgl.accessToken = "pk.eyJ1IjoicGNhcmV3ODgiLCJhIjoiY2tsb2R2eG51MGE4NDJ2bGg0ZWE5Y3MzaiJ9.oplWrmagYgAUgVIcNyti7A";
//create map
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/pcarew88/cklodo87p5owo18nx49hn70th' // map style URL from Mapbox Studio
});
// wait for map to load before adjusting it
map.on('load', function () {
// make a pointer cursor
map.getCanvas().style.cursor = 'default';
// set map bounds to the continental US
map.fitBounds([
[-133.2421875, 16.972741],
[-47.63671875, 52.696361]
]);
map.addSource('covid19vaccines-a02nry', {
type: 'vector',
url: "mapbox://pcarew88.7s4lns78"
});
map.addLayer({
id: "covid19vaccines-fill",
source: "covid19vaccines-a02nry",
/*'source-layer': Name of the source-layer,*/
type: "fill",
paint: {
"fill-color": [
"match",
["get", "COVID19V_6"],
"51-59%",
"#ebfb93",
"60-68%",
"#91eeca",
"69-77%",
"#2ec2d6",
"78-86%",
"#1b40e4",
">86%",
"#29098b"
]}});
// make a pointer cursor
map.getCanvas().style.cursor = 'default';
// define layer names
var layers = [
'51-60',
'61-69',
'70-76',
'77-86',
'86+'
];
var colors = [
'#ebfb93',
'#91eeca',
'#2ec2d6',
'#1b40e4',
'#29098b'
];
// create legend
for (i = 0; i < layers.length; i++) {
var layer = layers[i];
var color = colors[i];
var item = document.createElement('div');
var key = document.createElement('span');
key.className = 'legend-key';
key.style.backgroundColor = color;
var value = document.createElement('span');
value.innerHTML = layer;
item.appendChild(key);
item.appendChild(value);
legend.appendChild(item);
}
// change info window on hover
map.on('mousemove', function (e) {
var states = map.queryRenderedFeatures(e.point, {
layers: ['covid19vaccines-a02nry']
});
if (states.length > 0) {
document.getElementById('pd').innerHTML =
'<h4><strong>' +
states[0].properties.NAME +
'</strong></h4><p><strong><em>' +
Math.round(states[0].properties.COVID19V_6) +
'</strong>% Of Delivered Vaccines Administered (March 22nd)</em></p>';
} else {
document.getElementById('pd').innerHTML =
'<p>Hover over a state!</p>';
}
});
});
</script>
</body>
</html>