-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
571 lines (481 loc) · 19.5 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
<title>Congressional Committee Maps</title>
<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/underscore/underscore.js"></script>
<script src="bower_components/handlebars/handlebars.min.js"></script>
<link href="bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script>
<link rel="stylesheet" href="css/normalize.css" />
<link rel="stylesheet" href="css/foundation.css" />
<!-- custom css -->
<link rel="stylesheet" href="css/style.css" />
<!-- states, congressional districts, and helper functions-->
<script src="maps/statemap.js"></script>
<script src="maps/congress113map.js"></script>
<script src="js/helperFunctions.js"></script>
<script src="js/vendor/custom.modernizr.js"></script>
<script src="js/foundation/foundation.js"></script>
<script src="js/foundation/foundation.dropdown.js"></script>
<script id="committee-member-template" type="text/x-handlebars-template">
<div class="entry">
<a href="{{committee_results.url}}" target="_blank"><h6>{{ committee_name}} <i class="fa fa-link"></i></h6></a>
<ul>
{{#each sorted_members}}
<li><a href="javascript:void(0);" data-member-id="{{bioguide_id}}">
{{first_name}} {{last_name}} ({{party}}), {{stateAbbreviation}}{{#if district}}-{{district}}{{/if}}{{#if title}}, {{title}}{{/if}}</a></li>{{/each}}
</ul>
</div>
</script>
<script id="committee-member-detail-template" type="text/x-handlebars-template">
{{#each members}}
<div class="entry entry-member-detail">
<p style="margin-bottom:0;"><strong>{{first_name}} {{last_name}} ({{party}}){{#if title}}, {{title}}{{/if}}</strong>
<br />{{#unless district}}
{{state_name}}
{{else}}
District {{stateAbbreviation}}-{{district}}
{{/unless}}
<br> {{office}} <br>{{phone}}
<br /><a target="_blank" href="{{website}}">Website</a> • <a target="_blank" href="{{contact_form}}">Contact Form</a>
<br /><a target="_blank" href="http://facebook.com/profile.php?id={{facebook_id}}">Facebook</a> • <a href="http://twitter.com/{{twitter_id}}" target="_blank">Twitter</a> • <a href="http://www.opensecrets.org/politicians/summary.php?cid={{crp_id}}" target="_blank">Open Secrets</a>
</p>
</div>
{{/each}}
</script>
<script id="map-hover-template" type="text/x-handlebars-template">
{{#each members}}
<div class="map-hover">
<p><strong>{{first_name}} {{last_name}}</strong> ({{party}}, {{#unless district}}{{state_name}}{{else}}{{stateAbbreviation}}-{{district}}{{/unless}}){{#if title}}, {{title}}{{/if}}
</div>
{{/each}}
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-48161825-1', 'committeemaps.org');
ga('send', 'pageview');
</script>
<meta property="og:image" content="http://committeemaps.org/CommitteeMaps.org.png">
</head>
<body>
<script>
$(document).foundation();
</script>
<div class="row">
<div class="large-11 columns" style="margin-left:-15px;margin-top:15px;">
<h1 style="display:inline">Congressional Committee Maps</h1>
<span class="rwd-line">
<a href="#" style="margin-right:10px;margin-left:12px;" class="button committeeButton" data-dropdown="tinyDropHouse" data-options="is_hover:true">House Committees »</a>
<ul id="tinyDropHouse" class="f-dropdown" data-dropdown-content style="position: absolute; top: 230px; left: -99999px;">
<li><a href="#" data-committee="HSAG">House Committee on Agriculture</a></li>
<li><a href="#" data-committee="HSAP">House Committee on Appropriations</a></li>
<li><a href="#" data-committee="HSAS">House Committee on Armed Services</a></li>
<li><a href="#" data-committee="HSBU">House Committee on the Budget</a></li>
<li><a href="#" data-committee="HSED">House Committee on Education and the Workforce</a></li>
<li><a href="#" data-committee="HSIF">House Committee on Energy and Commerce</a></li>
<li><a href="#" data-committee="HSSO">House Committee on Ethics</a></li>
<li><a href="#" data-committee="HSBA">House Committee on Financial Services</a></li>
<li><a href="#" data-committee="HSFA">House Committee on Foreign Affairs</a></li>
<li><a href="#" data-committee="HSHA">House Committee on House Administration</a></li>
<li><a href="#" data-committee="HSHM">House Committee on Homeland Security</a></li>
<li><a href="#" data-committee="HSJU">House Committee on the Judiciary</a></li>
<li><a href="#" data-committee="HSII">House Committee on Natural Resources</a></li>
<li><a href="#" data-committee="HSGO">House Committee on Oversight and Government Reform</a></li>
<li><a href="#" data-committee="HSRU">House Committee on Rules</a></li>
<li><a href="#" data-committee="HSSM">House Committee on Small Business</a></li>
<li><a href="#" data-committee="HSSY">House Committee on Science, Space, and Technology</a></li>
<li><a href="#" data-committee="HSPW">House Committee on Transportation and Infrastructure</a></li>
<li><a href="#" data-committee="HSVR">House Committee on Veterans' Affairs</a></li>
<li><a href="#" data-committee="HSWM">House Committee on Ways and Means</a></li>
<li><a href="#" data-committee="HLIG">House Permanent Select Committee on Intelligence</a></li>
</ul>
<a href="#" class="button committeeButton" data-dropdown="tinyDropSenate" data-options="is_hover:true">Senate Committees »</a>
<ul id="tinyDropSenate" class="f-dropdown" data-dropdown-content style="position: absolute; top: 230px; left: -99999px; max-width:470px; ">
<li><a href="#" data-committee="SSAF">Senate Committee on Agriculture, Nutrition, and Forestry</a></li>
<li><a href="#" data-committee="SSAP">Senate Committee on Appropriations</a></li>
<li><a href="#" data-committee="SSAS">Senate Committee on Armed Services</a></li>
<li><a href="#" data-committee="SSBK">Senate Committee on Banking, Housing, and Urban Affairs</a></li>
<li><a href="#" data-committee="SSBU">Senate Committee on the Budget</a></li>
<li><a href="#" data-committee="SSCM">Senate Committee on Commerce, Science, and Transportation</a></li>
<li><a href="#" data-committee="SSEG">Senate Committee on Energy and Natural Resources</a></li>
<li><a href="#" data-committee="SSEV">Senate Committee on Environment and Public Works</a></li>
<li><a href="#" data-committee="SSFI">Senate Committee on Finance</a></li>
<li><a href="#" data-committee="SSFR">Senate Committee on Foreign Relations</a></li>
<li><a href="#" data-committee="SSGA">Senate Committee on Homeland Security and Governmental Affairs</a></li>
<li><a href="#" data-committee="SSHR">Senate Committee on Health, Education, Labor, and Pensions</a></li>
<li><a href="#" data-committee="SLIA">Senate Committee on Indian Affairs</a></li>
<li><a href="#" data-committee="SSJU">Senate Committee on the Judiciary</a></li>
<li><a href="#" data-committee="SSRA">Senate Committee on Rules and Administration</a></li>
<li><a href="#" data-committee="SSSB">Senate Committee on Small Business and Entrepreneurship</a></li>
<li><a href="#" data-committee="SSVA">Senate Committee on Veterans' Affairs</a></li>
<li><a href="#" data-committee="SLET">Senate Select Committee on Ethics</a></li>
<li><a href="#" data-committee="SLIN">Senate Select Committee on Intelligence</a></li>
<li><a href="#" data-committee="SPAG">Senate Special Committee on Aging</a></li>
<li><a href="#" data-committee="SCNC">United States Senate Caucus on International Narcotics Control</a></li>
</ul>
</span>
</div>
</div>
<!-- End Nav -->
<!-- Main Page Content and Sidebar -->
<div class="row">
<!-- Main Content -->
<div class="large-9 columns" role="content">
<section>
<!--<div class="large-12 columns" style="margin-left:-30px;">-->
<!--</div>-->
<div class="row">
<div class="large-12 columns" id="map">
</div>
</div>
</section>
</div>
<!-- End Main Content -->
<aside class="large-3 columns" >
<div class="panel" id="member-detail">
<p>Select a committee, then click a committee member for detail.</p>
</div>
<div id="committee-list">
</div>
</aside>
<!-- End Sidebar -->
</div>
<!-- End Main Content and Sidebar -->
<!-- Footer -->
<footer class="row">
<div class="large-12 columns">
<hr />
<div class="row">
<div class="large-6 columns">
<p>Let me know if you use these maps: mroswell@gmail.com</p>
</div>
<div class="large-6 columns">
</div>
</div>
</div>
</footer>
<script>
// console.log(statesMap);
var sortedMemberNames;
var latitude = 39.9;
var longitude = -98.5;
var latLng = new L.LatLng(latitude, longitude);
var map = L.map('map').setView(latLng, 4);
var stateLayer = L.geoJson(statesMap, {
onEachFeature:onEachFeature,
style: {
fillColor: 'white',
weight: 1,
opacity: 0.21,
color: '#333333',
dashArray: '0',
fillOpacity: 0.7
}
});
stateLayer.addTo(map);
var congressLayer = L.geoJson(congressionalDistricts,
{
onEachFeature:onEachFeature,
style: {
fillColor: 'white',
weight: 1,
opacity: 0.41,
color: '#D7D7D7',
dashArray: '0',
fillOpacity: 0
}
});
congressLayer.addTo(map);
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'mroswell.i6hfjp09'
}).addTo(map);
//iadoid0h
var drawMap= function (committee) {
var committeeRequest = $.ajax({
dataType: "json",
url: "https://congress.api.sunlightfoundation.com/committees",
data: {
per_page: "all",
//chamber: "house",
committee_id: committee,
subcommittee: false,
fields: 'name,committee_id,office,subcommittee,phone,url,members',
apikey: "9e3e71730ae34e1ebbf4dd0e1c346c07"
}
}).done(function(committee){
listMembers(committee);
var members = committee.results[0].members;
var states = {};
var districtName = {};
for (var i = 0; i < members.length; i++) {
var member = members[i].legislator;
if (member.chamber==="house") {
districtName = member.state+member.district;
// console.log("member.district: ", member.district, "districtName: ", districtName)
} else {
districtName = member.state_name;
}
if (!states[districtName]) {
states[districtName] = [ member ];
} else {
states[districtName].push(member);
}
}
if (member.chamber==="house") {
stateLayer.setStyle({
fillColor: 'white',
weight: 1,
opacity: 0.41,
color: 'grey',
dashArray: '0',
fillOpacity: 0.7
});
congressLayer.setStyle(function(shape) {
// var abbreviation = stateName2Abbrev[stateFips2Name[shape.properties.STATE]];
// var district = parseInt(shape.properties.CD, 10); //04 GeoJSON; 4 Congress API
// var match = states[abbreviation+district];
var match = states[shape.properties.DISTRICT];
return colorDistrict(match,'house');
});
congressLayer.bringToFront();
} else if (member.chamber==="senate") {
congressLayer.setStyle({
display: "none",
opacity: 0,
fillColor: "transparent"
});
stateLayer.setStyle(function(shape) {
var match = states[shape.properties.name];
// console.log('MATCH-SENATE', match);
return colorDistrict(match,'senate');
});
stateLayer.bringToFront();
}
});
};
$("[data-committee]").on("click", function(e) {
e.preventDefault();
//console.log($(this));
var committee = $(this).data("committee");
// console.log ('committee', committee);
$(this).parent().parent()
.css('left', '-99999px')
.removeClass("open");
drawMap(committee);
});
function colorDistrict(committee, chamber) {
if (!committee) {
if (chamber === "house") {
return {
display: "none",
opacity: 0,
fillColor: "transparent"
}
} else {
return {
fillColor: '#ffffff',
weight: 1,
opacity: 0.41,
color: 'grey',
dashArray: '0',
fillOpacity: 0.7
};
}
}
var parties = _.map(committee, function(member){
return member.party;
});
var hasDem = parties.indexOf("D") > -1;
var hasRep = parties.indexOf("R") > -1;
var hasInd = parties.indexOf("I") > -1;
var color;
if ((hasDem && hasRep) || (hasDem && hasInd)|| (hasRep && hasInd)) {
color = "#84207C";//"#86307A";//"purple";
} else if (hasDem) {
color = "blue";//"#0920d3";//"#1464C8";//"#2553A8";//"#0F2CB9";//"#0B22E3";//"#1B55B9";//"#1644C7";//"#2166AC";//"#4393C3";//"#2424FF"; //80% blue
} else if (hasInd) {
color = "#00B0A7";
} else {
color = "red";//"#d30c09";//"#c81714";//"#F1100D";//"#DD2820";//"#D73027";//"#B2182B";//"red";
}
return {
fillColor: color,
weight: 1,
opacity: 1,
color: 'white',
dashArray: '0',
fillOpacity: 0.7
};
}
function listMembers(committee) {
var arrayOfCommitteeChairs = [];
var arrayOfCommitteeMembers = [];
_.each(committee.results[0].members, function (member) {
var memberObject = member.legislator;
memberObject.title = member.title;
if (memberObject.office != null) {
memberObject.office = memberObject.office.replace("Building", "Bldg.");
}
memberObject.stateAbbreviation = memberObject.state;
if (memberObject.title) {
arrayOfCommitteeChairs.push(memberObject);
} else {
arrayOfCommitteeMembers.push(memberObject);
}
});
var sortedArrayOfMemberChairs = _(arrayOfCommitteeChairs).sortBy("title");
var sortedArrayOfMemberNames = _(arrayOfCommitteeMembers).sortBy("last_name");
sortedMemberNames = sortedArrayOfMemberChairs.concat(sortedArrayOfMemberNames);
var context = {
committee_abbrev: committee.results[0].committee_id,
committee_name: committee.results[0].name,
committee_results: committee.results[0],
committee_members: committee.results[0].members[0].legislator,
sorted_members: sortedMemberNames,
first_name: committee.results[0].members[0].legislator.first_name,
title: committee.results[0].members[0].title
};
var html = app.memberTemplate(context);
$('#committee-list')
.html(html);
var memberDetail;
$("[data-member-id]").on("click", function(e) {
var ID = $(this).data("member-id");
memberDetail = _.findWhere(sortedMemberNames, {bioguide_id: ID});
memberDetailFunction(memberDetail);
});
}
function memberDetailFunction(mDetail){
var memberContext = {
members: mDetail instanceof Array ? mDetail : [mDetail]
};
// console.log("memberContext: ", memberContext);
var htmlDetail = app.memberDetail(memberContext);
// var htmlDetail = templateDetail(memberContext);
if (memberContext.members.length>0) {
// console.log("length > 1", memberContext.members.length);
$('#member-detail').html(htmlDetail);
} else {
$('#member-detail').html('<p>Click a committee member<br />for detail. <br />Click the <i class="fa fa-link"></i> icon to visit the committee website. (It will open in a new window.) </p>');
}
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: mapMemberDetail
});
}
function membersFromBoundary(boundary) {
var color = checkColor(boundary)
var members = [];
if (color === "blue" || color === "red" || color === "#84207C" || color == "#00B0A7") {
for (var member in sortedMemberNames) {
if (boundary.feature.properties.name) {
var abbreviation = stateName2Abbrev[boundary.feature.properties.name];
if (abbreviation === sortedMemberNames[member].stateAbbreviation) {
members.push(sortedMemberNames[member]);
}
// } else if (boundary.feature.properties.CD) {
} else if (boundary.feature.properties.DISTRICT) {
if (boundary.feature.properties.DISTRICT ===sortedMemberNames[member].stateAbbreviation+sortedMemberNames[member].district) {
// console.log("member", member);
members.push(sortedMemberNames[member]);
}
}
}
}
return members;
}
function mapMemberDetail(e) {
var boundary = e.target;
var members = membersFromBoundary(boundary);
memberDetailFunction(members);
}
function checkColor(layer) {
if (layer.options) {
return layer.options.fillColor;
} else if (layer._layers) {
for (var polyID in layer._layers) {
return layer._layers[polyID].options.fillColor;
}
}
}
function highlightFeature(e) {
// TODO: limit highlight to last-selected layer (House, senate, joint)
// TODO: limit popup hover to committee members
var boundary = e.target;
var color = checkColor(e.target);
var members = membersFromBoundary(boundary);
info.update(members);
// console.log(e)
if (color === "blue" || color === "red" || color === "#84207C" || color === "#00B0A7") {
boundary.setStyle({
weight: 2,
color: '#666'
});
}
if (!L.Browser.ie && !L.Browser.opera) {
// boundary.bringToFront();
}
}
function resetHighlight(e) {
info.update();
var layer = e.target;
var color = checkColor(e.target);
// TODO: reset back to proper committee member party color
//console.log('RESET Function');
if (color === "blue" || color === "red" || color === "#84207C" || color ==="#00B0A7") {
layer.setStyle({
weight: 1,
color: '#ffffff'
});
}
// stateLayer.resetStyle(e.target);
}
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
// method that we will use to update the control based on feature properties passed
info.update = function (members) {
var memberContext = {
members: members
};
// console.log("memberContext: ", memberContext);
var htmlDetail = app.templateDetail(memberContext);
// console.log("members", members);
this._div.innerHTML = htmlDetail;
};
var app = {};
function init() {
var source = $("#committee-member-template")
.html();
app.memberTemplate = Handlebars.compile(source);
var sourceHover = $("#map-hover-template")
.html();
app.templateDetail = Handlebars.compile(sourceHover);
var source2 = $("#committee-member-detail-template")
.html();
app.memberDetail = Handlebars.compile(source2);
info.addTo(map);
}
init();
</script>
</body>
</html>