-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1019 lines (927 loc) · 44.7 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
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>School shootings map and timeline, United States 2018 - New York Daily News</title>
<link rel="icon" type="image/png" href="http://interactive.nydailynews.com/favicons.png">
<!-- DEFAULT -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon" href="">
<meta name="format-detection" content="telephone=no" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<!-- TITLES -->
<meta property="og:title" content='MAP: School shootings in the U.S., 2018' />
<meta name="twitter:title" content='MAP: School shootings in the U.S., 2018' />
<!-- DESCRIPTION -->
<meta name="description" content="A map of school shootings in the U.S. in 2018, with injury and fatality counts, updated regularly." />
<meta property="og:description" content="A map and timeline of school shootings in the U.S. in 2018, updated regularly" />
<meta name="twitter:description" content="A map and timeline of school shootings in the U.S. in 2018, updated regularly" />
<!-- KEYWORD -->
<meta name="keywords" content="school shootings,school shootings map,U.S. school shootings,how many school shootings have there been this year" />
<!-- LINK -->
<link rel="canonical" href="http://interactive.nydailynews.com/map/school-shootings/">
<meta property="og:url" content="http://interactive.nydailynews.com/map/school-shootings/" />
<meta name="twitter:url" content="http://interactive.nydailynews.com/map/school-shootings/" />
<!-- THUMBNAIL IMAGE-->
<meta property="og:image" content="http://interactive.nydailynews.com/map/school-shootings/img/school-shootings-map.jpg" />
<meta name="twitter:image" content="http://interactive.nydailynews.com/map/school-shootings/img/school-shootings-map.jpg" />
<meta name="twitter:image:alt" content="An image of two photos of school shooting memorials in Parkland, Florida." />
<meta property="og:image:width" content="1024" />
<meta property="og:image:height" content="512" />
<!-- PARSELY -->
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"headline": "MAP/TIMELINE: School shootings in the U.S., 2018",
"url": "http://interactive.nydailynews.com/map/school-shootings/",
"thumbnailUrl": "http://interactive.nydailynews.com/map/school-shootings/img/school-shootings-map.jpg",
"dateCreated": "2018-02-21T16:00:00Z",
"articleSection": "Interactive",
"creator": ["Interactive Project","Joe Murphy","Steve Smirti"],
"keywords": ["interactive map","interactive project","interactive","mass murder","school shootings","gun violence"]
}
</script>
<!-- NO NEED TO FILL -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:domain" content="http://interactive.nydailynews.com"/>
<meta name="twitter:site" content="@nydailynews">
<meta name="twitter:creator" content="@nydni">
<meta name="decorator" content="responsive" />
<meta name="nydn_section" content="NY Daily News" />
<meta name="msvalidate.01" content="02916AAC0DA8B068EFE01D721E03ED7E" />
<meta name="p:domain_verify" content="78efe4f5c9935744af497772f68a0ee7" />
<meta property="fb:app_id" content="107464888913" />
<meta property="fb:admins" content="1594068001" />
<meta property="fb:pages" content="268914272540" />
<meta property="og:type" content="article" />
<meta property="og:site_name" content="NY Daily News" />
<meta property="article:publisher" content="https://www.facebook.com/NYDailyNews/" />
<meta name="localeCountry" content="US"/>
<meta name="localeLanguage" content="en" />
<!-- ADOBE ANALYTICS -->
<script src="//assets.adobedtm.com/4fc527d6fda921c80e462d11a29deae2e4cf7514/satelliteLib-c91fdc6ac624c6cbcd50250f79786de339793801.js"></script>
<link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700|PT+Serif' rel='stylesheet'>
<script data-main="//interactive.nydailynews.com/nydn/js/rh.js?r=20170405001" src="//interactive.nydailynews.com/nydn/js/require.js?r=2016LIST" defer></script>
<script>
var nydn = nydn || {
"section": "NYDailyNews",
"subsection": "news",
"template": "article",
"revision": "201609014009",
"bidder": { contains: function() {} },
"targetPath": document.location.pathname
};
var nydnDO = [ {
'title':'xxxMAP: School shootings in the U.S., 2018xxx',
'link':'http://interactive.nydailynews.com/map/school-shootings/',
'p_type':'interactive',
'section':'interactive'
}];
</script>
<!-- ADS-START -->
<script>//((window.trb || (trb = {})).data || (trb.data = {})).dssOverrideLevelCode = 'free';</script>
<script src="//interactive.nydailynews.com/includes/template/template.js" onload="nydn_ads('project');"></script>
<!-- ADS-END -->
<link rel="stylesheet" href="//interactive.nydailynews.com/nydn/c/rh.css">
<link rel="stylesheet" href="css/style.css?v2">
<link rel="stylesheet" href="//interactive.nydailynews.com/js/leaflet/1.2.0/leaflet.css">
<!--
<link rel="stylesheet" href="//interactive.nydailynews.com/js/leaflet/markercluster/1.1.0/MarkerCluster.Default.css">
-->
<style>
</style>
<script>var nav_params = {section: 'projects', url: 'http://interactive.nydailynews.com/project/'};</script>
<script src="//interactive.nydailynews.com/library/vendor-nav/vendor-include.js" defer></script>
<style>
#shooting-map {
margin: 10px auto;
height: 400px;
}
</style>
</head>
<body id="nydailynews" data-section="nydailynews" data-subsection="NY Daily News">
<!-- SITEHEADER-START -->
<header id="templateheader"></header>
<!-- SITEHEADER-END -->
<!-- CONTENT-START -->
<main>
<article>
<div>
<div class="intro">
<div class="dek">2018 school shootings</div>
<h1>School shootings map and timeline, United States, 2018</h1>
<div>
<ul class="ra-share" id="ra-share-top" style="text-align: center;">
<li class="rt-share-f"><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://interactive.nydailynews.com/map/school-shootings/">facebook</a> </li>
<li class="ra-share-t"> <a target="_blank" href="https://twitter.com/intent/tweet?text=This is a map and timeline of the school shootings in the U.S. in 2018&url=http://interactive.nydailynews.com/map/school-shootings/&via=NYDNi&related=nydailynews,joemurph" id="twitterlink">Tweet</a></li>
<li class="ra-share-e"> <a href="mailto:?subject=A map and timeline of school shootings in the U.S. this year&body=http://interactive.nydailynews.com/map/school-shootings/">email</a> </li>
</ul>
</div>
<p class="stamp">Updated May 25, 2018</p>
<p id="datestamp" class="stamp">Published Feb. 21, 2018</p>
<p>
<a href="https://everytownresearch.org/school-shootings/">Everytown for Gun Safety defines a school shooting</a> as
</p>
<blockquote>
“...any time a firearm discharges a live round inside or into a school building or on or onto a school campus or grounds, as documented by the press and, when necessary, confirmed through further inquiries with law enforcement or school officials. Incidents in which guns were brought into schools but not discharged are not included.”
</blockquote>
<p>
Watch our map-timeline of 2018 school shootings, or filter shootings by the state the shooting happened in, or by casualties.
</p>
</div>
<section id="map">
<form id="panel">
<fieldset id="scrubber">
<legend>Start the timeline of 2018’s school shootings:</legend>
<div id="controls">
<button id="play" onClick="scrub.press_play(); return false;">Play Timeline</button>
</div>
</fieldset>
<div id="shooting-map"></div>
<fieldset id="filter" style="text-align: center;">
<legend>Filter school shootings by:</legend>
<div class="select">
<select id="states" name="states">
<option value="all">All states</option>
<option value="state-alabama">Alabama</option>
<option value="state-alaska" disabled="disabled">Alaska</option>
<option value="state-arizona">Arizona</option>
<option value="state-arkansas" disabled="disabled">Arkansas</option>
<option value="state-california">California</option>
<option value="state-colorado" disabled="disabled">Colorado</option>
<option value="state-connecticut" disabled="disabled">Connecticut</option>
<option value="state-delaware" disabled="disabled">Delaware</option>
<option value="state-district-of-columbia" disabled="disabled">District Of Columbia</option>
<option value="state-florida">Florida</option>
<option value="state-georgia">Georgia</option>
<option value="state-hawaii" disabled="disabled">Hawaii</option>
<option value="state-idaho" disabled="disabled">Idaho</option>
<option value="state-illinois">Illinois</option>
<option value="state-indiana" disabled="disabled">Indiana</option>
<option value="state-iowa" disabled="disabled">Iowa</option>
<option value="state-kansas" disabled="disabled">Kansas</option>
<option value="state-kentucky">Kentucky</option>
<option value="state-louisiana">Louisiana</option>
<option value="state-maine" disabled="disabled">Maine</option>
<option value="state-maryland">Maryland</option>
<option value="state-massachusetts" disabled="disabled">Massachusetts</option>
<option value="state-michigan">Michigan</option>
<option value="state-minnesota">Minnesota</option>
<option value="state-mississippi">Mississippi</option>
<option value="state-missouri">Missouri</option>
<option value="state-montana" disabled="disabled">Montana</option>
<option value="state-nebraska" disabled="disabled">Nebraska</option>
<option value="state-nevada" disabled="disabled">Nevada</option>
<option value="state-new-hampshire" disabled="disabled">New Hampshire</option>
<option value="state-new-jersey" disabled="disabled">New Jersey</option>
<option value="state-new-mexico" disabled="disabled">New Mexico</option>
<option value="state-new-york">New York</option>
<option value="state-north-carolina">North Carolina</option>
<option value="state-north-dakota" disabled="disabled">North Dakota</option>
<option value="state-ohio">Ohio</option>
<option value="state-oklahoma" disabled="disabled">Oklahoma</option>
<option value="state-oregon" disabled="disabled">Oregon</option>
<option value="state-pennsylvania">Pennsylvania</option>
<option value="state-rhode-island" disabled="disabled">Rhode Island</option>
<option value="state-south-carolina" disabled="disabled">South Carolina</option>
<option value="state-south-dakota" disabled="disabled">South Dakota</option>
<option value="state-tennessee">Tennessee</option>
<option value="state-texas">Texas</option>
<option value="state-utah" disabled="disabled">Utah</option>
<option value="state-vermont" disabled="disabled">Vermont</option>
<option value="state-virginia">Virginia</option>
<option value="state-washington">Washington</option>
<option value="state-west-virginia" disabled="disabled">West Virginia</option>
<option value="state-wisconsin" disabled="disabled">Wisconsin</option>
<option value="state-wyoming" disabled="disabled">Wyoming</option>
</select>
<div class="select_arrow"></div>
</div>
<div>
<ul>
<li>
<input type="radio" name="deaths" id="all" value="all" checked>
<label for="all">
<div class="check"></div>
All school shootings
</label>
</li>
<li>
<input type="radio" name="deaths" id="death-1" value="death-1">
<label for="death-1">
<div class="check"><div class="inside"></div></div>
Shootings with at least one fatality
</label>
</li>
<!--
<li>
<input type="radio" name="deaths" id="death-3" value="death-3">
<label for="death-3">
<div class="check"><div class="inside"></div></div>
3+ fatalities
</label>
</li>
<li>
<input type="radio" name="deaths" id="death-5" value="death-5">
<label for="death-5">
<div class="check"><div class="inside"></div></div>
5+ fatalities
</label>
</li>
<li>
<input type="radio" name="deaths" id="death-10" value="death-10">
<label for="death-10">
<div class="check"><div class="inside"></div></div>
10+ fatalities
</label>
</li>
-->
</ul>
</div>
</fieldset>
</form>
</section>
<section id="shootings">
<p class="latest-news">
<a href="http://www.nydailynews.com/tags/school-shootings">THE LATEST</a>:
<strong id="latest-news-headline"></strong>
<br>PHOTO GALLERY: <a href="http://www.nydailynews.com/news/daily-news-covers-mass-shootings-sandy-hook-gallery-1.2453211">Daily News front-pages on mass shootings</a>
<br>More maps: <a href="http://interactive.nydailynews.com/map/mass-shootings-since-sandy-hook/">Mass shootings in the U.S. since 2013</a>
</p>
<script>
var s = document.createElement('script');
var rando = function() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
s.onload = function() { callback(); }
s.setAttribute('src', '//interactive.nydailynews.com/feeds/tag-school-shootings-1.js?' + rando() + '=1');
document.getElementsByTagName('head')[0].appendChild(s);
function callback() {
document.getElementById('latest-news-headline').innerHTML = hed;
}
</script>
<p class="stamp">Data last updated May 25, 2018</p>
<p class="stamp">Data courtesy Everytown for Gun Safety</p>
</section>
<div>
<p class="caption">Interactive by Joe Murphy and Steve Smirti</p>
</div>
</div>
</article>
</main>
<script src="//interactive.nydailynews.com/js/jquery.min.js"></script>
<script src="//interactive.nydailynews.com/js/leaflet/1.2.0/leaflet.js"></script>
<!--
<script src="js/odometer.min.js"></script>
-->
<script>
window.odometerOptions = {
auto: true, // Don't automatically initialize everything with class 'odometer'
duration: 300, // Change how long the javascript expects the CSS animation to take
theme: 'minimal', // Specify the theme (if you have more than one theme css file on the page)
animation: 'count' // Count is a simpler animation method which just increments the value,
};
var center_point = [39.5,-98.35];
var shootings = 0;
var m = {
config: {
dev: document.location.hash === '#dev' ? 1 : 0,
},
markers: [],
tile: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png',
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>',
current_layer: 'all',
marker_group: { 'all': [] },
layer_group: {},
info: L.control(),
infosub: L.control(),
icon: function(classname) {
if ( typeof classname === 'undefined' ) classname = '';
return new L.divIcon({
className: "pin " + classname,
iconSize: L.point(20,20),
iconAnchor: [20,20],
//labelAnchor: [-6, 0],
//popupAnchor: [0, -36],
//html: '<span style="background-color:red;" />'
});
},
slugify: function(text) {
// from https://gist.github.com/mathewbyrne/1280286
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
},
numbers_lookup: ['zero','one','two','three','four', 'five','six','seven','eight','nine'],
month_lookup: {
'Jan': 'January',
'Feb': 'February',
'Mar': 'March',
'Apr': 'April',
'May': 'May',
'Jun': 'June',
'Jul': 'July',
'Aug': 'August',
'Sep': 'September',
'Oct': 'October',
'Nov': 'November',
'Dec': 'December'
},
convert_date: function(text) {
// Turn a string such as 1-Oct-17 into an AP-style'd date.
var bits = text.split('-');
var year = '20' + bits[2];
var month = this.month_lookup[bits[1]];
return month + ' ' + bits[0] + ', ' + year;
},
remove_markers: function(slug) {
// Remove a particular group's markers
this.map.removeLayer(this.layer_group[slug]);
},
clear_all_markers: function() {
// Remove 'em all
this.clustergroup.clearLayers();
},
load_markers: function(slug) {
// Given a slug that corresponds to a marker_group of markes, loop through them and add them to the map.
this.layer_group[slug] = L.layerGroup().addTo(this.map);
var len = this.marker_group[slug].length;
for ( var i = 0; i < len; i ++ )
{
this.clustergroup.addLayer(this.marker_group[slug][i]);
}
},
add_to_marker_group: function(slug, marker)
{
// The final stop in the marker assignation.
if ( typeof this.marker_group[slug] === 'undefined' ) this.marker_group[slug] = [];
this.marker_group[slug].push(marker);
},
create_marker: function(d, classname)
{
// Make and return a leaflet marker.
if ( typeof classname === 'undefined' ) classname = 'inactive-pin';
var marker = L.marker(new L.LatLng(d['lat'], d['long']), { icon: this.icon(classname) })
var date_str = this.convert_date(d['Incident Date']);
var loc = d['City Or County'] + ', ' + d['State'];
var slug = m.slugify(d['Incident Date'] + '-' + d['City Or County'] + '-' + d['State']);
var injured_str = d['injured'] + " injured, ";
if ( d['injured'] == '' ) injured_str = "";
var link_str = '';
if ( d['url'] !== '' ) link_str = '<p><a href=' + d['url'] + '>' + d['headline'] + '</a></p>';
var content = "<h3>" + loc + "</h3>\n\
<p>" + date_str + ': ' + injured_str + d['killed'] + " killed.</p>" + link_str;
marker.bindPopup(content);
return marker;
},
add_marker: function(d)
{
// Build out a marker, assign it to the appropriate marker_group(s).
marker = this.create_marker(d);
// Figure out which layer(s) to add the marker to.
var killed_bucket = d['killed'];
if ( d['killed'] >= 1 ) killed_bucket = 1;
while ( killed_bucket > 0 ) {
//if ( killed_bucket > 5 && killed_bucket < 10 ) killed_bucket = 5;
this.add_to_marker_group('death-' + killed_bucket, marker);
killed_bucket -= 1;
}
this.add_to_marker_group('all', marker);
this.add_to_marker_group('death-' + killed_bucket, marker);
if ( d['State'] !== '' ) this.add_to_marker_group('state-' + this.slugify(d['State']), marker);
},
process_marker: function(d) {
// Intermediary function between the data ingestion and the function that hands the markers to the marker_group.
if ( d['lat'] !== '' ) {
this.add_marker(d);
}
},
init: function()
{
var zoom = 4;
if ( is_mobile === true ) zoom = 3;
this.map = L.map('shooting-map', { minZoom: 3, maxZoom: 9, zoomControl:false, scrollWheelZoom:false }).setView(center_point, zoom);
// For reference: layer_group's are the reference markers, and clustergroup is the visible layer
this.clustergroup = L.layerGroup();
L.tileLayer(this.tile, {
attribution: this.attribution,
maxZoom: 16
}).addTo(this.map);
// INFO WINDOW
// Functions that control the on-hover info windows
this.info.options = { position: 'topleft' };
this.info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
this.info.update = function (name) {
if ( typeof name === 'undefined' ) this._div.innerHTML = '';
else this._div.innerHTML = name;
}
this.info.addTo(this.map);
if ( is_mobile == true ) this.infosub.options = { position: 'topleft' };
else this.infosub.options = { position: 'topright' };
this.infosub.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
this.infosub.update = function (name) {
if ( typeof name === 'undefined' ) this._div.innerHTML = '';
else this._div.innerHTML = name;
}
this.infosub.addTo(this.map);
this.marker_group = L.layerGroup().addTo(this.map);
// An item looks like this:
/*
{
"Incident Date": "1-Oct-17",
"Address": "1000 block of Massachusetts St",
"City Or County": "Lawrence",
"State": "Kansas",
"killed": 3,
"injured": 2,
"lat": 38.965463,
"long": -95.235711
},
*/
$.getJSON('data/2018.json?v5d', function(data) {
var len = data.length;
m.data = data;
shootings += len;
for ( var i = 0; i < len; i ++ ) {
m.process_marker(data[i]);
}
panel.init();
scrub.init();
update_twitter();
});
this.map.addLayer(this.clustergroup);
}
}
var panel = {
hash: document.location.hash,
hash_parts: [],
description: document.getElementById('current'),
taxonomy: {
'_blank': {
count: 0,
name: ''
},
},
active: [], // List of the active slugs. If no slugs are specified all start off active.
length: 0,
all: function(action)
{
// action is either clear or show
// loop through all the checkboxes and clear / show.
},
overwrite_url: function(value)
{
// Update the url, overwriting everything that was there before.
this.hash_parts = [value];
this.hash = value;
window.history.replaceState('', '', window.location.origin + window.location.pathname + '#' + this.hash);
},
toggle_url: function(value)
{
// Update the url to reflect the markers on the map.
// We do this so we can permalink particular maps.
if ( this.hash_parts.indexOf(value) === -1 )
{
// Append to the hash and description
this.hash_parts.push(value);
if ( this.hash === '' )
{
this.hash = value;
//this.description.innerHTML = this.taxonomy[value]['name'];
//this.hed.innerHTML = this.taxonomy[value]['name'];
}
else
{
this.hash += ',' + value;
//this.description.innerHTML += ', ' + this.taxonomy[value]['name'];
//this.hed.innerHTML += ', ' + this.taxonomy[value]['name'];
}
}
else
{
// Remove from the hash and description
var index = this.hash_parts.indexOf(value);
this.hash_parts.splice(index, 1);
var len = this.hash_parts.length;
if ( len > 0 )
{
this.hash = this.hash_parts[0];
//this.description.innerHTML = this.taxonomy[this.hash_parts[0]]['name'];
//this.hed.innerHTML = this.taxonomy[this.hash_parts[0]]['name'];
for ( var i = 1; i < len; i ++ )
{
this.hash += ',' + this.hash_parts[i];
//this.description.innerHTML += ', ' + this.taxonomy[this.hash_parts[i]]['name'];
//this.hed.innerHTML += ', ' + this.taxonomy[this.hash_parts[i]]['name'];
}
}
else
{
this.hash = '';
//this.description.innerHTML = '';
//this.hed.innerHTML = '';
}
}
window.history.replaceState('', '', window.location.origin + window.location.pathname + '#' + this.hash);
},
action: function(action, value)
{
// This fires when a form input element is clicked / changed.
if ( action === 'select' )
{
if ( m.marker_group.hasOwnProperty(value) === false ) this.show_message('notice', value);
$('#all').prop('checked', true);
}
else $('#states').val('all');
m.clustergroup.remove();
m.clustergroup = L.layerGroup();
m.load_markers(value);
m.map.addLayer(m.clustergroup);
this.overwrite_url(value);
},
init: function ()
{
//this.length
//this.hed = document.getElementById('current');
// If we've got hash values on page load that means we load only certain crimes.
if ( this.hash !== '' && this.hash !== '#dev' )
{
var hs = this.hash.substring(1);
var items = [hs];
if ( hs.indexOf(',') > 0 )
{
items = hs.split(',')
}
this.hash_parts = items;
var len = items.length;
for ( var i = 0; i < len; i++ )
{
// Activate these, hide all the others.
m.load_markers(items[i]);
if ( items[i].indexOf('state') >= 0 ) $('#states').val(items[i]);
else $('#' + items[i]).prop('checked', true);
}
}
else
{
this.hash = 'all';
this.hash_parts = ['all'];
m.load_markers('all');
}
// Add event handler to the form elements.
var radios = document.forms['panel'].elements['deaths'];
var l = radios.length;
for ( var i = 0; i < l; i ++ ) {
radios[i].onclick = function() {
if ( m.config.dev === 1 ) console.log("Radio clicked: ", this.value);
panel.action('radio', this.value);
};
}
document.querySelector('select[name="states"]').onchange = function() {
if ( m.config.dev === 1 ) console.log("Select clicked: ", this.value);
panel.action('select', this.value);
}
//document.getElementById('shootings-count').textContent = "the " + shootings.toLocaleString() + " subsequent";
}
};
m.init();
var scrub = {
days: ['1-Jan-18', '2-Jan-18', '3-Jan-18', '4-Jan-18', '5-Jan-18', '6-Jan-18', '7-Jan-18', '8-Jan-18', '9-Jan-18', '10-Jan-18', '11-Jan-18', '12-Jan-18', '13-Jan-18', '14-Jan-18', '15-Jan-18', '16-Jan-18', '17-Jan-18', '18-Jan-18', '19-Jan-18', '20-Jan-18', '21-Jan-18', '22-Jan-18', '23-Jan-18', '24-Jan-18', '25-Jan-18', '26-Jan-18', '27-Jan-18', '28-Jan-18', '29-Jan-18', '30-Jan-18', '31-Jan-18', '1-Feb-18', '2-Feb-18', '3-Feb-18', '4-Feb-18', '5-Feb-18', '6-Feb-18', '7-Feb-18', '8-Feb-18', '9-Feb-18', '10-Feb-18', '11-Feb-18', '12-Feb-18', '13-Feb-18', '14-Feb-18', '15-Feb-18', '16-Feb-18', '17-Feb-18', '18-Feb-18', '19-Feb-18', '20-Feb-18', '21-Feb-18', '22-Feb-18', '23-Feb-18', '24-Feb-18', '25-Feb-18', '26-Feb-18', '27-Feb-18', '28-Feb-18', '1-Mar-18', '2-Mar-18', '3-Mar-18', '4-Mar-18', '5-Mar-18', '6-Mar-18', '7-Mar-18', '8-Mar-18', '9-Mar-18', '10-Mar-18', '11-Mar-18', '12-Mar-18', '13-Mar-18', '14-Mar-18', '15-Mar-18', '16-Mar-18', '17-Mar-18', '18-Mar-18', '19-Mar-18', '20-Mar-18', '21-Mar-18', '22-Mar-18', '23-Mar-18', '24-Mar-18', '25-Mar-18', '26-Mar-18', '27-Mar-18', '28-Mar-18', '29-Mar-18', '30-Mar-18', '31-Mar-18', '1-Apr-18', '2-Apr-18', '3-Apr-18', '4-Apr-18', '5-Apr-18', '6-Apr-18', '7-Apr-18', '8-Apr-18', '9-Apr-18', '10-Apr-18', '11-Apr-18', '12-Apr-18', '13-Apr-18', '14-Apr-18', '15-Apr-18', '16-Apr-18', '17-Apr-18', '18-Apr-18', '19-Apr-18', '20-Apr-18', '21-Apr-18', '22-Apr-18', '23-Apr-18', '24-Apr-18', '25-Apr-18', '26-Apr-18', '27-Apr-18', '28-Apr-18', '29-Apr-18', '30-Apr-18', '1-May-18', '2-May-18', '3-May-18', '4-May-18', '5-May-18', '6-May-18', '7-May-18', '8-May-18', '9-May-18', '10-May-18', '11-May-18', '12-May-18', '13-May-18', '14-May-18', '15-May-18', '16-May-18', '17-May-18', '18-May-18', '19-May-18', '20-May-18', '21-May-18', '22-May-18', '23-May-18', '24-May-18', '25-May-18', '26-May-18', '27-May-18', '28-May-18', '29-May-18', '30-May-18', '31-May-18', '1-Jun-18', '2-Jun-18', '3-Jun-18', '4-Jun-18', '5-Jun-18', '6-Jun-18', '7-Jun-18', '8-Jun-18', '9-Jun-18', '10-Jun-18', '11-Jun-18', '12-Jun-18', '13-Jun-18', '14-Jun-18', '15-Jun-18', '16-Jun-18', '17-Jun-18', '18-Jun-18', '19-Jun-18', '20-Jun-18', '21-Jun-18', '22-Jun-18', '23-Jun-18', '24-Jun-18', '25-Jun-18', '26-Jun-18', '27-Jun-18', '28-Jun-18', '29-Jun-18', '30-Jun-18', '1-Jul-18', '2-Jul-18', '3-Jul-18', '4-Jul-18', '5-Jul-18', '6-Jul-18', '7-Jul-18', '8-Jul-18', '9-Jul-18', '10-Jul-18', '11-Jul-18', '12-Jul-18', '13-Jul-18', '14-Jul-18', '15-Jul-18', '16-Jul-18', '17-Jul-18', '18-Jul-18', '19-Jul-18', '20-Jul-18', '21-Jul-18', '22-Jul-18', '23-Jul-18', '24-Jul-18', '25-Jul-18', '26-Jul-18', '27-Jul-18', '28-Jul-18', '29-Jul-18', '30-Jul-18', '31-Jul-18', '1-Aug-18', '2-Aug-18', '3-Aug-18', '4-Aug-18', '5-Aug-18', '6-Aug-18', '7-Aug-18', '8-Aug-18', '9-Aug-18', '10-Aug-18', '11-Aug-18', '12-Aug-18', '13-Aug-18', '14-Aug-18', '15-Aug-18', '16-Aug-18', '17-Aug-18', '18-Aug-18', '19-Aug-18', '20-Aug-18', '21-Aug-18', '22-Aug-18', '23-Aug-18', '24-Aug-18', '25-Aug-18', '26-Aug-18', '27-Aug-18', '28-Aug-18', '29-Aug-18', '30-Aug-18', '31-Aug-18', '1-Sep-18', '2-Sep-18', '3-Sep-18', '4-Sep-18', '5-Sep-18', '6-Sep-18', '7-Sep-18', '8-Sep-18', '9-Sep-18', '10-Sep-18', '11-Sep-18', '12-Sep-18', '13-Sep-18', '14-Sep-18', '15-Sep-18', '16-Sep-18', '17-Sep-18', '18-Sep-18', '19-Sep-18', '20-Sep-18', '21-Sep-18', '22-Sep-18', '23-Sep-18', '24-Sep-18', '25-Sep-18', '26-Sep-18', '27-Sep-18', '28-Sep-18', '29-Sep-18', '30-Sep-18', '1-Oct-18', '2-Oct-18', '3-Oct-18', '4-Oct-18', '5-Oct-18', '6-Oct-18', '7-Oct-18', '8-Oct-18', '9-Oct-18', '10-Oct-18', '11-Oct-18', '12-Oct-18', '13-Oct-18', '14-Oct-18', '15-Oct-18', '16-Oct-18', '17-Oct-18', '18-Oct-18', '19-Oct-18', '20-Oct-18', '21-Oct-18', '22-Oct-18', '23-Oct-18', '24-Oct-18', '25-Oct-18', '26-Oct-18', '27-Oct-18', '28-Oct-18', '29-Oct-18', '30-Oct-18', '31-Oct-18', '1-Nov-18', '2-Nov-18', '3-Nov-18', '4-Nov-18', '5-Nov-18', '6-Nov-18', '7-Nov-18', '8-Nov-18', '9-Nov-18', '10-Nov-18', '11-Nov-18', '12-Nov-18', '13-Nov-18', '14-Nov-18', '15-Nov-18', '16-Nov-18', '17-Nov-18', '18-Nov-18', '19-Nov-18', '20-Nov-18', '21-Nov-18', '22-Nov-18', '23-Nov-18', '24-Nov-18', '25-Nov-18', '26-Nov-18', '27-Nov-18', '28-Nov-18', '29-Nov-18', '30-Nov-18', '1-Dec-18', '2-Dec-18', '3-Dec-18', '4-Dec-18', '5-Dec-18', '6-Dec-18', '7-Dec-18', '8-Dec-18', '9-Dec-18', '10-Dec-18', '11-Dec-18', '12-Dec-18', '13-Dec-18', '14-Dec-18', '15-Dec-18', '16-Dec-18', '17-Dec-18', '18-Dec-18', '19-Dec-18', '20-Dec-18', '21-Dec-18', '22-Dec-18', '23-Dec-18', '24-Dec-18', '25-Dec-18', '26-Dec-18', '27-Dec-18', '28-Dec-18', '29-Dec-18', '30-Dec-18', '31-Dec-18'],
months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
in_play: 0,
julian_date: 0,
current_date: '',
press_play: function() {
// 1. Wipe the map of markers
this.in_play = 1;
this.killed = 0;
this.injured = 0;
var play_button = document.getElementById('play');
play_button.classList.add('hide');
m.clear_all_markers();
// 2. Loop through the this.days() object
// 3. For each day, add the markers for that particular day.
// 4. Also, advance the scrubber.
var i = 0;
var inter = setInterval( function() {
scrub.play_date(i);
i ++;
// WHEN THE TIMELINE COMPLETES
if ( i >= scrub.julian_date ) {
clearInterval(inter);
scrub.in_play = 0;
play_button.textContent = 'Replay Timeline';
play_button.classList.remove('hide');
scrub.killed = 0;
scrub.injured = 0;
}
}, 300);
},
killed: 0,
injured: 0,
show_date: function(i) {
// Update the info box with the date
var day_bits = this.days[i].split('-');
var day_long = m.month_lookup[day_bits[1]] + ' ' + day_bits[0];
m.info.update('<h3><span>' + day_long + '</span>, 2018</h3>');
},
play_date: function(i) {
// i is the number of days into the year we want to show.
var day = scrub.days[i];
var day_slug = m.slugify(day);
var len = this.events[day].length;
if ( this.in_play == 0 && len == 0 ) return;
this.scrubber.value(i+1);
if ( len == 0 ) return;
var day_bits = day.split('-');
var day_long = m.month_lookup[day_bits[1]] + ' ' + day_bits[0];
var loc = 'In ';
for ( var j = 0; j < len; j ++ ) {
//if ( j == 0 ) loc +=
//console.log(this.events_meta[day][j]);
this.killed += this.events_meta[day][j]['killed'];
this.injured += +this.events_meta[day][j]['injured'];
m.clustergroup.addLayer(this.events[day][j]);
}
var s = 's';
if ( len === 1 ) s = '';
if ( this.in_play == 1 ) m.info.update('<h3><span>' + m.numbers_lookup[len] + '</span> school shooting' + s + ' ' + day_long + '</h3>');
document.getElementById('killed').innerHTML = this.killed;
document.getElementById('injured').innerHTML = this.injured;
setTimeout( function() {
$('.' + day_slug).removeClass('active-pin');
$('.' + day_slug).addClass('inactive-pin'); }, 100 );
},
format_current_date: function(d) {
if ( d === null ) var d = new Date();
var date = +d.getDate();
var month = d.getMonth();
var year = '' + d.getFullYear();
return date + '-' + this.months[month] + '-' + year[2] + year[3];
},
init: function() {
this.current_date = this.format_current_date(new Date());
this.scrubber = new ScrubberView();
document.getElementById('controls').appendChild(this.scrubber.elt);
// NUMBER OF DAYS IN THE YEAR via https://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366
var date = new Date();
this.julian_date = (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) - Date.UTC(date.getFullYear(), 0, 0)) / 24 / 60 / 60 / 1000;
//this.julian_date += 1;
this.scrubber.max(this.julian_date);
this.scrubber.step(1);
this.prev = 0;
this.scrubber.onValueChanged = function (value) {
console.log("ACTION: SCRUB CHANGE FIRE");
if ( scrub.in_play == 0 && scrub.prev !== value ) {
console.log("ACTION: SCRUB CHANGE EXECUTE");
document.getElementById('total-caption').setAttribute('role', '');
scrub.show_date(value);
}
}
this.scrubber.onScrubEnd = function (value) {
console.log("ACTION: SCRUB END FIRE");
if ( scrub.in_play == 0 && scrub.prev !== value ) {
console.log("ACTION: SCRUB END EXECUTE");
var i = 0;
scrub.prev = value;
scrub.killed = 0;
scrub.injured = 0;
m.clear_all_markers();
while ( i < value ) {
scrub.play_date(i);
i ++;
}
document.getElementById('total-caption').setAttribute('role', 'alert');
}
}
m.infosub.update('<p id="total-caption"><span class="odometer" id="killed">0</span> total killed, <span class="odometer" id="injured">0</span> total injured</p>');
// Put together the map markers we need to be able to place on the map
this.events = {};
this.events_meta = {};
for ( var i = 0; i < this.julian_date; i ++ ) {
// There are definitely more efficient ways to do this.
var day = this.days[i];
var day_slug = m.slugify(day);
this.events[day] = [];
this.events_meta[day] = [];
var len = m.data.length;
for ( var j = 0; j < len; j ++ ) {
if ( m.data[j]['Incident Date'] == day ) {
this.events[day].push(m.create_marker(m.data[j], 'active-pin ' + day_slug));
this.events_meta[day].push(m.data[j]);
}
}
}
}
};
// From https://github.com/desmosinc/scrubber
function ScrubberView() {
this.makeAccessors();
this.createDOM();
this.attachListeners();
this.onValueChanged = function () {};
this.onScrubStart = function () {};
this.onScrubEnd = function () {};
}
ScrubberView.prototype.makeAccessors = function () {
var value = 0;
var min = 0;
var max = 1;
var step = 0;
var orientation = 'horizontal';
this.value = function (_value) {
if (_value === undefined) return value;
if (value === _value) return this;
_value = Math.max(min, Math.min(max, _value));
if (step > 0) {
var nsteps = Math.round((_value - min)/step);
var invStep = 1/step;
if (invStep === Math.round(invStep)) {
_value = (min*invStep + nsteps)/invStep;
} else {
_value = (min/step + nsteps)*step;
}
value = Math.max(min, Math.min(max, _value));
} else {
value = _value;
}
this.redraw();
this.onValueChanged(value);
return this;
};
this.min = function (_min) {
if (_min === undefined) return min;
if (min === _min) return this;
min = _min;
this.redraw();
return this;
};
this.max = function (_max) {
if (_max === undefined) return max;
if (max === _max) return this;
max = _max;
this.redraw();
return this;
};
this.step = function (_step) {
if (_step === undefined) return step;
if (step === _step) return this;
step = _step;
this.redraw();
return this;
};
this.orientation = function(_orientation) {
if (_orientation === undefined) return orientation;
if (_orientation === orientation) return this;
orientation = _orientation;
this.redraw();
return this;
};
};
ScrubberView.prototype.createDOM = function () {
this.elt = document.createElement('div');
this.track = document.createElement('div');
this.thumb = document.createElement('div');
this.elt.className = this.orientation() === 'horizontal' ? 'scrubber' : 'scrubber-vert';
this.track.className = 'track';
this.thumb.className = 'thumb';
this.elt.appendChild(this.track);
this.elt.appendChild(this.thumb);
};
ScrubberView.prototype.redraw = function () {
var frac = (this.value() - this.min())/(this.max() - this.min());
if (this.orientation() === 'horizontal') {
this.elt.className = 'scrubber';
this.thumb.style.top = '50%';
this.thumb.style.left = frac*100 + '%';
}
else {
this.elt.className = 'scrubber-vert';
this.thumb.style.left = '50%';
this.thumb.style.top = 100 - (frac*100) + '%';
}
};
ScrubberView.prototype.attachListeners = function () {
var self = this;
var mousedown = false;
var cachedLeft;
var cachedWidth;
var cachedTop;
var cachedHeight;
var start = function (evt) {
evt.preventDefault();
self.onScrubStart(self.value());
document.addEventListener('mouseup', stop);
document.addEventListener('touchend', stop);
mousedown = true;
var rect = self.elt.getBoundingClientRect();
// NOTE: page[X|Y]Offset and the width and height
// properties of getBoundingClientRect are not
// supported in IE8 and below.
//
// Scrubber doesn't attempt to support IE<9.
var xOffset = window.pageXOffset;
var yOffset = window.pageYOffset;
cachedLeft = rect.left + xOffset;
cachedWidth = rect.width;
cachedTop = rect.top + yOffset;
cachedHeight = rect.height;
self.thumb.className += ' dragging';
};
var stop = function () {
document.removeEventListener('mouseup', stop, true);
document.removeEventListener('touchend', stop, true);
mousedown = false;
cachedLeft = undefined;
cachedWidth = undefined;
cachedTop = undefined;
cachedHeight = undefined;
self.thumb.className = 'thumb';
self.onScrubEnd(self.value());
};
var setValueFromPageX = function (pageX) {
var frac = Math.min(1, Math.max((pageX - cachedLeft)/cachedWidth, 0));
self.value((1-frac)*self.min() + frac*self.max());
};
var setValueFromPageY = function (pageY) {
var frac = Math.min(1, Math.max(1 - (pageY - cachedTop)/cachedHeight, 0));
self.value((1-frac)*self.min() + frac*self.max());
};
this.elt.addEventListener('mousedown', start);
this.elt.addEventListener('touchstart', start);
document.addEventListener('mousemove', function (evt) {
if (!mousedown) return;
evt.preventDefault();
if (self.orientation() === 'horizontal')
setValueFromPageX(evt.pageX);
else
setValueFromPageY(evt.pageY);
});
document.addEventListener('touchmove', function (evt) {
if (!mousedown) return;
evt.preventDefault();
if (self.orientation() === 'horizontal')
setValueFromPageX(evt.changedTouches[0].pageX);
else
setValueFromPageY(evt.changedTouches[0].pageY);
});
this.elt.addEventListener('mouseup', function (evt) {
if (!mousedown) return;
evt.preventDefault();
if (self.orientation() === 'horizontal')
setValueFromPageX(evt.pageX);
else
setValueFromPageY(evt.pageY);
});
this.elt.addEventListener('touchend', function (evt) {
if (!mousedown) return;
evt.preventDefault();
if (self.orientation() === 'horizontal')
setValueFromPageX(evt.changedTouches[0].pageX);
else
setValueFromPageY(evt.changedTouches[0].pageY);
});
};
function update_twitter(number_killed) {
var a = document.getElementById('twitterlink');
var old_href = a.getAttribute('href');
var new_href = old_href.replace('the school shootings', 'the ' + m.data.length + ' school shootings');
a.setAttribute('href', new_href);
}
</script>