-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
742 lines (681 loc) · 27.4 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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
<!DOCTYPE html>
<html>
<head>
<title>Tenants Map | CARTO</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Lato:400,600,700|Open+Sans:300,400,600" rel="stylesheet">
<!-- Include Leaflet -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<link href="https://unpkg.com/[email protected]/dist/leaflet.css" rel="stylesheet">
<!-- Include CARTO.js -->
<script src="https://libs.cartocdn.com/carto.js/v4.0.8/carto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<link href="https://carto.com/developers/carto-js/examples/maps/public/style.css" rel="stylesheet">
<style>
* { margin:0; padding:0; }
html { box-sizing:border-box; height:100%; }
body { background:#f2f6f9; height:100%; font-family:"lato"; font-weight:normal;overflow: hidden;}
h1, h2, h3, h5, h5, h6 {
font-family:"lato" !important;
font-weight:normal !important;
padding-bottom: 5px;
margin: 0px 0px !important;
}
label {
font-family:"lato" !important;
}
p {
font-family:"lato" !important;
}
.bold {font-weight:bold !important;}
.lighter {color:#444444;}
hr {margin-bottom: 10px; margin-top: 10px;}
#container { display:flex; width:100%; height:100%; }
#map { flex:1; margin:10px; }
.separator{
min-height: 1px;
background-color: rgba(46, 60, 67, 0.08);
margin: 16px 0;
}
.toolbox_left {
position: absolute;
bottom: 24px;
left: 24px;
min-width: 300px;
max-width: 300px;
z-index: 2;
}
.toolbox {
position:relative;
overflow-y:hidden;
}
#info-box {
overflow-y:auto;
position:relative;
overflow-x:hidden;
height:600px;
}
#info-box, #canvas1, #canvas2, #canvas3 {
display:none;
}
.icon {
margin-left: 5px;
margin-right:3px;
}
.legend-text {
font-size:11px;
}
label {
font-size:14px !important;
}
#no_results {
display:none;
}
.close-button,.reset_map{
font-size:11px;
float:right;
}
.clearfix {
overflow: auto;
}
.dashed_line {
border:none;
border-top:2px dashed #000;
color:#fff;
background-color:#fff;
height:1px;
width:15%;
margin-right: 10px;
float: left;
}
.solid_line {
border:none;
border-top:2px solid #000;
color:#fff;
background-color:#fff;
height:1px;
width:15%;
margin-right: 10px;
float: left;
}
.gradient_box {
background: linear-gradient(to right, #ffffb2, #b10026);
width: 15%;
height:15px;
float: left;
margin-top: 5px;
margin-right: 10px;
border:0.5px solid black;
}
.margin_bottom {
margin-bottom:5px;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- Description -->
<aside class="toolbox_left">
<div class="box">
<header>
<h1 class = "bold">Tenants Map</h1>
</header>
<div class="separator"></div>
<h4 class="lighter">Instructions</h4>
<h5 class="lighter">Click on a feature for more information about the property's units, rent-stabilization, and housing complaints.</h5>
<div class="separator"></div>
<section>
<h4 class="lighter">Legend</h4>
<div class="clearfix margin_bottom">
<hr class="solid_line"> <p class="legend-text"> (<em>black solid outline</em>) Contains rent-stabilized units according to <em>both</em> the Rent Guidelines Board and NYC Property Tax Bills. </p>
</div>
<div class="clearfix margin_bottom">
<hr class="dashed_line"> <p class="legend-text"> (<em>black dased outline</em>) Contains rent-stabilized units according to <em>either</em> the Rent Guidelines Board or NYC Property Tax Bills. </p>
</div>
<div class="clearfix margin_bottom">
<div class="gradient_box"></div><p class="legend-text">(<em>parcel color</em>) Tax lots are shaded according to the increasing number of housing-related 311 complaints made about the property since 2015 </p>
</div>
<div class="separator"></div>
<h4 class="lighter">Filter to a community district.</h4>
<ul class="actions">
<label>Community District:</label> <select id="community_district">
<option value="101">101</option>
<option value="102">102</option>
<option value="103">103</option>
<option value="104">104</option>
<option value="105">105</option>
<option value="106">106</option>
<option value="107">107</option>
<option value="108">108</option>
<option value="109">109</option>
<option value="110">110</option>
<option value="111">111</option>
<option value="112">112</option>
</select>
<input type="submit" value="Search" onclick="set_cd()">
</ul>
<div class="separator"></div>
<h4 class="lighter">Search for a Manhattan address.</h4>
<label>Address:</label> <input id="address" onfocus="this.value=''" type="text" name="address" value="" size="20"><br/>
<input type="submit" value="Search" onclick="set_address()">
<div id="no_results"><p>No results found.</p></div>
<a href="#" onclick="reset_map();" class="reset_map">Reset Map</a>
</div>
</aside>
<aside class="toolbox">
<div id="info-box" class="box clearfix">
<div id="info"></div>
<div id="rent_info"></div>
<canvas id="canvas3"></canvas>
<div id="311_info"></div>
<canvas id="canvas1" height="300px"></canvas>
<canvas id="canvas2"></canvas>
<div id="source"></div>
<a href="#" onclick="toggle_visibility('info-box');" class="close-button">Close Window</a>
</div>
</section>
<footer class="js-footer"></footer>
</div>
</aside>
<script>
const map = L.map('map').setView([40.73, -74], 15);
map.scrollWheelZoom.disable();
L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/rastertiles/voyager/{z}/{x}/{y}{r}.png', {
maxZoom: 18
}).addTo(map);
const client = new carto.Client({
apiKey: '0cdd88f5e816766aec13f416ec14b633e6ecb4b6',
username: 'betanyc'
});
var api_key = '0cdd88f5e816766aec13f416ec14b633e6ecb4b6';
const source_rent = new carto.source.SQL(`
WITH
o AS (
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_after_20180101_1 GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2017_18_1
GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2016_1
GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2015_16_1
GROUP BY bbl)
),
m AS (
SELECT bbl, SUM(number_complaints) complaints
FROM o
GROUP BY bbl
)
SELECT right_source.cartodb_id cartodb_id, right_source.the_geom_webmercator the_geom_webmercator, m.complaints, right_source.pluto_bbl, right_source.pluto_policeprct, right_source.rent_pdf_cartodb_id, right_source.rent_pdf_status1, right_source.rent_pdf_status2, right_source.rent_pdf_status3, right_source.pluto_cd, right_source.pluto_council, right_source.pluto_zipcode, right_source.pluto_firecomp, right_source.pluto_address, right_source.pluto_ownername, right_source.pluto_numfloors, right_source.pluto_unitsres, right_source.pluto_unitstotal, right_source.pluto_yearbuilt, right_source.pluto_histdist, right_source.pluto_landmark, right_source.krauss_cartodb_id, right_source.pluto_schooldist
FROM m
RIGHT JOIN rent_stabilized_plus_tax_data AS right_source
ON right_source.pluto_bbl = m.bbl
WHERE right_source.pluto_unitsres > 0
`);
const style_rent = new carto.style.CartoCSS(`
#layer {
polygon-fill: ramp([complaints], (#ffffb2, #fed976, #feb24c, #fd8d3c, #fc4e2a, #e31a1c, #b10026), jenks);
::backline [rent_pdf_cartodb_id=null][krauss_cartodb_id=null]{
line-color: #bcbcbc;
line-opacity: 1;
[zoom >= 17] {line-width: .75}
[zoom < 17] {line-width: .5}
[zoom < 16] {line-width: .25}
[zoom < 15] {line-width: .1}
[zoom < 14] {line-width: .05}
}
::dashline [rent_pdf_cartodb_id!=null][krauss_cartodb_id!=null]{
line-color: #000000;
line-opacity: 1;
[zoom >= 18] {line-width: 1.75}
[zoom < 18] {line-width: 1.5}
[zoom < 17] {line-width: 1}
[zoom < 16] {line-width: .75}
[zoom < 15] {line-width: .5}
[zoom < 14] {line-width: .25}
}
::dashline [rent_pdf_cartodb_id!=null][krauss_cartodb_id=null]{
line-color: #000000;
line-opacity: 1;
line-dasharray: 5, 3;
[zoom >= 18] {line-width: 1.75}
[zoom < 18] {line-width: 1.5}
[zoom < 17] {line-width: 1}
[zoom < 16] {line-width: .75}
[zoom < 15] {line-width: .5}
[zoom < 14] {line-width: .25}
}
::frontline [rent_pdf_cartodb_id=null][krauss_cartodb_id!=null]{
line-color: #000000;
line-opacity: 1;
line-dasharray: 5, 3;
[zoom >= 18] {line-width: 1.75}
[zoom < 18] {line-width: 1.5}
[zoom < 17] {line-width: 1}
[zoom < 16] {line-width: .75}
[zoom < 15] {line-width: .5}
[zoom < 14] {line-width: .25}
}
}
`);
const layer_rent = new carto.layer.Layer(source_rent, style_rent, {featureOverColumns: ['pluto_bbl','pluto_ownername', 'pluto_address','rent_pdf_status1','rent_pdf_status2','rent_pdf_status3','pluto_cd','pluto_schooldist','pluto_council','pluto_zipcode','pluto_firecomp','pluto_policeprct','pluto_numfloors','pluto_unitsres','pluto_unitstotal','pluto_yearbuilt','pluto_histdist','pluto_landmark']});
client.addLayer(layer_rent);
layer_rent.on('featureOver', featureEvent =>{
let rent_popup_content = '';
rent_popup_content += `<div class="widget">`;
rent_popup_content += `<p class = "bold">${featureEvent.data.pluto_address}</p>`;
popup.setContent(rent_popup_content);
popup.setLatLng(featureEvent.latLng);
if (!popup.isOpen()) {
popup.openOn(map);
}
});
var complaint_chart;
var year_chart;
var units_year_chart;
var LabelsPlugin = {afterDatasetsDraw: function(chart) {
var ctx = chart.ctx;
chart.data.datasets.forEach(function(dataset, i) {
var meta = chart.getDatasetMeta(i);
if (!meta.hidden) {
meta.data.forEach(function(element, index) {
// Draw the text in black, with the specified font
ctx.fillStyle = 'rgb(100, 100, 100)';
var fontSize = 10;
var fontStyle = 'normal';
var fontFamily = 'Helvetica Neue';
ctx.font = Chart.helpers.fontString(fontSize, fontStyle, fontFamily);
if (dataset.data[index] != null)
dataNum = dataset.data[index];
else
dataNum = 0;
// Just naively convert to string for now
var dataString = dataNum.toString();
// Make sure alignment settings are correct
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
var padding = -15;
var position = element.tooltipPosition();
if (dataString != 0) {
ctx.fillText(dataString, position.x, position.y - (fontSize / 2) - padding);
}
});
}
});
}}
layer_rent.on('featureClicked', featureEvent => {
let content = '';
let content_rent = '';
let content_311 = '';
let source = '';
content += `<h3 class = "bold">${featureEvent.data.pluto_address}</h3>
<div class="separator"></div>
<h4 class = "lighter">Property Information</h4>
<h6 class = "lighter">BBL: ${featureEvent.data.pluto_bbl}</h5>
<h6 class = "lighter">Owner Name: ${featureEvent.data.pluto_ownername}</h6>
<h6 class = "lighter">Year Built: ${featureEvent.data.pluto_yearbuilt}</h6>
<h6 class = "lighter">Residential Units: ${featureEvent.data.pluto_unitsres} of ${featureEvent.data.pluto_unitstotal}</h6>
<h6 class = "lighter">Number of Floors: ${featureEvent.data.pluto_numfloors}</h6>`;
if (featureEvent.data.rent_pdf_status1 != '') {
content += `<h6 class = "lighter">Rent Stabilized Status: ${featureEvent.data.rent_pdf_status1}`;
if (featureEvent.data.status2 != '')
content += `, ${featureEvent.data.rent_pdf_status2}`;
if (featureEvent.data.status3 != '')
content += `, ${featureEvent.data.rent_pdf_status3}`;
content += `</h6>`;
}
content += `
<div class="separator"></div>
<h4 class = "lighter">Neighborhood Information</h4>
<h6 class = "lighter">Community District: ${featureEvent.data.pluto_cd}</h6>
<h6 class = "lighter">City Council District: ${featureEvent.data.pluto_council}</h6>
<h6 class = "lighter">Police Precinct: ${featureEvent.data.pluto_policeprct}</h6>
<h6 class = "lighter">Fire Company: ${featureEvent.data.pluto_firecomp}</h6>`;
if (featureEvent.data.pluto_histdist != '' && featureEvent.data.pluto_histdist != null)
content += `<h6 class = "lighter">Historic District: ${featureEvent.data.pluto_histdist}</h6>`;
if (featureEvent.data.pluto_landmark != '' && featureEvent.data.pluto_landmark != null)
content += `<h6 class = "lighter">Landmark: ${featureEvent.data.pluto_landmark}</h6>`;
content_rent += `<div class="separator"></div>
<h4 class = "lighter">Rent-Stabilized Units</h4>`;
var url_tax = "https://betanyc.carto.com/api/v2/sql/?q=SELECT cartodb_id, _2007uc, _2008uc, _2009uc, _2010uc, _2011uc, _2012uc, _2013uc, _2014uc, _2015uc, _2016uc FROM john_krauss_tax_data WHERE ucbbl='"+featureEvent.data.pluto_bbl+"'&api_key="+api_key;
fetch(url_tax)
.then(function(response) {
return response.json();
})
.then(function(tax_data) {
if (tax_data.rows.length != 0 ) {
if (typeof units_year_chart !== 'undefined'){
units_year_chart.clear();
units_year_chart.destroy();
}
console.log("1");
percent_change = ((tax_data.rows[0]._2016uc - tax_data.rows[0]._2007uc)/tax_data.rows[0]._2007uc)*100;
ctx3 = document.getElementById("canvas3").getContext('2d');
units_year_chart = new Chart(ctx3, {
type: 'line',
plugins: LabelsPlugin,
data: {
labels: ["2007","2008","2009","2010","2011","2012","2013","2014","2015","2016"],
datasets: [{
data: [tax_data.rows[0]._2007uc, tax_data.rows[0]._2008uc, tax_data.rows[0]._2009uc, tax_data.rows[0]._2010uc, tax_data.rows[0]._2011uc, tax_data.rows[0]._2012uc, tax_data.rows[0]._2013uc, tax_data.rows[0]._2014uc, tax_data.rows[0]._2015uc, tax_data.rows[0]._2016uc],
borderColor: '#175676'
}]
},
options: {
legend: {
display: false
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
fontSize: 10
}
}],
xAxes: [{
ticks: {
fontSize: 10
}
}],
},
title: {
display: false,
text: 'Rent-Stabilized Units By Year'
}
}
});
console.log("2");
content_rent += `<h6 class = "lighter">% Change since 2007: ${percent_change.toFixed(2)}%</h6>`;
console.log("3 + content_rent");
}
else {
clear_rent_charts();
content_rent += `<h6 class = "lighter">No Available Data</h6>`;
}
});
console.log("4");
let heat = 0;
let plumbing1 = 0;
let plumbing2 = 0;
let paint = 0;
let rodent = 0;
let general_construction = 0;
let dirty_conditions = 0;
let unsanitary_conditions = 0;
let elevator = 0;
let year_arr = {};
let year_labels = [];
let year_data = [];
var url_311 = "https://betanyc.carto.com/api/v2/sql/?q=SELECT cartodb_id, complaint_type, descriptor, created_date, EXTRACT(year from to_date(created_date, 'MM/DD/YYYY')) AS created_year FROM table_311_buzzfeed_projmap_2015_16_1 WHERE bbl='"+featureEvent.data.pluto_bbl+"' UNION SELECT cartodb_id, complaint_type, descriptor, created_date, EXTRACT(year from to_date(created_date, 'MM/DD/YYYY')) AS created_year FROM table_311_buzzfeed_projmap_2016_1 WHERE bbl='"+featureEvent.data.pluto_bbl+"' UNION SELECT cartodb_id, complaint_type, descriptor, created_date, EXTRACT(year from to_date(created_date, 'MM/DD/YYYY')) AS created_year FROM table_311_buzzfeed_projmap_2017_18_1 WHERE bbl='"+featureEvent.data.pluto_bbl+"' UNION SELECT cartodb_id, complaint_type, descriptor, created_date, EXTRACT(year from to_date(created_date, 'MM/DD/YYYY')) AS created_year FROM table_311_buzzfeed_projmap_after_20180101_1 WHERE bbl='"+featureEvent.data.pluto_bbl+"'&api_key="+api_key;
let complaints_count = 0;
fetch(url_311)
.then(function(response) {
return response.json();
})
.then(function(geom_data) {
complaints_count = geom_data.rows.length;
complaints_per_unit = geom_data.rows.length/featureEvent.data.pluto_unitsres;
content_311 += `<div class="separator"></div>
<h4 class = "lighter">311 Complaints</h4>
<h6 class = "lighter">Total Number of Complaints: ${complaints_count}</h6>
<h6 class = "lighter">Average Complaints Per Residential Unit: ${complaints_per_unit.toFixed(4)}</h6>`;
if (complaints_count != 0) {
if (typeof complaint_chart !== 'undefined'){
complaint_chart.clear();
complaint_chart.destroy();
}
if (typeof year_chart !== 'undefined'){
year_chart.clear();
year_chart.destroy();
}
console.log(geom_data.rows);
for (var i = 0; i < complaints_count; i++) {
if (geom_data.rows[i].complaint_type == "HEAT/HOT WATER")
heat++;
else if (geom_data.rows[i].complaint_type == "PLUMBING")
plumbing1++;
else if (geom_data.rows[i].complaint_type == "PAINT/PLASTER")
paint++;
else if (geom_data.rows[i].complaint_type == "Plumbing")
plumbing2++;
else if (geom_data.rows[i].complaint_type == "Rodent")
rodent++;
else if (geom_data.rows[i].complaint_type == "Dirty Conditions")
dirty_conditions++;
else if (geom_data.rows[i].complaint_type == "General Construction/Plumbing")
general_construction++;
else if (geom_data.rows[i].complaint_type == "UNSANITARY CONDITIONS")
unsanitary_conditions++;
else if (geom_data.rows[i].complaint_type == "Elevator")
elevator++;
}
ctx = document.getElementById("canvas1").getContext('2d');
ctx2 = document.getElementById("canvas2").getContext('2d');
complaint_chart = new Chart(ctx, {
type: 'pie',
data: {
labels: ["HEAT/HOT WATER","PLUMBING","PAINT/PLASTER","Plumbing","Rodent","Dirty Conditions","General Construction/Plumbing","UNSANITARY CONDITIONS", "Elevator"],
datasets: [{
backgroundColor: ['#E31A1C','#FEB24C','#175676','#4BA3C3','#EC5766','#8D3B72','#0C0A3E','#00A878', '#f25c10'],
borderWidth: 0,
data: [heat, plumbing1,paint,plumbing2,rodent,dirty_conditions,general_construction, unsanitary_conditions, elevator]
}]
},
options: {
title: {
display: true,
text: 'Complaints by Complaint Type'
},
legend: {
display: true,
labels: {
fontSize: 10
},
position:'bottom',
onClick: null,
fullWidth: true
}
}
});
for (var i = 0; i < complaints_count; i++) {
year_arr[geom_data.rows[i].created_year] = 1 + (year_arr[geom_data.rows[i].created_year] || 0);
}
year_labels = Object.keys(year_arr);
year_data = Object.values(year_arr);
year_chart = new Chart(ctx2,{
type: 'line',
plugins: LabelsPlugin,
data: {
labels: year_labels,
datasets: [{
data: year_data,
borderColor: '#175676'
}]
},
options: {
legend: {
display: false
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
},
title: {
display: true,
text: 'Complaints by Year'
}
}
});
if (document.getElementById('canvas1').style.display = 'none')
document.getElementById('canvas1').style.display = 'block';
if (document.getElementById('canvas2').style.display = 'none')
document.getElementById('canvas2').style.display = 'block';
}
else {
clear_311_charts();
}
show_info_box();
document.getElementById('info').innerHTML = content;
document.getElementById('rent_info').innerHTML = content_rent;
document.getElementById('311_info').innerHTML = content_311;
document.getElementById('source').innerHTML = source;
});
});
function reset_map() {
source_rent.setQuery(`WITH
o AS (
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_after_20180101_1 GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2017_18_1
GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2016_1
GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2015_16_1
GROUP BY bbl)
),
m AS (
SELECT bbl, SUM(number_complaints) complaints
FROM o
GROUP BY bbl
)
SELECT right_source.cartodb_id cartodb_id, right_source.the_geom_webmercator the_geom_webmercator, m.complaints, right_source.pluto_bbl, right_source.pluto_policeprct, right_source.rent_pdf_cartodb_id, right_source.rent_pdf_status1, right_source.rent_pdf_status2, right_source.rent_pdf_status3, right_source.pluto_cd, right_source.pluto_council, right_source.pluto_zipcode, right_source.pluto_firecomp, right_source.pluto_address, right_source.pluto_ownername, right_source.pluto_numfloors, right_source.pluto_unitsres, right_source.pluto_unitstotal, right_source.pluto_yearbuilt, right_source.pluto_histdist, right_source.pluto_landmark, right_source.krauss_cartodb_id, right_source.pluto_schooldist
FROM m
RIGHT JOIN rent_stabilized_plus_tax_data AS right_source
ON right_source.pluto_bbl = m.bbl
WHERE right_source.pluto_unitsres > 0`);
map.setView([40.73, -74], 15);
}
function filter_map(filter) {
source_rent.setQuery(`WITH
o AS (
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_after_20180101_1 GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2017_18_1
GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2016_1
GROUP BY bbl)
UNION
(SELECT bbl, COUNT(*) number_complaints
FROM table_311_buzzfeed_projmap_2015_16_1
GROUP BY bbl)
),
m AS (
SELECT bbl, SUM(number_complaints) complaints
FROM o
GROUP BY bbl
)
SELECT right_source.cartodb_id cartodb_id, right_source.the_geom_webmercator the_geom_webmercator, m.complaints, right_source.pluto_bbl, right_source.pluto_policeprct, right_source.rent_pdf_cartodb_id, right_source.rent_pdf_status1, right_source.rent_pdf_status2, right_source.rent_pdf_status3, right_source.pluto_cd, right_source.pluto_council, right_source.pluto_zipcode, right_source.pluto_firecomp, right_source.pluto_address, right_source.pluto_ownername, right_source.pluto_numfloors, right_source.pluto_unitsres, right_source.pluto_unitstotal, right_source.pluto_yearbuilt, right_source.pluto_histdist, right_source.pluto_landmark, right_source.krauss_cartodb_id, right_source.pluto_schooldist
FROM m
RIGHT JOIN rent_stabilized_plus_tax_data AS right_source
ON right_source.pluto_bbl = m.bbl
WHERE right_source.pluto_unitsres > 0`+ filter);
}
function set_cd() {
var select = document.getElementById("community_district");
var cd = select.options[select.selectedIndex].value;
var cd_filter = " AND right_source.pluto_cd = "+cd;
filter_map(cd_filter);
var url_cd = "https://betanyc.carto.com/api/v2/sql/?q=SELECT ST_Extent(the_geom) FROM nycd WHERE borocd="+cd+"&api_key="+api_key;
fetch(url_cd)
.then(response => {
return response.json()
})
.then(json => {
const extent = json.rows[0].st_extent;
console.log(extent);
const bounds = parseExtent(extent);
console.log(extent);
console.log(bounds);
map.fitBounds(
[
[bounds.south, bounds.west],
[bounds.north, bounds.east]
]
);
});
}
// From BOX(-179.5 -89.9,179.3 82.3) to bounds object
function parseExtent(extent) {
const floatRegex = /-?[0-9]\d*(\.\d+)?/g;
const matches = extent.match(floatRegex);
return {
west: Number.parseFloat(matches[0]),
south: Number.parseFloat(matches[1]),
east: Number.parseFloat(matches[2]),
north: Number.parseFloat(matches[3])
};
}
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
function clear_311_charts() {
if (typeof complaint_chart !== 'undefined'){
complaint_chart.clear();
document.getElementById("canvas1").style.display = 'none';
}
if (typeof year_chart !== 'undefined'){
year_chart.clear();
document.getElementById("canvas2").style.display = 'none';
}
}
function clear_rent_charts() {
if (typeof units_year_chart !== 'undefined'){
units_year_chart.clear();
document.getElementById("canvas3").style.display = 'none';
}
}
function show_info_box() {
if (document.getElementById('info-box').style.display = 'none')
document.getElementById('info-box').style.display = 'block';
}
//Use the City's Geoclient API to search for an address
function set_address() {
var boro = "Manhattan";
var adr = document.getElementById("address").value;
const proxyurl = "https://cors-anywhere.herokuapp.com/";
var url = "https://api.cityofnewyork.us/geoclient/v1/search.json?input=" + " " + adr + " " + boro + "&app_id=dd37f663&app_key=c99663c5e8b11315279f8d28ef245dab";
fetch(proxyurl + url, {mode: 'cors'})
.then(function(response) {
return response.json();
})
.then(function(address) {
document.getElementById('no_results').style.display = 'none';
results = address.results;
response = results[0].response;
latitude = response.latitude;
longitude = response.longitude;
map.setView([latitude, longitude], 18);
})
.catch(function(error) {
document.getElementById('no_results').style.display = 'block';
});
}
//Labels on Points on Chart.js Charts
client.getLeafletLayer().addTo(map);
const popup = L.popup({ closeButton: false });
</script>
</body>
</html>