-
Notifications
You must be signed in to change notification settings - Fork 0
/
2016.html
200 lines (170 loc) · 5.96 KB
/
2016.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
<html>
<head>
<meta charset="utf-8" />
<meta property="og:image" content="https://raw.githubusercontent.com/tuttlepower/VotingMap/master/VoteMap.PNG" />
<link rel="icon"
href="https://raw.githubusercontent.com/tuttlepower/tuttlepower/master/Resources/Images/facelighting.png"
type="Head" sizes="16x16">
<title>Vote Map - 2016 </title>
<!-- Load Leaflet from CDN -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
crossorigin=""></script>
<!-- Load Esri Leaflet from CDN -->
<script src="https://unpkg.com/[email protected]/dist/esri-leaflet.js"
integrity="sha512-1tScwpjXwwnm6tTva0l0/ZgM3rYNbdyMj5q6RSQMbNX6EUMhYDE3pMRGZaT41zHEvLoWEK7qFEJmZDOoDMU7/Q=="
crossorigin=""></script>
<!-- Load Esri Leaflet Geocoder from CDN, needed for Search Bar -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/esri-leaflet-geocoder.css"
integrity="sha512-v5YmWLm8KqAAmg5808pETiccEohtt8rPVMGQ1jA6jqkWVydV5Cuz3nJ9fQ7ittSxvuqsvI9RSGfVoKPaAJZ/AQ=="
crossorigin="">
<script src="https://unpkg.com/[email protected]/dist/esri-leaflet-geocoder.js"
integrity="sha512-uK5jVwR81KVTGe8KpJa1QIN4n60TsSV8+DPbL5wWlYQvb0/nYNgSOg9dZG6ViQhwx/gaMszuWllTemL+K+IXjg=="
crossorigin=""></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#legend {
position: absolute;
left: 10px;
bottom: 10px;
}
#links {
position: absolute;
right: 10px;
bottom: 20px;
}
#info-pane {
position: absolute;
top: 10px;
right: 10px;
z-index: 400;
padding: 1em;
background: white;
}
#demo {
top: 30px;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="info-pane" class="leaflet-bar">Hover to Inspect</div>
<div id="legend">
<img src="muddy_key_labeled_compressed.png" alt="muddy label" width="150" height="150">
</div>
<script type="text/javascript" src="js/reworked.js"></script>
<script>
//creates variable called map and sets the view to middle of America with a zoom level of 5
var map = L.map('map', {
center: [39.0902, -95.7129],
zoom: 5,
});
var year = 2016;
var upperfence2000 = 51327.875;
var upperfence2004 = 60004.5;
var upperfence2008 = 64140;
var upperfence2012 = 62942;
var upperfence2016 = 66148;
//Sets basemap color and features
L.esri.basemapLayer('Gray').addTo(map);
//pulls county data from US
var counties = L.esri.featureLayer({
url: 'https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/State_County/MapServer/1',
simplifyFactor: 0.5,
precision: 5,
weight: .3,
//opacity:1,
fillOpacity: 1,
color: 'white',
//fillColor: 'white',
style: function (feature) {
for (i in reworked) {
if (feature.properties.GEOID == reworked[i].fips) {
if (reworked[i].year == year) {
if (reworked[i].democrat > reworked[i].republican) {
return {
//fillColor: 'hsl(250,100%,50%)'
fillColor: 'hsl(' + 240 + ',' + (Math.abs(reworked[i].democrat - reworked[i]
.republican) / reworked[i].votetotal) * 100 + '% ,' + 50 +
'%)',
//fillColor: 'hsl('+ 0 +','+((Math.abs(us_votes[i].votes_dem-us_votes[i].votes_gop)/(us_votes[i].total_votes)))+','+(((1-(us_votes[i].total_votes/50)*100)/2)+50)+')',
color: 'hsl(' + 240 + ',' + (Math.abs(reworked[i].democrat - reworked[i]
.republican) / reworked[i].votetotal) * 100 + '% ,' + 50 + '%)',
//fillColor:"blue",
fillOpacity: (reworked[i].votetotal / upperfence2016),
}
} else {
return {
//fillColor: 'hsl(0,100%,50%)'
fillColor: 'hsl(' + 0 + ',' + (Math.abs(reworked[i].democrat - reworked[i]
.republican) / reworked[i].votetotal) * 100 + '% ,' + 50 +
'%)',
//fillColor:'hsl('+ 240 +','+((Math.abs(us_votes[i].votes_dem-us_votes[i].votes_gop)/(us_votes[i].total_votes)))+','+(((1-(us_votes[i].total_votes/50)*100)/2)+50)+')',
color: 'hsl(' + 0 + ',' + (Math.abs(reworked[i].democrat - reworked[i]
.republican) / reworked[i].votetotal) * 100 + '% ,' + 50 + '%)',
//fillColor:"red",
fillOpacity: (reworked[i].votetotal / upperfence2016),
}
}
}
}
}
}
}).addTo(map);
var oldId;
counties.on('mouseout', function (e) {
document.getElementById('info-pane').innerHTML = 'Hover to Inspect';
counties.resetFeatureStyle(oldId);
});
counties.on('mouseover', function (e) {
oldId = e.layer.feature.id;
document.getElementById('info-pane').innerHTML = e.layer.feature.properties.NAME + ' - ' + e
.layer.feature
.properties.GEOID;
counties.setFeatureStyle(e.layer.feature.id, {
color: 'orange',
fillColor: 'orange',
weight: .3,
opacity: 1,
fillOpacity: 1,
});
});
//binds popups to the counties layer
//this determines what goes inside the popup for each county
counties.bindPopup(function (layer) {
for (i in reworked) {
if (layer.feature.properties.GEOID == reworked[i].fips) {
if (reworked[i].year == year) {
return L.Util.template(
'<div><p><b>Year: </b>' + reworked[i].year.toString() +
'</p><p><b>County Name: </b>{NAME}</p><p><b>Democratic Votes:</b> ' +
reworked[i]
.democrat.toLocaleString() + '<b> (' + (reworked[i].democrat / reworked[i]
.votetotal *
100).toFixed(2) +
'%)</b>' + '</p><p><b>Republican Votes: </b>' + reworked[i].republican
.toLocaleString() + '<b> (' + (reworked[i].republican / reworked[i]
.votetotal * 100)
.toFixed(2) + '%)</b>' +
'</p></div>',
layer.feature.properties);
}
}
}
});
</script>
</body>
</html>