-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
309 lines (269 loc) · 9.29 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Intersection Collision Evaluation</title>
<link href="https://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
<link href='http://fonts.googleapis.com/css?family=Roboto+Slab:400,700,300' rel='stylesheet' type='text/css'>
<script>
/**
CREATING VARIABLES
**/
//Create the markers array, markerName array, and old to be used later
var markers = [];
var markerName = []
var old;
/**
FUNCTIONS
**/
//Send data to the riak database
function submitAccident() {
$.ajax('/',
{
data: JSON.stringify({
'latitude': document.getElementById('newlat').val,
'longitude': document.getElementById('newlong').val,
'state': document.getElementById('state').val,
'county': document.getElementById('county').val,
'actual_time': document.getElementById('actualtime').val,
'location': document.getElementById('location').val,
'fatalities': document.getElementById('fatal').val,
'notes': document.getElementById('notes').val
}),
contentType: 'application/json',
type: 'POST'
});
return false;
};
//Function to create the parker to be put on the page through the Google Maps api
function createMarker( mark, map ) {
var image = 'marker.png';
var myLatLng = new google.maps.LatLng(mark[1], mark[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
title: mark[0],
zIndex: mark[11]
});
//Set listener to pop out sidebar with info about crash site
google.maps.event.addListener( marker, 'click', function( a ) {
document.getElementById( 'sidebar' ).className = "in";
document.getElementById( 'sidebar' ).innerHTML =
'<div class="leftcontent"><h4>' + marker.title + '</h4>' +
'<p> Town= ' + mark[8].toString() + '<br><p> County= ' + mark[7].toString() +
'<br><p> Lat, Long= ' + mark[1].toString() + ', ' + mark[2].toString() +
'<br><p> CRF= ' + mark[3].toString() + '<br><p> Total Crashes= ' + mark[4].toString() +
'<br><p> County Rank= ' + mark[5].toString() + '<br><p> State Rank= ' + mark[6].toString() +
'<br><p> Time= ' + mark[10].toString() +
'<br><p> Notes= ' + mark[9].toString() + '</p></div>';
});
//This function returns the marker so that it can be deleted later if need be
return marker;
}
//Function to set the markers on the map
function setMarkers(map, locations) {
// Add markers to the map from locations
window.allthemarkers = new Array();
for (var i = 0; i < locations.length; i++) {
markerName.push(createMarker( locations[i], map ));
}
google.maps.event.addListener(map, 'click', function() {
document.getElementById( 'sidebar' ).className = "out";
document.getElementById( 'sidebar' ).innerHTML = '';
});
};
//Initialize the Google map
function initialize() {
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(44.809658,-68.770759),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
window.map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
setMarkers(window.map,markers);
};
//Function using the right sidebar to change the markers that are shown based on total crashes
function changeTotalCrashes(max){
for (var i=0; i<markers.length; i++){
if (markers[i][4] < max){
markerName[i].setMap(null);
}
else{
markerName[i].setMap(map);
}
}
}
//Function using the right sidebar to change the markers that are shown based on year
function changeYear(yr){
for (var i=0; i<markers.length; i++){
var y = markers[i][10];
y = y.substr(0,4);
y = parseInt(y);
if (yr == 0){
markerName[i].setMap(map);
}
else{
if (y == yr){
markerName[i].setMap(map);
}
else{
markerName[i].setMap(null);
}
}
}
}
//Function using the right sidebar to change the markers that are shown based on CRF
function changeCrf(max){
for (var i=0; i<markers.length; i++){
if (markers[i][3] < max){
markerName[i].setMap(null);
}
else{
markerName[i].setMap(map);
}
}
}
//Function to cancel submitting data to database
function cancel(){
document.getElementById( 'inputform' ).className = "out2";
old.setMap(null)
}
/**
RUN COMMANDS
**/
//Add data from riak database
$.ajax('/api/1/report',
{ //Pull in the data and assign the properties to an accident in the accidents array
dataType: 'json',
success: function (accidents, textStatus, jqXHR) {
for (var i=0; i<accidents.length; i++){
markers.push( [accidents[i].location_start,parseFloat(accidents[i].latitude),
parseFloat(accidents[i].longitude),parseFloat(accidents[i].crf),
parseFloat(accidents[i].total_crashes),
parseFloat(accidents[i].county_rank),parseFloat(accidents[i].state_rank),
accidents[i].county,accidents[i].town, accidents[i].notes, accidents[i].time, i] )
}
//Run initialize to update the map on the page
initialize();
}
}
);
//Prepare to take data and send it to database
$(document).ready(
function () {
console.log('document ready')
$('#new-accident-report').submit(submitAccident());
}
);
//Create the map using the initialize function
google.maps.event.addDomListener(window, 'load');
//location point
window.onload = function() {
document.getElementById('rightslide').addEventListener('click', function (point) {
document.getElementById( 'rightslide' ).className = "rightin";
google.maps.event.addListener(map, 'click', function() {
document.getElementById( 'rightslide' ).className = "rightout";
});
});
document.getElementById('add').addEventListener('click', function (point) {
alert ("Click on the map, or select an already existing pointer, to mark the location of the crash.");
var clicked = false;
google.maps.event.addListener(map, 'click', function( event ){
if (clicked == true) {
old.setMap(null)
var lat = event.latLng.lat();
var long = event.latLng.lng();
var newmarker = ['name',lat,long,3000];
old = createMarker(newmarker,window.map);
document.getElementById( 'inputform' ).className = "in2";
document.getElementById( 'newlat' ).value = lat;
document.getElementById( 'newlong' ).value = long;
}
else {
var lat = event.latLng.lat();
var long = event.latLng.lng();
var newmarker = ['name',lat,long,3000];
old = createMarker(newmarker,window.map);
clicked = true;
document.getElementById( 'inputform' ).className = "in2";
document.getElementById( 'newlat' ).value = lat;
document.getElementById( 'newlong' ).value = long;
}
});
});
};
</script>
</head>
<body>
<div id="wrapper">
<div id="map-canvas"></div>
<div id="over_map">
<div id="sidebar"></div>
<div id="inputform">
<form onsubmit="return submitAccident();" id="new-accident-form">
<table id="tableform"><tr>
<td>Town/City:</td>
<td> <input type="text" name="town" id="town"></td>
<td>County:</td>
<td><input type="text" name="county" id="county"></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" name="state" id="state"></td>
<td>Time:</td>
<td><input type="text" name"actual_time" id="actualtime"> </td>
</tr>
<tr>
<td>Location Name:</td>
<td><input type="text" name="location" id="location"></td>
<td>Fatalities:</td>
<td><input type="text" name="fatalities" id="fatal"></td>
</tr>
<tr>
<td>Notes:</td>
<td><textarea name="notes" cols="20" rows="3" id="notes">
</textarea></td>
<td>Date:</td><td><input type="text" name="date"></td>
<td width="0px"><input type="hidden" name="newlat" width="0px" id="newlat" ><input type="hidden" name="newlong" width="0px" id="newlong"></td>
<td></td>
</tr>
<tr height="30px">
<td>
<input type="submit" value="Submit">
<input type="button" value="Cancel" onclick="cancel()">
</td>
</tr>
</tr>
</table>
</form>
</div>
<div id="rightslide">
<img src="tools.png" style="margin-left:-35px; margin-top:-7px;">
<div style="float:right; width:190px; font-size:14px;">
<form class="toolclass">
<h4>Total Crashes</h4>
<input type="radio" name="totalCrashes" checked value="GT0" onclick="changeTotalCrashes(0)">All crashes<br>
<input type="radio" name="totalCrashes" value="GT10" onclick="changeTotalCrashes(10)">Total crashes > 10<br>
<input type="radio" name="totalCrashes" value="GT20" onclick="changeTotalCrashes(20)">Total crashes > 20<br>
<input type="radio" name="totalCrashes" value="GT30" onclick="changeTotalCrashes(30)">Total crashes > 30
<h4>Year</h4>
<input type="radio" name="years" checked value="all" onclick="changeYear(0)">All years<br>
<input type="radio" name="years" value="2009" onclick="changeYear(2009)">2009-2011<br>
<input type="radio" name="years" value="2013" onclick="changeYear(2013)">2013
<h4>CRF</h4>
<input type="radio" name="crf" checked value="all" onclick="changeCrf(0)">All CRF<br>
<input type="radio" name="crf" value="GT2" onclick="changeCrf(2)">CRF > 2<br>
<input type="radio" name="crf" value="GT3" onclick="changeCrf(3)">CRF > 3
</form>
</div>
</div>
</div>
<img src="add.png" id="add">
</div>
</body>
</html>