-
Notifications
You must be signed in to change notification settings - Fork 2
/
cong-index-after-link-added.html
430 lines (360 loc) · 19 KB
/
cong-index-after-link-added.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
<!DOCTYPE html>
<html>
<head>
<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.6.4/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/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/gz_2010_us_040_00_20m.js"></script>
<script src="maps/cd_dists.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-committee="{{committee_abbrev}}">
{{memberFirstName}} {{memberLastName}}{{#if title}}, {{title}}{{/if}}</a></li>{{/each}}
</ul>
</div>
</script>
<script id="committee-member-detail-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-committee="{{committee_abbrev}}">
{{memberFirstName}} {{memberLastName}}{{#if title}}, {{title}}{{/if}}</a></li>{{/each}}
</ul>
</div>
</script>
</head>
<body>
<script>
$(document).foundation();
</script>
<div class="row">
<div class="large-12 columns">
<h1><small>Congressional Committee Maps</small></h1>
</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">
<a href="#" 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="javascript:void(0);" data-committee="HSAG">House Committee on Agriculture</a></li>
<li><a href="javascript:void(0);" data-committee="HSAP">House Committee on Appropriations</a></li>
<li><a href="javascript:void(0);" data-committee="HSAS">House Committee on Armed Services</a></li>
<li><a href="javascript:void(0);" data-committee="HSBA">House Committee on Financial Services</a></li>
<li><a href="javascript:void(0);" data-committee="HSBU">House Committee on the Budget</a></li>
<li><a href="javascript:void(0);" data-committee="HSED">House Committee on Education and the Workforce</a></li>
<li><a href="javascript:void(0);" data-committee="HSFA">House Committee on Foreign Affairs</a></li>
<li><a href="javascript:void(0);" data-committee="HSGO">House Committee on Oversight and Government Reform</a></li>
<li><a href="javascript:void(0);" data-committee="HSHA">House Committee on House Administration</a></li>
<li><a href="javascript:void(0);" data-committee="HSHM">House Committee on Homeland Security</a></li>
<li><a href="javascript:void(0);" data-committee="HSIF">House Committee on Energy and Commerce</a></li>
<li><a href="javascript:void(0);" data-committee="HSII">House Committee on Natural Resources</a></li>
<li><a href="javascript:void(0);" data-committee="HSJU">House Committee on the Judiciary</a></li>
<li><a href="javascript:void(0);" data-committee="HSPW">House Committee on Transportation and Infrastructure</a></li>
<li><a href="javascript:void(0);" data-committee="HSRU">House Committee on Rules</a></li>
<li><a href="javascript:void(0);" data-committee="HSSM">House Committee on Small Business</a></li>
<li><a href="javascript:void(0);" data-committee="HSSO">House Committee on Ethics</a></li>
<li><a href="javascript:void(0);" data-committee="HSSY">House Committee on Science, Space, and Technology</a></li>
<li><a href="javascript:void(0);" data-committee="HSVR">House Committee on Veterans' Affairs</a></li>
<li><a href="javascript:void(0);" data-committee="HSWM">House Committee on Ways and Means</a></li>
<li><a href="javascript:void(0);" 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;">
<li><a href="javascript:void(0);" data-committee="SSAF">Senate Committee on Agriculture, Nutrition, and Forestry</a></li>
<li><a href="javascript:void(0);" data-committee="SSAP">Senate Committee on Appropriations</a></li>
<li><a href="javascript:void(0);" data-committee="SSAS">Senate Committee on Armed Services</a></li>
<li><a href="javascript:void(0);" data-committee="SSBK">Senate Committee on Banking, Housing, and Urban Affairs</a></li>
<li><a href="javascript:void(0);" data-committee="SSBU">Senate Committee on the Budget</a></li>
<li><a href="javascript:void(0);" data-committee="SSCM">Senate Committee on Commerce, Science, and Transportation</a></li>
<li><a href="javascript:void(0);" data-committee="SSEG">Senate Committee on Energy and Natural Resources</a></li>
<li><a href="javascript:void(0);" data-committee="SSEV">Senate Committee on Environment and Public Works</a></li>
<li><a href="javascript:void(0);" data-committee="SSFI">Senate Committee on Finance</a></li>
<li><a href="javascript:void(0);" data-committee="SSFR">Senate Committee on Foreign Relations</a></li>
<li><a href="javascript:void(0);" data-committee="SSGA">Senate Committee on Homeland Security and Governmental Affairs</a></li>
<li><a href="javascript:void(0);" data-committee="SSHR">Senate Committee on Health, Education, Labor, and Pensions</a></li>
<li><a href="javascript:void(0);" data-committee="SLIA">Senate Committee on Indian Affairs</a></li>
<li><a href="javascript:void(0);" data-committee="SSJU">Senate Committee on the Judiciary</a></li>
<li><a href="javascript:void(0);" data-committee="SSRA">Senate Committee on Rules and Administration</a></li>
<li><a href="javascript:void(0);" data-committee="SSSB">Senate Committee on Small Business and Entrepreneurship</a></li>
<li><a href="javascript:void(0);" data-committee="SSVA">Senate Committee on Veterans' Affairs</a></li>
<li><a href="javascript:void(0);" data-committee="SLET">Senate Select Committee on Ethics</a></li>
<li><a href="javascript:void(0);" data-committee="SLIN">Senate Select Committee on Intelligence</a></li>
<li><a href="javascript:void(0);" data-committee="SPAG">Senate Special Committee on Aging</a></li>
<li><a href="javascript:void(0);" data-committee="SCNC">United States Senate Caucus on International Narcotics Control</a></li>
</ul>
<a href="#" class="button committeeButton" data-dropdown="tinyDropJoint" data-options="is_hover:true">Joint Committees »</a>
<ul id="tinyDropJoint" class="f-dropdown" data-dropdown-content style="position: absolute; top: 230px; left: -99999px;">
<li><a href="javascript:void(0);" data-committee="JSTX">Joint Committee on Taxation</a></li>
<li><a href="javascript:void(0);" data-committee="JSPR">Joint Committee on Printing</a></li>
<li><a href="javascript:void(0);" data-committee="JSLC">Joint Committee on the Library</a></li>
<li><a href="javascript:void(0);" data-committee="JSEC">Joint Economic Committee</a></li>
<li><a href="javascript:void(0);" data-committee="JCSE">Commission on Security and Cooperation in Europe"</a></li>
</ul>
</div>
<div class="row">
<div class="large-12 columns" id="map">
</div>
</div>
</section>
</div>
<!-- End Main Content -->
<!-- Sidebar -->
<aside class="large-3 columns">
<div class="panel" id=committee-detail-list">
<h5>Featured</h5>
<p>Click a district or member for detail.</p>
</div>
<div id="committee-list">
<!--<h5>Committee Members</h5>-->
</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: [email protected]</p>
</div>
<div class="large-6 columns">
</div>
</div>
</div>
</footer>
<script>
var latitude = 39.9;
var longitude = -98.5;
var latLng = new L.LatLng(latitude, longitude);
var map = L.map('map').setView(latLng, 4);
// var marker = L.marker(latLng).addTo(map);
var stateLayer = L.geoJson(statesMap);
stateLayer.addTo(map).setStyle(function(shape) {
return {
fillColor: 'white',
weight: 1,
opacity: 0.41,
color: 'grey',
dashArray: '3',
fillOpacity: 0.7
};
});
var congressLayer = L.geoJson(congressionalDistricts);
congressLayer.addTo(map);
L.tileLayer('http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png', {
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://cloudmade.com">CloudMade</a>',
key: '4733d063f9704b1c940a64459b1263e9',
styleId: 96931,
maxZoom: 18
}).addTo(map);
var drawDistricts = function (responseData) {
L.geoJson(congressionalDistricts).addTo(map);
};
// create variable called committeeRequest that asks Congress API for the members of the
// House Agriculture Committee
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") {
console.log(member.chamber);
districtName = member.state+member.district;
console.log(districtName);
} else {
districtName = member.state_name;
console.log(districtName);
}
if (!states[districtName]) {
states[districtName] = [ member ];
} else {
states[districtName].push(member);
}
}
console.log(states);
if (member.chamber==="house") {
stateLayer.setStyle({
fillColor: 'white',
weight: 1,
opacity: 0.41,
color: 'grey',
dashArray: '3',
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];
console.log("match: " , match);
return colorDistrict(match,'house');
})
} else if (member.chamber==="senate") {
congressLayer.setStyle({
display: "none",
opacity: 0,
fillColor: "transparent"
});
stateLayer.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.NAME];
console.log('match: ' + match);
return colorDistrict(match,'senate');
})
}
});
};
//drawMap('HSAG');
$("[data-committee]").on("click", function(e) {
//console.log($(this));
var committee = $(this).data("committee");
//console.log("dropdown: ", $(this));
var committeeName = $(this).text();
//$('#whichCommittee').empty();
//$('#whichCommittee').append(committeeName);
//console.log("parent", $(this).parent().parent());
$(this).parent().parent()
.css('left', '-99999px')
.removeClass("open");
drawMap(committee);
});
//$('.committeeButton').on("click",function(){
function colorDistrict(committee, chamber) {
if (!committee) {
if (chamber === "house") {
return {
display: "none",
opacity: 0,
fillColor: "transparent"
}
} else {
return {
fillColor: 'white',
weight: 1,
opacity: 0.41,
color: 'grey',
dashArray: '3',
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 color;
if (hasDem && hasRep) {
color = "purple";
} else {
if (hasDem) {
color = "blue";
} else {
color = "red";
}
}
return {
fillColor: color,
weight: 1,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
function listMembers(committee) {
console.log(committee.results[0].name);
var source = $("#committee-member-template")
.html();
var source2 = $("#committee-member-detail-template")
.html();
var templateOrig = Handlebars.compile(source);
var template2 = Handlebars.compile(source2);
// console.log(committee.results[0].members);
// console.log(committee.results[0].members[0].legislator);
// console.log(committee.results[0].members[0].legislator.first_name);
//var parseCongressionalCommitteeResponse = function (congressionalCommittee) {
// create array that will be populated with state names
var arrayOfCommitteeChairs = [];
var arrayOfCommitteeMembers = [];
var committeeNamesObj = {};
_.each(committee.results[0].members, function(member, index){
var memberObject = {
memberFirstName: member.legislator.first_name,
memberLastName: member.legislator.last_name,
title: member.title
};
if (memberObject.title) {
arrayOfCommitteeChairs.push(memberObject);
} else {
arrayOfCommitteeMembers.push(memberObject);
}
})
var sortedArrayOfMemberNames = _(arrayOfCommitteeMembers).sortBy("memberLastName");
var sortedArrayOfMemberChairs = _(arrayOfCommitteeChairs).sortBy("title");
var sortedMemberNames = sortedArrayOfMemberChairs.concat(sortedArrayOfMemberNames);
console.log(sortedMemberNames);
// console.log("arrayOfCommitteeMembers", arrayOfCommitteeMembers);
//return arrayOfStateNamesForThisCommittee;
// };
var context = {
committee_abbrev: committee.results[0].committee_id,
committee_name: committee.results[0].name,
committee_results: committee.results[0],
sorted_members: sortedMemberNames,
first_name: committee.results[0].members[0].legislator.first_name,
title: committee.results[0].members[0].title
};
var html = templateOrig(context);
$('#committee-list')
.html(html);
$('#committee-detail-list')
.html(html);
console.log(committee);
}
</script>
</body>
</html>