-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.htm
441 lines (402 loc) · 13.1 KB
/
main.htm
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
<!DOCTYPE html>
<html>
<head>
<style>
/* Set the size of the div element that contains the map */
#map {
height: 450px; /* The height is 450 pixels */
width: 100%; /* The width is the width of the web page */
}
#button {
background-color: #f44336; /* Red */
border: none;
color: white;
padding: 12px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 8px;
float: right;
cursor: pointer;
margin-top: 20px;
margin-bottom: 25px;
font-family:verdana;
}
.form-popup {
display: none;
position: fixed;
top: 91px;
right: 15px;
border: 3px solid #f1f1f1;
z-index: 9;
}
.form-container {
max-width: 300px;
padding: 10px;
background-color: white;
}
.form-container input[type=text], .form-container input[type=text]{
width: 90%;
padding: 15px;
margin: 5px 0 22px 0;
border:none;
background: #f1f1f1;
}
.form-container input[type=text]:focus, .form-container input[type=text]:focus {
background-color: #ddd;
outline: none;
}
.form-container .btn {
background-color: #4CAF50;
color: white;
padding: 16px 20px;
border: none;
cursor: pointer;
width: 100%;
margin-bottom:10px;
opacity: 0.8;
}
.form-container .cancel {
background-color: red;
}
.form-container .btn:hover, .open-button:hover{
opacity: 1;
}
.switch {
position: absolute;
top: 50px;
display: inline-flex;
width: 50px;
height: 25px;
}
/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
display:inline-flex;
margin-top: 0px;
}
.slider:before {
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(23px);
-ms-transform: translateX(23px);
transform: translateX(23px);
}
/* Rounded sliders */
.slider.round {
border-radius: 25px;
}
.slider.round:before {
border-radius: 50%;
}
#rows{
display: flex;
flex-direction: row;
width: 100%;
align-items: center;
justify-content: center;
align-content: center;
}
#spacer {
-webkit-flex: 1;
align-items: center;
align-self: center;
justify-content: center;
-ms-flex: 1;
flex: 1;
}
.spacer img {
display: block;
float: right;
width: 80%;
height: auto;
margin: auto;
min-width: 100px;
max-width: 350px;
}
</style>
</head>
<body>
<div id = "rows">
<span id = "spacer">
<label class="switch">
<input type = "checkbox" id = "mode" onchange = "themeChange()">
<span class = "slider round"></span>
</label> </span>
<img src="day2.png" alt = "Logo" width = "137" height = "102" style = "padding:3px" id = "image">
<span id = "spacer">
<button class="open-button" onclick="openForm()" id = "button">Report Crime</button> </span>
</div>
<div class="form-popup" id="myForm">
<form action ="javascript:reportFromBrowser(document.getElementById('loc').value,document.getElementById('desc').value)" class="form-container" id = "label" style = "font-family:verdana;">
<h1>Report a Crime</h1>
<label for="loc" style = "font-family:verdana;" id = "label"><b>Location</b></label>
<input type="text" placeholder="Enter Location" name="loc" id="loc" style = "font-family:verdana;" required>
<label for="desc" style = "font-family:verdana;" id = "label"><b>Description</b></label>
<input type="text" placeholder="Enter Description" name="desc" id="desc" style = "font-family:verdana;" required>
<button type="submit" class="btn" style = "font-family:verdana;">Report</button>
<button type="button" class="btn cancel" onclick ="closeForm()" style = "font-family:verdana;">Close</button>
</form>
</div>
<script>
function openForm() {
document.getElementById("myForm").style.display = "block";
}
function closeForm() {
document.getElementById("myForm").style.display = "none";
}
function reportFromBrowser(address, content){
closeForm();
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function(results, status) {
if (status === 'OK') {
var params = {
"crimeType": content,
"time": getLocalTime(),
"latitude": results[0].geometry.location.lat(),
"accuracy": "10",
"longitude": results[0].geometry.location.lng()
};
var settings = {
"async": true,
"crossDomain": true,
"url": "https://fcoto8jt9f.execute-api.us-east-1.amazonaws.com/in/hack",
"method": "POST",
"headers": {
"Content-Type": "application/json",
},
"processData": false,
"data": JSON.stringify(params)
}
$.ajax(settings).done(function (response) {
console.log(response);
});
addMarker(results[0].geometry.location.lat(), results[0].geometry.location.lng(), map, content, getLocalTime());
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
function getLocalTime(){
var time = new Date();
var hour = (time.getHours()<10?'0':'')+ time.getHours() + ":" + (time.getMinutes()<10?'0':'') + time.getMinutes() + ":" + (time.getSeconds()<10?'0':'') + time.getSeconds();
//var weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
//var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
//var day = weekday[time.getDay()];
//var curr_month = months[time.getMonth()];
var local = time.getFullYear() + "-" + (time.getMonth()<10?'0':'') + (time.getMonth()+1) + "-" + (time.getDate()<10?'0':'') + time.getDate() + " " + hour;
//var local = day + " " + curr_month + " " + time.getDate() + " " + time.getFullYear() + " " + hour + " " + "GMT+0000 (UTC)";
return local;
}
function themeChange(){
if (document.getElementById("mode").checked == false){
dayMode();
} else {
nightMode();
}
}
function dayMode(){
map.setMapTypeId('roadmap');
document.body.style.backgroundColor = "white";
document.getElementById("image").src = "day2.png";
document.getElementsByClassName("form-container")[0].style.backgroundColor = "white";
document.getElementsByClassName("form-popup")[0].style.border = "3px solid #f1f1f1";
document.getElementById("label").style.color = "black";
}
function nightMode(){
map.setMapTypeId('night_mode');
document.body.style.backgroundColor = "#242f3e";
document.getElementById("image").src = "night2.png";
document.getElementsByClassName("form-container")[0].style.backgroundColor = "#242f3e";
document.getElementsByClassName("form-popup")[0].style.border = "3px solid #000000";
document.getElementById("label").style.color = "white";
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!--The div element for the map -->
<div id="map"></div>
<script>
// Initialize and add the map
var map;
function initMap() {
// The location of Chicago
var chicago = {lat: 41.8837338, lng: -87.6288585};
// The map, centered at Chicago
map = new google.maps.Map(document.getElementById('map'), {zoom: 13, center: chicago, mapTypeControlOptions: {mapTypeIds: ['roadmap', 'satellite', 'hybrid', 'terrain', 'night_mode']}});
var geocoder = new google.maps.Geocoder();
var night_mode = new google.maps.StyledMapType(
[
{elementType: 'geometry', stylers: [{color: '#242f3e'}]},
{elementType: 'labels.text.stroke', stylers: [{color: '#242f3e'}]},
{elementType: 'labels.text.fill', stylers: [{color: '#746855'}]},
{
featureType: 'administrative.locality',
elementType: 'labels.text.fill',
stylers: [{color: '#d59563'}]
},
{
featureType: 'poi',
elementType: 'labels.text.fill',
stylers: [{color: '#d59563'}]
},
{
featureType: 'poi.park',
elementType: 'geometry',
stylers: [{color: '#263c3f'}]
},
{
featureType: 'poi.park',
elementType: 'labels.text.fill',
stylers: [{color: '#6b9a76'}]
},
{
featureType: 'road',
elementType: 'geometry',
stylers: [{color: '#38414e'}]
},
{
featureType: 'road',
elementType: 'geometry.stroke',
stylers: [{color: '#212a37'}]
},
{
featureType: 'road',
elementType: 'labels.text.fill',
stylers: [{color: '#9ca5b3'}]
},
{
featureType: 'road.highway',
elementType: 'geometry',
stylers: [{color: '#746855'}]
},
{
featureType: 'road.highway',
elementType: 'geometry.stroke',
stylers: [{color: '#1f2835'}]
},
{
featureType: 'road.highway',
elementType: 'labels.text.fill',
stylers: [{color: '#f3d19c'}]
},
{
featureType: 'transit',
elementType: 'geometry',
stylers: [{color: '#2f3948'}]
},
{
featureType: 'transit.station',
elementType: 'labels.text.fill',
stylers: [{color: '#d59563'}]
},
{
featureType: 'water',
elementType: 'geometry',
stylers: [{color: '#17263c'}]
},
{
featureType: 'water',
elementType: 'labels.text.fill',
stylers: [{color: '#515c6d'}]
},
{
featureType: 'water',
elementType: 'labels.text.stroke',
stylers: [{color: '#17263c'}]
}
], {name: ''});
map.mapTypes.set('night_mode', night_mode);
//Making this map big enough
var windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
document.getElementById("map").style.height = parseInt(Math.floor(windowHeight * .8)) + "px";
}
</script>
<script type="text/javascript">
var API_GATE = 'https://fcoto8jt9f.execute-api.us-east-1.amazonaws.com/in/hack';
$(document).ready(function(){
$.ajax({
type: 'GET',
url: API_GATE,
success: function(data){
//$('#map').html('');
//alert(data.Items);
data.Items.forEach(function(testtableItem){
//alert(typeof(testtableItem.latitude));
var updatedTime = testtableItem.time.substring(0,10) + " " + testtableItem.time.substring(11,19);
addMarker(parseFloat(testtableItem.latitude), parseFloat(testtableItem.longitude), map , testtableItem.crimeType, updatedTime);
});
}
});
});
</script>
<script>
function addMarker(lati, longi, map, content, time){
var pos = {lat: lati, lng: longi};
var infowindow = new google.maps.InfoWindow({
content: '<b>Time: </b>' + time + '<br><b>Description: </b>' + content
});
var marker = new google.maps.Marker({
position: pos,
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 8,
strokeColor: 'black',
strokeWeight: 3,
fillColor: 'white',
fillOpacity: 0.8,
},
map : map
});
marker.addListener('click', function() {
infowindow.open(map,marker);
if(map.getZoom() < 15)
{
map.setCenter(pos);
map.setZoom(15);
}
});
}
</script>
<p style = "font-family:verdana; color: grey; font-size: 10px;">
Disclaimer: SafetyWatch should not be used as an accurate crime reporting web.
It is a crowd-sourced effort to maximize safety in big cities.
Any areas devoid of crime reports do not necessarily signify they are crime free.</p>
<!--Load the API from the specified URL
* The async attribute allows the browser to render the page while the API loads
* The key parameter will contain your own API key (which is not needed for this tutorial)
* The callback parameter executes the initMap() function -->
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDz5JbM2CcCdWLRknygEzEDR0ZiJM7bUVw&callback=initMap">
</script>
</body>
</html>