-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.html
210 lines (170 loc) · 7.99 KB
/
Test.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
<html>
<head>
<meta charset="utf-8" />
<link rel="icon"
href="https://raw.githubusercontent.com/tuttlepower/tuttlepower/master/Resources/Images/facelighting.png"
type="Head" sizes="16x16">
<title>Test Map</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;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="legend">
<img src="muddy_key_labeled_compressed.png" alt="muddy label" width="150" height="150">
</div>
<div id="links">
<button
onclick="window.location.href = 'https://stemlounge.com/muddy-america-color-balancing-trumps-election-map-infographic/';">Original
Muddy Map</button>
<button onclick="window.location.href = 'https://github.com/tuttlepower/VotingMap';">Github</button>
</div>
<script type="text/javascript" src="us-votes.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,
});
//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 us_votes) {
if (feature.properties.GEOID == us_votes[i].combined_fips) {
if (us_votes[i].votes_dem > us_votes[i].votes_gop) {
return {
//fillColor: 'hsl(250,100%,50%)'
fillColor: 'hsl(' + 240 + ',' + (us_votes[i].per_point_diff) + ',' + 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 + ',' + (us_votes[i].per_point_diff) + ',' + 50 + '%)',
fillOpacity: (us_votes[i].total_votes / 59828),
};
} else {
return {
//fillColor: 'hsl(0,100%,50%)'
fillColor: 'hsl(' + 0 + ',' + (us_votes[i].per_point_diff) + ',' + 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 + ',' + (us_votes[i].per_point_diff) + ',' + 50 + '%)',
fillOpacity: (us_votes[i].total_votes / 59828),
}
}
}
}
}
}).addTo(map);
//binds popups to the counties layer
counties.bindPopup(function (layer) {
for (i in us_votes) {
if (layer.feature.properties.GEOID == us_votes[i].combined_fips) {
return L.Util.template(
'<div><p><b>State: </b>' + us_votes[i].state_abbr.toString() +
'</p><p><b>County Name: </b>{NAME}</p><p><b>Democratic Votes:</b> ' + us_votes[i]
.votes_dem.toLocaleString() +'<b> ('+(us_votes[i].per_dem*100).toFixed(2)+'%)</b>'+ '</p><p><b>Republican Votes: </b>' + us_votes[i].votes_gop.toLocaleString() +'<b> ('+(us_votes[i].per_gop*100).toFixed(2)+'%)</b>'+
'</p></div>',
layer.feature.properties);
}
}
//this determines what goes inside the popup for each building
});
/////////////////////////////
//Placeholder
var Test = L.layerGroup();
//uses esri basemaplayers to get a light theme and streets
var grayscale = L.esri.basemapLayer('Gray'),
grayLabels = L.esri.basemapLayer('GrayLabels'),
darkmode = L.esri.basemapLayer('DarkGray');
//gives different basemap options
var baseLayers = {
"Grayscale": grayscale,
"Grayscale Labeled": grayLabels,
"Dark Mode": darkmode,
};
//different layers can be placed here, allowing them to be seen and hidden
var overlays = {
//"buildings": buildings,
"Test": Test
};
//inserts layers to map
L.control.layers(baseLayers, overlays).addTo(map);
/////////////////////////////
//inserts generic searchbar
var arcgisOnline = L.esri.Geocoding.arcgisOnlineProvider();
L.esri.Geocoding.geosearch({
//allows the search to look through items outside of the initial screen position
useMapBounds: false,
zoomToResult: true,
expanded: false,
providers: [
arcgisOnline,
L.esri.Geocoding.featureLayerProvider({
//gives our map information to the search bar
url: 'https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/State_County/MapServer/1',
//specifies what to search by
searchFields: ['COUNTY', 'NAME'],
//generic label, that seperates generic results from map specific results in search bar
label: 'Counties',
//random large number to allow for the search bar to search large areas of the map.
bufferRadius: 5000,
//shows the searches in the search bar
formatSuggestion: function (feature) {
// search results
// cut "+ ' - ' + feature.properties.BuildMaint" but may want to re-add it
return feature.properties.NAME;
}
})
]
}).addTo(map);
</script>
</body>
</html>