-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
411 lines (316 loc) · 12.2 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
<html>
<head>
<title>Query Census API</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<style>
option[disabled]{
display:none;
}
</style>
</head>
<body onunload="">
<div class="container">
<div class="jumbotron">
<h1>Census API</h1>
<p>Created By: Colorado State Demography Office</p>
</div>
<div class="row">
<div class="col-sm-8">
<h3>Select Dataset & Table:</h3>
<!-- $('#dataset').val(); -->
<select class="form-control" style="width:50%;" id="dataset">
<option value="c1980">1980 Census</option>
<option value="c1990">1990 Census</option>
<option value="c2000">2000 Census</option>
<option value="c2010">2010 Census</option>
<option value="c2020">2020 Census</option>
<option value="acs0610">2006-2010 ACS</option>
<option value="acs0711">2007-2011 ACS</option>
<option value="acs0812">2008-2012 ACS</option>
<option value="acs0913">2009-2013 ACS</option>
<option value="acs1014">2010-2014 ACS</option>
<option value="acs1115">2011-2015 ACS</option>
<option value="acs1216">2012-2016 ACS</option>
<option value="acs1317">2013-2017 ACS</option>
<option value="acs1418">2014-2018 ACS</option>
<option value="acs1519">2015-2019 ACS</option>
<option value="acs1620">2016-2020 ACS</option>
<option value="acs1721">2017-2021 ACS</option>
<option value="acs1822">2018-2022 ACS</option>
<option value="acs1923" selected>2019-2023 ACS</option>
</select>
<br /><br />
<form class="form-horizontal">
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label">Filter</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="tableSearch" placeholder="Search Tables...">
</div>
<div class="col-sm-2">
</div>
</div>
</form>
<div class="form-group">
<select class="form-control" id="tables" style="width:90%;" size='15'>
</select>
</div>
</div>
<div class="col-sm-4">
<h3>Select Geography:</h3>
<!-- $('#sumlev').val(); -->
<select class="form-control" style="width:90%;" id="sumlev">
<option value="state" selected>All States</option>
<option value="county">All Counties</option>
<option value="place">All Places</option>
<option value="tract">All Census Tracts</option>
<option value="bg">All Census Block Groups</option>
</select>
<p style="width:90%; margin-top: 10px; text-align:center;" class="dontshow">in</p>
<!-- $('#statesel').val(); -->
<select class="form-control dontshow" style="width:90%;" id="statesel" >
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="4">Arizona</option>
<option value="5">Arkansas</option>
<option value="6">California</option>
<option value="8" selected>Colorado</option>
<option value="9">Connecticut</option>
<option value="10">Delaware</option>
<option value="11">District of Columbia</option>
<option value="12">Florida</option>
<option value="13">Georgia</option>
<option value="15">Hawaii</option>
<option value="16">Idaho</option>
<option value="17">Illinois</option>
<option value="18">Indiana</option>
<option value="19">Iowa</option>
<option value="20">Kansas</option>
<option value="21">Kentucky</option>
<option value="22">Louisiana</option>
<option value="23">Maine</option>
<option value="24">Maryland</option>
<option value="25">Massachusetts</option>
<option value="26">Michigan</option>
<option value="27">Minnesota</option>
<option value="28">Mississippi</option>
<option value="29">Missouri</option>
<option value="30">Montana</option>
<option value="31">Nebraska</option>
<option value="32">Nevada</option>
<option value="33">New Hampshire</option>
<option value="34">New Jersey</option>
<option value="35">New Mexico</option>
<option value="36">New York</option>
<option value="37">North Carolina</option>
<option value="38">North Dakota</option>
<option value="39">Ohio</option>
<option value="40">Oklahoma</option>
<option value="41">Oregon</option>
<option value="42">Pennsylvania</option>
<option value="44">Rhode Island</option>
<option value="45">South Carolina</option>
<option value="46">South Dakota</option>
<option value="47">Tennessee</option>
<option value="48">Texas</option>
<option value="49">Utah</option>
<option value="50">Vermont</option>
<option value="51">Virginia</option>
<option value="53">Washington</option>
<option value="54">West Virginia</option>
<option value="55">Wisconsin</option>
<option value="56">Wyoming</option>
</select>
<br /><br />
<p><b>OR</b> Search for a Specific Geography</p>
<div id="typeparent">
<input id="type" class="typeahead" type="text" data-provide="typeahead" autocomplete="off">
</div>
<br /><br /><br />
<div class="checkbox">
<label><input id="checkmoe" type="checkbox" value="" >Include Margin of Error (ACS Only)</label>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<hr />
<input class="btn btn-default" type="submit" value="Get CSV" onclick="send('csv','demog');"> <input class="btn btn-default" type="submit" value="Get JSON" onclick="send('json','demog');"> <input class="btn btn-default" type="submit" value="Get GeoJSON" onclick="send('json','geojson');">
<br />
<br />
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="typeahead/bootstrap3-typeahead.min.js"></script>
<script src="typeahead/typeaheadplacedata.js"></script>
<script>
var selectgeonum='';
var $input;
$(document).ready(function() {
$input = $('.typeahead');
$input.typeahead({source: typeaheadplacedata,
autoSelect: true,
minLength: 3});
//below is prob useless?
$input.change(function() {
var current = $input.typeahead("getActive");
selectgeonum = (current.id);
if (current) {
// Some item from your model is active!
if (current.name == $input.val()) {
// This means the exact match is found. Use toLowerCase() if you want case insensitive match.
selectgeonum = (current.id);
} else {
// This means it is only a partial match, you can either add a new item
// or take the active if you don't want new items
selectgeonum = (current.id);
}
} else {
// Nothing is active so it is a new value (or maybe empty value)
}
});
//initial setup
$('#sumlev').val('state');
$('#statesel').val('8');
$('#dataset').val('acs1923');
$('#tableSearch').val('');
$('#checkmoe').prop('checked', false);
$('.dontshow').hide();
//load acs1014 tables into box
loadtables('acs1923','data');
//setup events
$( "#sumlev" ).on( "change", function() {
if($( this ).val()=='state'){ $('.dontshow').hide();}
if($( this ).val()=='county'){ $('.dontshow').show();}
if($( this ).val()=='place'){ $('.dontshow').show();}
if($( this ).val()=='tract'){ $('.dontshow').show();}
if($( this ).val()=='bg'){ $('.dontshow').show();}
}); //end sumlev on change
$( "#dataset" ).on( "change", function() {
$('#tables').empty();
if($(this).val()=='acs1923'){
loadtables('acs1923','data');
}
if($(this).val()=='acs1822'){
loadtables('acs1822','data');
}
if($(this).val()=='acs1721'){
loadtables('acs1721','data');
}
if($(this).val()=='acs1620'){
loadtables('acs1620','data');
}
if($(this).val()=='acs1519'){
loadtables('acs1519','data');
}
if($(this).val()=='acs1418'){
loadtables('acs1418','data');
}
if($(this).val()=='acs1317'){
loadtables('acs1317','data');
}
if($(this).val()=='acs1216'){
loadtables('acs1216','data');
}
if($(this).val()=='acs1115'){
loadtables('acs1115','data');
}
if($(this).val()=='acs1014'){
loadtables('acs1014','data');
}
if($(this).val()=='acs0913'){
loadtables('acs0913','data');
}
if($(this).val()=='acs0812'){
loadtables('acs0812','data');
}
if($(this).val()=='acs0711'){
loadtables('acs0711','data');
}
if($(this).val()=='acs0610'){
loadtables('acs0610','data');
}
if($(this).val()=='c2020'){
loadtables('c2020','data');
}
if($(this).val()=='c2010'){
loadtables('c2010','data');
}
if($(this).val()=='c2000'){
loadtables('c2000','sf1');
loadtables('c2000','sf3');
}
if($(this).val()=='c1990'){
loadtables('c1990','sf1');
loadtables('c1990','sf3');
}
if($(this).val()=='c1980'){
loadtables('c1980','sf1');
loadtables('c1980','sf3');
}
}); //end dataset on change
$( "#tableSearch" ).on( "keyup", function() {
$( ".toptions" ).each(function( index ) {
if(($( this ).text().toLowerCase().indexOf($( "#tableSearch" ).val().toLowerCase()))< 0){$( this ).prop('disabled',true);}else{$( this ).prop('disabled',false);}
});
}); //end table search on key up
}); //end document ready
function loadtables(db, schema){
$.ajax({
url: "https://gis.dola.colorado.gov/capi/meta?db="+db+"&schema="+schema,
dataType: 'json',
success: showdata
});
function showdata(data){
var showschema='';
if(db=='c1980'){showschema=schema+" - ";}
if(db=='c1990'){showschema=schema+" - ";}
if(db=='c2000'){showschema=schema+" - ";}
var dropdowntables="";
for(i=0;i<data.length;i++){
dropdowntables=dropdowntables+"<option class='toptions' >"+showschema+data[i].table_id+": "+data[i].table_title+"</option>";
}
$('#tables').append(dropdowntables);
}
}; //end loadtables
function send(type, api){
var table, schema, res, subsplit, sumlev, geonum;
//if havent selected a table yet
if($('select[id=tables]').val()==null){alert('Please select a table!'); return 0;}
//sumlev
var geodescription = $('#sumlev').val();
if(geodescription=='state'){sumlev='40';}
if(geodescription=='county'){sumlev='50';}
if(geodescription=='place'){sumlev='160';}
if(geodescription=='tract'){sumlev='140';}
if(geodescription=='bg'){sumlev='150';}
//selected state
var state = '&state=' + $('#statesel').val();
if(geodescription=='state'){state='';} //choosing 1 state is disabled
//dataset
var dataset = $('#dataset').val();
//selected table text
var tablestring=$('select[id=tables]').val();
//check for moe checkbox
var moe='';
if($('#checkmoe').is(':checked')){moe='&moe=yes';}
if($input.val()==''){geonum='';}else{if(selectgeonum!==''){geonum='&geonum='+selectgeonum}}
//parse option text to get schema and table information
if(dataset=='c1980' || dataset=='c1990' || dataset=='c2000'){
res = tablestring.split(" - ");
schema = res[0];
subsplit=res[1].split(":");
table=subsplit[0];
}else{
schema='data';
res = tablestring.split(":");
table=res[0].toLowerCase();
}
//send to demog.php
window.location.href = 'https://gis.dola.colorado.gov/capi/' + api + '?limit=99999&db='+dataset+'&schema='+schema+'&table='+table+'&sumlev='+sumlev+'&type='+type+moe+state+geonum;
}
</script>
</body>
</html>