-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
242 lines (199 loc) · 7.76 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html>
<html>
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DM5K75JW4Z"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-DM5K75JW4Z');
</script>
<title>The 2024 Pima County District 1 Supervisor Race</title>
<meta name="description" content="About me, and this website">
<meta content="width=device-width, initial-scale=1" name="viewport" />
<!-- itemprop tags for Google -->
<meta itemprop="name" content="The 2024 Presidential Election in Pima County, precinct by precinct">
<meta itemprop="description" content="An interactive map of Pima County's 265 voting precincts that shows the 2024 U.S. Presidential Election outcome for each precinct.">
<meta itemprop="image" content="https://lukeknipe.com/az_voter_reg_by_ld/og.png">
<!-- og tags for Facebook -->
<meta property="og:title" content="The 2024 Presidential Election in Pima County, precinct by precinct" />
<meta property="og:locale" content="en_US" />
<meta property="og:url" content="https://lukeknipe.com/az_voter_reg_by_ld/">
<meta property="og:type" content="website">
<meta property="og:description" content="An interactive map of Pima County's 265 voting precincts that shows the 2024 U.S. Presidential Election outcome for each precinct.">
<meta property="og:image" content="https://lukeknipe.com/az_voter_reg_by_ld/og.png">
<meta property="og:image:alt" content="The 2024 Presidential Election in Pima County, precinct by precinct">
<!-- Twitter tags -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Arizona's legislative districts, by the numbers">
<meta name="twitter:description" content="An interactive map of Pima County's 265 voting precincts that shows the 2024 U.S. Presidential Election outcome for each precinct.">
<meta name="twitter:image" content="https://lukeknipe.com/az_voter_reg_by_ld/og.png">
<link rel="stylesheet" href="style.css">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://lukeknipe.com/az_voter_reg_by_ld" />
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
</head>
<body>
<div id='map'></div>
<script type="text/javascript" src="pima_d1_2024.js"></script>
<script type="text/javascript">
// Display basemap
var map = L.map('map', {zoomControl: false}).setView([32.38, -110.9], 11.5);
new L.Control.Zoom({ position: 'bottomleft' }).addTo(map);
L.tileLayer('https://api.mapbox.com/styles/v1/lukeknipe/cl5mwyk7000gy15qvyp46e1h2/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoibHVrZWtuaXBlIiwiYSI6ImNsNW13ajU1azAwZmszZXBxeWV0ZWtlaTgifQ.llc0hOFsg4QzV7tiR1jLdg', {
maxZoom: 18,
attribution: 'Map data: <a href="https://gisopendata.pima.gov/">Pima County Geospatial Data Portal</a>' +
' | Election data: <a href="https://www.pima.gov/394/Elections">Pima County Elections Department</a> | Imagery © <a href="http://mapbox.com">Mapbox</a>',
}).addTo(map);
// Control that shows district info on hover
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = (props ?
'<h1>Precinct<br>' + props.PRECINCT + '</h1>'
+ '<h2><center>Turnout ' + ((props.BALLOTS / (props.VOTERS))*100).toFixed(2) + '%</h2></center>'
+ '<h2><center>' + leanCalc(((props.SPAIN / (props.BALLOTS))*100).toFixed(2), ((props.SCOTT / (props.BALLOTS))*100).toFixed(2)) + '</center></h2>'
+ '<h3><br>' + ((props.SPAIN / (props.BALLOTS))*100).toFixed(2) + '% Spain</h3>'
+ '<h4><br>' + props.SPAIN + ' Votes for Steve Spain<br></h4>'
+ '<h3><br>' + ((props.SCOTT / (props.BALLOTS))*100).toFixed(2) + '% Scott</h3>'
+ '<h4><br>' + props.SCOTT + ' Votes for Rex Scott<br></h4>'
+ '<h3><br>' + (((props.WRITE_IN) / (props.BALLOTS))*100).toFixed(2) + '% Write-In</h3>'
+ '<h4><br>' + props.WRITE_IN + ' Write-in votes<br></h4>'
+ '<h3><br>' + + ((props.UNDER / (props.BALLOTS))*100).toFixed(2) + '% Undervote</h3>'
+ '<h4><br>' + props.UNDER + ' Undervotes</h4>'
+ '<h4><br>' + props.OVER + ' Overvotes</h4>'
: 'Hover over a voting precinct');
};
info.addTo(map);
function leanCalc(pctRep, pctDem) {
if (pctRep > pctDem) {
return '<span style="color: red;"><center><b>Spain + ' + (pctRep - pctDem).toFixed(2) + '%</b></center></span>';
} else {
return '<span style="color: blue;"><center><b>Scott + ' + (pctDem - pctRep).toFixed(2) + '%</b></center></span>';
}
}
// Get color for Dem precincts
function getColorDem(e) {
return e > 33.7 ? '#08306B' :
e > 29.2 ? '#0A549E' :
e > 26.2 ? '#2172B6' :
e > 22.4 ? '#3E8EC4' :
e > 18.7 ? '#60A6D2' :
e > 15.0 ? '#89BFDD' :
e > 11.2 ? '#B0D2E8' :
e > 7.5 ? '#CDE0F2' :
e > 3.7 ? '#E2EEF9' :
'#E2EEF9';
};
// Get color for Rep precincts
function getColorRep(e) {
return e > 33.7 ? '#FFFFFF' :
e > 29.2 ? '#FFFFFF' :
e > 26.2 ? '#FFFFFF' :
e > 22.4 ? '#FF4C4C' :
e > 18.7 ? '#FF6666' :
e > 15.0 ? '#FF7F7F' :
e > 11.2 ? '#FF9999' :
e > 7.5 ? '#FFB2B2' :
e > 3.7 ? '#FFCCCC' :
'#FFE5E5';
};
// Style for district map
function style(feature) {
const demEdge = (feature.properties.SCOTT / (feature.properties.BALLOTS)*100) - (feature.properties.SPAIN / (feature.properties.BALLOTS)*100);
const repEdge = (feature.properties.SPAIN / (feature.properties.BALLOTS)*100) - (feature.properties.SCOTT / (feature.properties.BALLOTS)*100);
if (demEdge > 0.001) {
return {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.5,
fillColor: getColorDem(demEdge),
};
}
if (repEdge > 0.001) {
return {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7,
fillColor: getColorRep(repEdge),
};
}
else {
return {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7,
fillColor: '#FFFFFF',
};
}
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
// Display districts
var geojson;
function resetHighlight(e) {
geojson.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}
geojson = L.geoJson(electionResults, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
// Display legend
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0, 3.7, 7.5, 11.2, 15.0, 18.7, 22.4, 26.2, 29.9, 33.7],
labels = ['<b>Harris/Trump<br>margin %</b><br>'],
from, to;
for (var i = 0; i < grades.length; i++) {
from = grades[i];
to = grades[i + 1];
labels.push(
'<i style="background:' + getColorDem(from + 0) + '"></i><i style="background:' + getColorRep(from + 0) + '"></i> ' +
from + (to ? '–' + to : '+'));
}
div.innerHTML = labels.join('<br>');
return div;
};
legend.addTo(map);
</script>
</body>