856e1d58
Sean Wills
Search menu
|
1
|
var app = angular.module('batmanDelivers', ['ngSanitize', 'ui.select']);
|
b2145b07
Tarpit Grover
WIP
|
2
|
|
3ef35c23
Sean Wills
Commented feature...
|
3
4
5
6
|
app.controller('myCtrl', function($scope, $http, $rootScope, $sce) {
//GLOBAL VARIABLES
|
856e1d58
Sean Wills
Search menu
|
7
8
|
var key = 'AIzaSyAPYatPrCcmNcVdAO_MF0YhO3c1mgdLvuQ';
var distance;
|
01ae2e35
Sean Wills
Falied smooth mov...
|
9
|
var map;
|
3ef35c23
Sean Wills
Commented feature...
|
10
|
var mapReset = false;
|
93483f6d
Sean Wills
Settings Working,...
|
11
|
$scope.routeStarted = false;
|
3ef35c23
Sean Wills
Commented feature...
|
12
13
14
15
16
17
18
19
20
21
|
//UI VARIABLES
$scope.warning = '';
$scope.timer = 0;
$scope.predictedTime = 0;
$scope.speed = 50; //Average MPH
//UI ARRAYS
|
93483f6d
Sean Wills
Settings Working,...
|
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
|
$scope.settings = [{
description: 'Enable Time Prediction',
enabled: true,
showOnRouteLoad: true,
showOnPageLoad: false,
template: $sce.trustAsHtml("<span>Prediction: {{predictedTime}} (Mins)</span>")
},
{
description: 'Enable Speed Manipulation',
enabled: true,
showOnRouteLoad: true,
showOnPageLoad: false,
template: $sce.trustAsHtml("<span>Manipulate Speed:</span> <div id='slider'></div>")
},
{
description: 'Enable Speed Display',
enabled: true,
showOnRouteLoad: true,
showOnPageLoad: false,
template: $sce.trustAsHtml("<p>View Speed: {{speed}} (MPH)</p>")
},
{
description: 'Enable Additional Stops',
enabled: true,
showOnRouteLoad: false,
showOnPageLoad: true,
template: $sce.trustAsHtml("<p class='add-stop' ng-click='addStop()'>Additional Stop</p>")
},
{
description: 'Reset Map',
enabled: true,
showOnRouteLoad: false,
showOnPageLoad: true,
template: $sce.trustAsHtml("<p ng-click='resetMap()'>Reset Map</p>")
}
]
|
3ef35c23
Sean Wills
Commented feature...
|
58
59
60
61
62
63
64
|
$scope.stops = [
{
Description: "Start typing to search...",
lbl: "Pickup",
valid: false,
id: 1
|
de63be91
Sean Wills
No settings
|
65
|
},
|
3ef35c23
Sean Wills
Commented feature...
|
66
67
68
69
70
|
{
Description: "Start typing to search...",
lbl: "Drop",
valid: false,
id: 2
|
484036e0
Tarpit Grover
WIP
|
71
|
}]
|
b2145b07
Tarpit Grover
WIP
|
72
|
|
3ef35c23
Sean Wills
Commented feature...
|
73
74
|
//INIT MAP
|
01ae2e35
Sean Wills
Falied smooth mov...
|
75
76
|
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer();
|
01ae2e35
Sean Wills
Falied smooth mov...
|
77
|
initMap();
|
856e1d58
Sean Wills
Search menu
|
78
|
|
3ef35c23
Sean Wills
Commented feature...
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
//FUNCTIONS
$scope.$on('StopChanged', function() {
var validstops = $scope.stops.filter(function(x) {
return x.valid;
});
if (validstops.length == 1) {
map.panTo(validstops[0].$marker.getPosition());
} else if (validstops.length > 1) {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < validstops.length; i++) {
bounds.extend(validstops[i].$marker.getPosition());
}
map.fitBounds(bounds, 100);
|
856e1d58
Sean Wills
Search menu
|
96
|
}
|
856e1d58
Sean Wills
Search menu
|
97
|
|
ec938bf0
Tarpit Grover
first commit
|
98
|
|
3ef35c23
Sean Wills
Commented feature...
|
99
100
101
102
103
104
105
106
107
|
if (validstops.length == $scope.stops.length) {
//Set Markers as null ****
var waypoints = [];
if ($scope.stops.length > 2) {
waypoints = $scope.stops.slice(1, $scope.stops.length - 1);
}
calcRoute($scope.stops[0], $scope.stops[$scope.stops.length - 1], waypoints);
}
});
|
93483f6d
Sean Wills
Settings Working,...
|
108
109
110
111
112
113
114
|
function refreshSettings(completed){
newSettings = [];
$scope.settings.forEach(function(s, i){
if(completed && !s.showOnPageLoad){
s.showOnRouteLoad = true;
} else {
s.showOnRouteLoad = false;
|
3ef35c23
Sean Wills
Commented feature...
|
115
|
}
|
93483f6d
Sean Wills
Settings Working,...
|
116
117
118
119
120
|
newSettings.push(s);
if (i == $scope.settings.length - 1){
$scope.settings = newSettings;
}
})
|
3ef35c23
Sean Wills
Commented feature...
|
121
122
123
124
|
}
function getTime() {
var speed = $scope.speed / distance; //Difference
setTimeout(function() {
|
93483f6d
Sean Wills
Settings Working,...
|
125
126
127
|
$scope.$apply(function() {
$scope.predictedTime = (60 / speed).toFixed(1); //Work out the minutes based on the difference
});
|
3ef35c23
Sean Wills
Commented feature...
|
128
129
|
}, 500)
}
|
ec938bf0
Tarpit Grover
first commit
|
130
|
function initMap() {
|
ec938bf0
Tarpit Grover
first commit
|
131
|
map = new google.maps.Map(document.getElementById('map-div'), {
|
3ef35c23
Sean Wills
Commented feature...
|
132
|
scrollwheel: false,
|
01ae2e35
Sean Wills
Falied smooth mov...
|
133
134
135
136
137
|
center: {
lat: 51.491903,
lng: -0.024640
},
mapTypeId: 'roadmap',
|
b2145b07
Tarpit Grover
WIP
|
138
|
zoom: 14,
|
ec938bf0
Tarpit Grover
first commit
|
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
|
mapTypeControl: false,
styles: [{
"featureType": "all",
"elementType": "labels.text.fill",
"stylers": [{
"saturation": 36
},
{
"color": "#000000"
},
{
"lightness": 40
}
]
},
{
"featureType": "all",
"elementType": "labels.text.stroke",
"stylers": [{
"visibility": "on"
},
{
"color": "#000000"
},
{
"lightness": 16
}
]
},
{
"featureType": "all",
"elementType": "labels.icon",
"stylers": [{
"visibility": "off"
}]
},
{
"featureType": "administrative",
"elementType": "geometry.fill",
"stylers": [{
"color": "#000000"
},
{
"lightness": 20
}
]
},
{
"featureType": "administrative",
"elementType": "geometry.stroke",
"stylers": [{
"color": "#000000"
},
{
"lightness": 17
},
{
"weight": 1.2
}
]
},
{
"featureType": "landscape",
"elementType": "geometry",
"stylers": [{
"color": "#000000"
},
{
"lightness": 20
}
]
},
{
"featureType": "poi",
"elementType": "geometry",
"stylers": [{
"color": "#000000"
},
{
"lightness": 21
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.fill",
"stylers": [{
"color": "#000000"
},
{
"lightness": 17
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.stroke",
"stylers": [{
"color": "#000000"
},
{
"lightness": 29
},
{
"weight": 0.2
}
]
},
{
"featureType": "road.arterial",
"elementType": "geometry",
"stylers": [{
"color": "#000000"
},
{
"lightness": 18
}
]
},
{
"featureType": "road.local",
"elementType": "geometry",
"stylers": [{
"color": "#000000"
},
{
"lightness": 16
}
]
},
{
"featureType": "transit",
"elementType": "geometry",
"stylers": [{
"color": "#000000"
},
{
"lightness": 19
}
]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [{
"color": "#000000"
},
{
"lightness": 17
}
]
}
|
b2145b07
Tarpit Grover
WIP
|
291
|
]
|
ec938bf0
Tarpit Grover
first commit
|
292
|
});
|
a0fba7c8
David Beech
david
|
293
|
$rootScope.map = map;
|
ec938bf0
Tarpit Grover
first commit
|
294
|
}
|
01ae2e35
Sean Wills
Falied smooth mov...
|
295
|
function calcRoute(start, end, waypoints) {
|
01ae2e35
Sean Wills
Falied smooth mov...
|
296
297
298
|
directionsService.route({
origin: start.$marker.getPosition(),
destination: end.$marker.getPosition(),
|
b2145b07
Tarpit Grover
WIP
|
299
|
waypoints: waypoints.map(function(x) {
|
01ae2e35
Sean Wills
Falied smooth mov...
|
300
301
302
|
return {
location: x.Description,
stopover: true
|
b2145b07
Tarpit Grover
WIP
|
303
|
};
|
01ae2e35
Sean Wills
Falied smooth mov...
|
304
305
306
307
308
|
}),
travelMode: 'DRIVING',
provideRouteAlternatives: false
}, function(response, status) {
if (status === 'OK') {
|
856e1d58
Sean Wills
Search menu
|
309
|
distance = response.routes[0].legs[0].distance.value * 0.000621371;
|
3ef35c23
Sean Wills
Commented feature...
|
310
311
312
313
314
315
316
317
|
if (distance < 35) {
directionsDisplay.setMap(map);
directionsDisplay.setDirections(response);
directionsDisplay.setOptions({
suppressMarkers: true
});
slider();
getTime();
|
93483f6d
Sean Wills
Settings Working,...
|
318
|
refreshSettings();
|
3ef35c23
Sean Wills
Commented feature...
|
319
320
321
322
323
324
325
|
follow(response.routes[0].overview_path);
} else {
$scope.warning = 'Destination Too Far Away!';
setTimeout(function() {
$scope.warning = " ";
}, 1000)
}
|
01ae2e35
Sean Wills
Falied smooth mov...
|
326
327
328
329
330
|
} else {
console.log("Need more Stops", start, end, waypoints)
}
});
}
|
26ced867
Sean Wills
New commit
|
331
|
function follow(overview_path) {
|
5b416886
Sean Wills
Move and rotate
|
332
|
var marker = new SlidingMarker({
|
01ae2e35
Sean Wills
Falied smooth mov...
|
333
|
position: overview_path[0],
|
b2145b07
Tarpit Grover
WIP
|
334
335
336
337
|
icon: {
url: "../includes/images/car3x.png",
scaledSize: new google.maps.Size(32, 32),
anchor: new google.maps.Point(16, 16)
|
01ae2e35
Sean Wills
Falied smooth mov...
|
338
339
|
},
map: map,
|
5b416886
Sean Wills
Move and rotate
|
340
341
342
|
optimized: false,
duration: 0,
easing: "linear"
|
01ae2e35
Sean Wills
Falied smooth mov...
|
343
|
});
|
856e1d58
Sean Wills
Search menu
|
344
|
|
5b416886
Sean Wills
Move and rotate
|
345
|
//Distances and Measurements
|
856e1d58
Sean Wills
Search menu
|
346
|
var pre = [0];
|
26ced867
Sean Wills
New commit
|
347
|
var j = 0;
|
856e1d58
Sean Wills
Search menu
|
348
349
350
|
var rotateTime = 0;
var heading;
var metres;
|
3ef35c23
Sean Wills
Commented feature...
|
351
|
|
b2145b07
Tarpit Grover
WIP
|
352
|
function moveDriver() {
|
93483f6d
Sean Wills
Settings Working,...
|
353
|
$scope.routeStarted = true;
|
3ef35c23
Sean Wills
Commented feature...
|
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
var from = new google.maps.LatLng(overview_path[j].lat(), overview_path[j].lng());
var to = new google.maps.LatLng(overview_path[j + 1].lat(), overview_path[j + 1].lng());
$scope.stops.forEach(function(stop) {
if (stop.valid) {
var stopLatLng = new google.maps.LatLng(stop.$marker.position.lat(), stop.$marker.position.lng());
var distance = google.maps.geometry.spherical.computeDistanceBetween(from, stopLatLng); //Metres
if (distance < 50) {
stop.$marker.setMap(null);
stop.valid = false;
//Delete Marker
} else {
//Already removed
}
}
|
856e1d58
Sean Wills
Search menu
|
369
|
|
3ef35c23
Sean Wills
Commented feature...
|
370
|
})
|
856e1d58
Sean Wills
Search menu
|
371
|
|
3ef35c23
Sean Wills
Commented feature...
|
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
var heading = Math.round(google.maps.geometry.spherical.computeHeading(from, to));
pre.push(heading);
var turn = Math.abs(pre[0]) - Math.abs(pre[1]);
if (Math.abs(turn) > 40 && Math.abs(turn) < 140) {
if ($scope.speed < 100) {
rotateTime = 1500; //secs
} else {
rotateTime = 500; //secs
}
if (heading < 0) {
//Turning left
setTimeout(function() {
$('img[src="../includes/images/car3x.png"]').css({
'transform': 'rotate(' + heading + 'deg)'
});
}, rotateTime)
} else {
setTimeout(function() {
$('img[src="../includes/images/car3x.png"]').css({
'transform': 'rotate(' + heading + 'deg)'
});
}, rotateTime)
}
|
856e1d58
Sean Wills
Search menu
|
395
|
} else {
|
3ef35c23
Sean Wills
Commented feature...
|
396
397
398
399
400
|
rotateTime = 0;
$('img[src="../includes/images/car3x.png"]').css({
'transform': 'rotate(' + heading + 'deg)'
});
|
856e1d58
Sean Wills
Search menu
|
401
|
}
|
3ef35c23
Sean Wills
Commented feature...
|
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
//** Make batman do skid over roundabouts
//Getting Distance to milliseconds
var metres = google.maps.geometry.spherical.computeDistanceBetween(from, to); //Metres
var miles = metres * 0.000621371; //Miles
var speed = $scope.speed / miles; //Difference
var speedPerHour = 60 / speed; //Work out the minutes based on the difference
var speedPerMilli = speedPerHour * 60000; // Convert to milliseconds
j++;
marker.duration = speedPerMilli + rotateTime;
setTimeout(function() {
marker.setPosition(overview_path[j]);
}, rotateTime)
if (j < overview_path.length - 1 && mapReset != true) {
map.setZoom(16);
map.panTo(marker.getPosition());
setTimeout(function() {
pre.shift();
moveDriver();
}, speedPerMilli + rotateTime)
|
856e1d58
Sean Wills
Search menu
|
424
|
} else {
|
3ef35c23
Sean Wills
Commented feature...
|
425
|
refreshSettings(true);
|
93483f6d
Sean Wills
Settings Working,...
|
426
|
$scope.routeStarted = false;
|
3ef35c23
Sean Wills
Commented feature...
|
427
428
|
$scope.warning = 'Route Completed!';
setTimeout(function() {
|
93483f6d
Sean Wills
Settings Working,...
|
429
430
|
$scope.warning = " ";
}, 1000)
|
856e1d58
Sean Wills
Search menu
|
431
|
}
|
b2145b07
Tarpit Grover
WIP
|
432
433
|
}
moveDriver();
|
1131cb0d
Sean Wills
First commit
|
434
|
|
b2145b07
Tarpit Grover
WIP
|
435
|
}
|
1131cb0d
Sean Wills
First commit
|
436
|
|
3ef35c23
Sean Wills
Commented feature...
|
437
438
|
//UI FUNCTIONS
|
93483f6d
Sean Wills
Settings Working,...
|
439
440
441
442
443
444
445
|
$scope.checkRouteSetting = function(setting){
if (setting.enabled == true && setting.showOnRouteLoad == false){
return true;
} else {
return false;
}
}
|
3ef35c23
Sean Wills
Commented feature...
|
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
$scope.resetMap = function() {
initMap();
mapReset = true;
$scope.stops = [{
Description: "Start typing to search...",
lbl: "Pickup",
valid: false,
id: 1
}, {
Description: "Start typing to search...",
lbl: "Drop",
valid: false,
id: 2
}]
$scope.warning = 'Map Reset!';
setTimeout(function() {
$scope.warning = " ";
mapReset = false;
}, 1000)
}
$scope.addStop = function() {
if ($scope.stops.length < 4) {
|
93483f6d
Sean Wills
Settings Working,...
|
469
470
471
472
473
474
475
476
477
478
479
|
if ($scope.routeStarted) {
$scope.warning = 'Route Has Started!';
setTimeout(function() {
$scope.warning = " ";
}, 1000)
} else {
$scope.stops.splice($scope.stops.length - 1, 0, {
Description: "Start typing to search...",
lbl: "Stop"
})
}
|
3ef35c23
Sean Wills
Commented feature...
|
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
} else {
$scope.warning = 'Reached Stop Limit!';
setTimeout(function() {
$scope.warning = '';
}, 500)
}
}
$scope.checkStop = function(i) {
if (i == 0 || i == $scope.stops.length - 1) {
return true;
} else {
return false;
}
}
|
93483f6d
Sean Wills
Settings Working,...
|
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
$scope.enableSettings = function() {
if ($('.settings').css('display') == 'none') {
$('.settings').slideDown("slow");
} else {
$('.settings').slideUp("slow");
}
}
$scope.changeSetting = function(change, i) {
if (change == 'enable') {
$scope.settings[i].enabled = true;
$scope.warning = 'Setting Enabled, Click X To Disable!';
$(".setting" + i).css("text-decoration", "none");
setTimeout(function() {
$scope.warning = " ";
}, 1000)
} else {
$scope.settings[i].enabled = false;
$scope.warning = 'Setting Disabled, Click X To Enable!';
$(".setting" + i).css("text-decoration", "line-through");
setTimeout(function() {
$scope.warning = " ";
}, 1000)
}
}
|
3ef35c23
Sean Wills
Commented feature...
|
519
520
521
522
|
$scope.removeStop = function(i) {
//TODO: STOP REMOVES PICKUP
$scope.stops.splice(stop, 1);
}
|
93483f6d
Sean Wills
Settings Working,...
|
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
function slider() {
$("#slider").slider({
animate: "fast",
animate: true,
value: 50,
min: 20,
max: 300,
step: 1,
slide: function(event, ui) {
$scope.$apply(function() {
$scope.speed = ui.value;
getTime();
});
}
});
}
|
3ef35c23
Sean Wills
Commented feature...
|
539
540
|
|
856e1d58
Sean Wills
Search menu
|
541
|
});
|