-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·294 lines (239 loc) · 10.1 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
body {
padding-top: 50px;
padding-bottom: 20px;
}
</style>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/main.css">
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script type="text/javascript" src="js/vendor/handlebars.js"></script>
<script src="maps/md_sldu_centroids.json"></script>
<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h2>Maryland League of Conservation Voters <br><small>State Senate Scorecard Map</small></h2>
</div>
<div class="row">
<div id="main" class="col-md-9">
<div id="map"></div>
</div>
<div id="sidebar" class="col-md-3"></div>
</div>
<div class="row">
<div id="content"></div>
</div>
</div><!-- /container -->
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.0.min.js"><\/script>')</script>
<script src="js/vendor/bootstrap.min.js"></script>
<script src="js/main.js"></script>
<script type="text/javascript" src="js/vendor/tabletop.js"></script>
<script type="text/javascript">
// var public_spreadsheet_url = 'https://docs.google.com/spreadsheet/pub?key=0Ao3Ts9D8bHHpdHRWYmRIYldKcFBFVnRELUhVay04NWc&single=true&gid=0&output=html';
var public_spreadsheet_url = 'https://docs.google.com/spreadsheet/pub?key=0Ao3Ts9D8bHHpdDlXWVlhSl9UelVmSjV0NHJBUGxQbFE&output=html';
var dist;
var freeze;
var MDSenateDistricts = {};
console.log('MDSenateDistricts', MDSenateDistricts);
var app = {};
var senateLayer;
var latitude = 38.82;
var longitude = -77.28;
var latLng = new L.LatLng(latitude, longitude);
var sidebar = $('#sidebar');
var map = L.map('map').setView(latLng, 7);
function clearInfobox() {
sidebar.html(' ');
}
$(document).ready( function() {
Tabletop.init( { key: public_spreadsheet_url,
callback: showInfo,
parseNumbers: true } );
});
function showInfo(data, tabletop) {
var scoreColor;
var source = $("#senate-template").html();
var template = Handlebars.compile(source);
var sourcebox = $("#senate-template-infobox").html();
app.infoboxTemplate = Handlebars.compile(sourcebox);
$.each( tabletop.sheets("Senate2015").all(), function(i, member) {
scoreColor = getColor(member.score2013);
member['scoreColor'] = scoreColor;
var html = template(member);
$("#content").append(html);
MDSenateDistricts[member.district] = member;
});
console.log(MDSenateDistricts);
loadGeo();
// processJSON(tabletop.sheets("Sheet1").all());
}
function scoreToColor() {
var sldust = Number(data.properties.SLDUST);
console.log(MDSenateDistricts)
var score = MDSenateDistricts[sldust].score2013;
console.log()
return getColor(score);
}
var geoStyle = function(data) {
var sldust = Number(data.properties.SLDUST);
console.log(sldust);
// Sort out how to get at the SLDUST data.
// console.log("geoStyle: ", Number(data.properties.SLDUST));
var score = MDSenateDistricts[sldust].score2013;
var scoreToColor = getColor(score);
return {
fillColor: scoreToColor,
weight: 1,
opacity: 0.51,
color: '#333333',
dashArray: '0',
fillOpacity: 1
}
}
// function loadGeo(district) {
// senateLayer = L.geoJson(geosenate, {
// onEachFeature:onEachFeature,
// style: geoStyle
// });
// senateLayer.addTo(map);
// }
var geojsonMarkerOptions = {
radius: 5,
fillColor: geoStyle, //"#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
};
function loadGeo(district) {
senateLayer = L.geoJson(geosenate, {
onEachFeature:onEachFeature,
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, geojsonMarkerOptions);
}
}).addTo(map);
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: mapMemberDetailClick
});
}
function highlightFeature(e) {
var layer = e.target;
var memberNumber = Number(layer.feature.properties.SLDUST);
var memberDetail = MDSenateDistricts[memberNumber];
// This fills in the sidebar as you mouse around.
// NO STICKY CLICK
if (!freeze) {
html = app.infoboxTemplate(memberDetail);
$('#sidebar').html(html);
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
}
function resetHighlight(e) {
var layer = e.target;
senateLayer.resetStyle(e.target);
info.update();
if (!freeze) {
clearInfobox();
}
}
function mapMemberDetailClick(e) {
freeze=1;
var boundary = e.target;
var memberNumber = Number(boundary.feature.properties.SLDUST);
console.log("mapMemberDetailClick: ", memberNumber);
var member = memberDetailFunction(memberNumber);
}
function memberDetailFunction(memberNumber){
var districtDetail = MDSenateDistricts[memberNumber]
// 1. Build Template for the information box from districtDetails attributes.
// 2. Insert the rendered template into .info
var html = app.infoboxTemplate(districtDetail);
$('#sidebar').html(html);
// $('#sidebar').html(JSON.stringify(districtDetail));
}
function getColor(score) {
return score > 80 ? 'rgb(0, 104, 55)' :
score > 60 ? 'rgb(102, 189, 99)' :
score > 40 ? 'rgb(166, 217, 106)' :
score > 20 ? 'rgb(255, 255, 191)' :
score > 0 ? 'rgb(244, 109, 67)' :
'rgb(165, 0, 38)';
}
$(document).on("click","button",function(event) {
event.preventDefault();
clearInfobox();
freeze=0;
});
</script>
<script id="senate-template" type="text/x-handlebars-template">
<div class="entry" >
<div style='margin-top:-5px; margin-bottom:3px; background-color: {{scoreColor}};height:20px;'></div>
<div class="body">
<strong>District {{{district}}}</strong><br>
{{{fullname}}} ({{{party}}})<br>
{{#if phone}}{{{phone}}}<br>{{/if}}
Lifetime Score: <strong>{{{lifetimescore}}}</strong><br>
2013 Score: <strong>{{{score2013}}}</strong><br>
{{{notes}}}<br>
{{#if twitter}}<a target='_new' href="http://twitter.com/{{{twitter}}}"><i class="icon-twitter icon-2x custom-icon"></i></a>{{/if}} {{#if facebook}} <a target='_new' href="{{{facebook}}}"><i class="icon-facebook icon-2x custom-icon"></i></a> {{/if}}{{#if email}}<a target='_new' href="mailto:{{{email}}}"><i class="icon-envelope icon-2x custom-icon"></i></a>{{/if}}
</div>
</div>
</script>
<script id="senate-template-infobox" type="text/x-handlebars-template">
<div class="entry" style="padding-top:12px; background-color: {{scoreColor}};">
<div class="body">
<button type='button' id='close' class='close'>×</button><br>
<strong> {{{fullname}}} ({{{party}}})</strong><br>
District {{{district}}}<br>
{{#if phone}}{{{phone}}}<br>{{/if}}
Lifetime Score: <strong>{{{lifetimescore}}}</strong><br>
2013 Score: <strong>{{{score2013}}}</strong><br>
{{{notes}}}<br>
{{#if twitter}}<a target='_new' href="http://twitter.com/{{{twitter}}}"><i class="icon-twitter icon-2x custom-icon"></i></a>{{/if}} {{#if facebook}} <a target='_new' href="{{{facebook}}}"><i class="icon-facebook icon-2x custom-icon"></i></a> {{/if}}{{#if email}}<a target='_new' href="mailto:{{{email}}}"><i class="icon-envelope icon-2x custom-icon"></i></a>{{/if}}
</div>
</div>
</script> <!-- /container -->
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
<!--<script>-->
<!--(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=-->
<!--function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;-->
<!--e=o.createElement(i);r=o.getElementsByTagName(i)[0];-->
<!--e.src='//www.google-analytics.com/analytics.js';-->
<!--r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));-->
<!--ga('create','UA-XXXXX-X');ga('send','pageview');-->
<!--</script>-->
</body>
</html>