-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
234 lines (202 loc) · 5.14 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico"/>
<title>Cicero Elections</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://api.mapbox.com/mapbox-gl-js/v1.10.0/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v1.10.0/mapbox-gl.css" rel="stylesheet" />
<style>
html {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial,
sans-serif, Apple Color Emoji, Segoe UI Emoji;
background-color: #fff;
line-height: 1.35;
font-size: 14px;
}
html,
body {
height: 100%;
}
#map {
position: absolute;
top: 13vh;
bottom: 0;
left: 0;
right: 0;
}
.App-header {
background-color: #4b87e0;
min-height: 13vh;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 0px 40px;
color: #fff;
}
a { text-decoration: none;
color: #fff;
}
.header-title {
font-size: calc(10px + 2vmin);
}
.header-subtitle {
font-size: calc(3px + 2vmin);
}
.mapboxgl-popup {
max-width: 400px;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial,
sans-serif, Apple Color Emoji, Segoe UI Emoji;
font-size: 14px;
}
</style>
</head>
<body>
<div class='App-header'>
<div class="header-left">
<div class="header-title">
Upcoming Cicero Elections
</div>
<div class="header-subtitle">
October-December 2022
</div>
</div>
<div class="header-right">
<div class="header-subtitle">
<a href="https://cicerodata.com" target="_blank">Click to learn more at cicerodata.com</a>
</div>
</div>
</div>
<div id="map"></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoibHVrZW1ja2luc3RyeSIsImEiOiJjajU0ODRsNmMwMHg2MndxeWsxMXhpY3k5In0.yM_-IJxaryqd9i5Rt6k8LA';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/lukemckinstry/ckd7svdqa02c91inxvb2j8n4y',
center: [-103.59179687498357, 40.66995747013945],
zoom: 3,
minZoom: 2,
maxZoom: 11,
});
var nav = new mapboxgl.NavigationControl({
showCompass: false,
showZoom: true
});
map.addControl(nav, "top-left");
map.on('load', function() {
map.addSource('elections', {
type: 'geojson',
data: 'https://gist.githubusercontent.com/kklinges/935b0e617ddb28af496c2e76488f9cae/raw/b65e7b83871644936ffde60cc7823b11263ce84c/upcoming.geojson',
cluster: true,
clusterMaxZoom: 14, // Max zoom to cluster points on
clusterRadius: 50 // Radius of each cluster when clustering points (defaults to 50)
});
map.addLayer({
id: 'clusters',
type: 'circle',
source: 'elections',
filter: ['has', 'point_count'],
paint: {
'circle-color': [
'step',
['get', 'point_count'],
'#8f5db5',
4,
'#dcb522'
],
'circle-radius': [
'step',
['get', 'point_count'],
30,
4,
40
]
}
});
map.addLayer({
id: 'election-count',
type: 'symbol',
source: 'elections',
filter: ['has', 'point_count'],
layout: {
'text-field': '{point_count_abbreviated} \n elections in the area',
'text-font': ['DIN Offc Pro Medium', 'Arial Unicode MS Bold'],
'text-size': 12
}
});
map.addLayer({
id: 'unclustered-election-point',
type: 'circle',
source: 'elections',
filter: ['!', ['has', 'point_count']],
paint: {
//'circle-color': '#5bce22',
'circle-color': '#54c6bd',
'circle-radius': 10,
}
});
map.addLayer({
id: 'unclustered-election-label',
type: 'symbol',
source: 'elections',
filter: ['!', ['has', 'point_count']],
layout: {
'text-field': '{name_formal} \n {next_election_display}',
'text-font': ['DIN Offc Pro Medium', 'Arial Unicode MS Bold'],
'text-size': 12
}
});
map.on('click', 'clusters', function(e) {
var features = map.queryRenderedFeatures(e.point, {
layers: ['clusters']
});
var clusterId = features[0].properties.cluster_id;
map.getSource('elections').getClusterExpansionZoom(
clusterId,
function(err, zoom) {
if (err) return;
map.easeTo({
center: features[0].geometry.coordinates,
zoom: zoom
});
}
);
});
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
map.on('mouseenter', 'unclustered-election-label', function(e) {
map.getCanvas().style.cursor = 'pointer';
var coordinates = e.features[0].geometry.coordinates.slice();
var description = e.features[0].properties.ue_remarks;
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
if (description === '') {return}
popup
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
map.on('mouseleave', 'unclustered-election-label', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});
map.on('mouseenter', 'clusters', function() {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'clusters', function() {
map.getCanvas().style.cursor = '';
});
});
</script>
</body>
</html>