-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
147 lines (133 loc) · 6.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
<!doctype html>
<html lang="en">
<head>
<title> NYC Bike Accidents</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html {height: 100%}
body {height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif;background-image: url(stacked_circles.png);}
#googlemap { height: 100% }
#loading {display: none}
#loading img {width:67px;height:75px;}
#header {width: 490px;float: left;}
#controls {margin-left: 230px;}
#bike_cut {margin: 0 0 10px 20px;float:left;}
#mapIt {margin-left: 80px;}
#startDt, #endDt {width: 175px;}
#credits {margin-right: 20px;width: 400px; font-size: .85em}
.right {margin-top:0;float: right;}
.left {margin-top:0;float: left;}
h1 {margin: 0 0 0 20px;padding: 0;}
</style>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyATQ7rs5zSYWRccfV7pC0NmjhONVHqca2U&sensor=false">
</script>
<script type="text/javascript">
var map;
var activeInfoWindow;
var markers = [];
$(function() {
$( ".datepicker" ).datepicker();
});
var date = new Date();
var firstDayMonth = new Date(date.getFullYear(), date.getMonth(), 1);
$( document ).ready(function() {
$("#startDt").datepicker( "setDate" , firstDayMonth );
$("#endDt").datepicker( "setDate" , date );
$('#mapIt').click(function(){
getResults();
});
});
function initialize() {
var myLatlng = new google.maps.LatLng(40.715,-73.941);
var mapOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('googlemap'), mapOptions);
var bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);
}
function getResults() {
$('#loading').show();
setMapOnAll(null);
markers = [];
var startDt = $( "#startDt" ).datepicker( "getDate" );
var endDt = $( "#endDt" ).datepicker( "getDate" );
var realEndDt = new Date(endDt);
realEndDt.setDate(endDt.getDate()+1);
// var query = "date > '" + startDt.toISOString() + "' AND date < '" + endDt.toISOString() + "' AND (number_of_cyclist_injured > 0 OR number_of_cyclist_killed > 0)";
var query = "(vehicle_type_code1 = 'BICYCLE' OR vehicle_type_code2 = 'BICYCLE' OR vehicle_type_code_3 = 'BICYCLE' OR vehicle_type_code_4 = 'BICYCLE' OR vehicle_type_code_5 = 'BICYCLE') AND date > '" + startDt.toISOString() + "' AND date < '" + realEndDt.toISOString() + "'";
if ($('#injured').is(':checked') && $('#killed').is(':checked')) {
query += " AND (number_of_cyclist_injured > 0 OR number_of_cyclist_killed > 0)";
}
else if ($('#injured').is(':checked')) {
query += " AND number_of_cyclist_injured > 0";
}
else if ($('#killed').is(':checked')) {
query += " AND number_of_cyclist_killed > 0";
}
var url = "https://data.cityofnewyork.us/resource/h9gi-nx95.json?$where=" + encodeURIComponent(query).replace(/'/g, "%27");
$.get( url, function( data ) {
$.each( data, function(i, value) {
if (value != null && value.location != null && value.location != undefined) {
var myLatlng = new google.maps.LatLng(value.location.latitude, value.location.longitude);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
//title: value.contributing_factor_vehicle_1
});
var contentString = 'Number of Cyclists Injured: ' + value.number_of_cyclist_injured +
'<br>Number of Cyclists Killed: ' + value.number_of_cyclist_killed +
'<br>Contributing Factor: ' + value.contributing_factor_vehicle_1;
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker.addListener('click', function() {
if (activeInfoWindow != null)
activeInfoWindow.close();
activeInfoWindow = infowindow;
infowindow.open(map, marker);
});
markers.push(marker);
}
});
$('#loading').hide();
}, "json");
}
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<h1>NYC Bike Accidents</h1>
<div id="header">
<img id="bike_cut" src="bike_cut.jpg" />
<div id="controls">
<p>Start Date <input type="text" id="startDt" class="datepicker"></p>
<p>End Date <input type="text" id="endDt" class="datepicker"></p>
<p class="left">Cyclist Injured <input type="checkbox" id="injured"></p>
<p class="right">Cyclist Killed <input type="checkbox" id="killed"></p>
<p><button type="button" id="mapIt">Get Results</button></p>
</div>
</div>
<div class="right">
<div id="credits">
<p>Data spans from mid-2012 through present and is pulled from <a href="https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions/h9gi-nx95">NYC OpenData</a>.</p>
<p>Linocut by Mike Rubbo via <a href="https://www.flickr.com/photos/httpwwwsitup-cyclecomphotos/5803286720/in/photolist-9QPmXA-5VjLpw-dYj7s7-ewvT7J-8vwZ3z-kr1sdy-eYFXyR-7zKyGA-kr1sGQ-7o8FDF-gWz9UY-kqYS7Z-6L4LYs-9mriGb-qyYHwm-gWzdQ5-kqYTut-gWzemL-kqYU7v-36bFhS-nUW7ik-kVa2yX-6Sgfd4-5doJT6-d34qUj-ndafZz-pe8zkh-2C6RPu-7bPUZm-cxDPQC-mMRMnj-8xgFZj-oym72A-81mtap-gWzgtk-gWzhrS-4N61Ps-kqYSDF-8rjDMV-iMERg9-fVUHV4-biLhie-oEGYXT-fnhbCi-rNftUb-4paE4Z-fiFQKV-6LkLmJ-kqYgnF-kr1te1">Flickr</a>.</p>
<div id="loading"><img src="bike-animated.gif" /> <b>LOADING...</b></div>
</div>
</div>
<div style="clear:both"></div>
<div id="googlemap">
</div>
</body>
</html>