856e1d58
Sean Wills
Search menu
|
1
|
|
b2145b07
Tarpit Grover
WIP
|
2
|
var app = angular.module('batmanDelivers', ['ngSanitize', 'ui.select']);
|
3ef35c23
Sean Wills
Commented feature...
|
3
4
5
6
|
app.controller('myCtrl', function($scope, $http, $rootScope) {
var key = 'AIzaSyAPYatPrCcmNcVdAO_MF0YhO3c1mgdLvuQ';
var distance;
|
856e1d58
Sean Wills
Search menu
|
7
8
|
var map;
$scope.stops = [{
|
01ae2e35
Sean Wills
Falied smooth mov...
|
9
|
Description: "Start typing to search...",
|
3ef35c23
Sean Wills
Commented feature...
|
10
|
lbl: "Pickup",
|
93483f6d
Sean Wills
Settings Working,...
|
11
|
valid: false,
|
3ef35c23
Sean Wills
Commented feature...
|
12
13
14
15
16
17
18
19
20
21
|
id: 1
}, {
Description: "Start typing to search...",
lbl: "Drop",
valid: false,
id: 2
}]
var directionsService = new google.maps.DirectionsService;
|
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
|
var directionsDisplay = new google.maps.DirectionsRenderer();
initMap();
$scope.timeTaken = 0;
$scope.speed = 50; //Average MPH
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();
});
}
});
}
function getTime(){
var speed = $scope.speed / distance; //Difference
setTimeout(function(){
$scope.predictedTime = 60 / speed; //Work out the minutes based on the difference
}, 500)
}
function initMap() {
map = new google.maps.Map(document.getElementById('map-div'), {
center: {
lat: 51.491903,
lng: -0.024640
},
|
3ef35c23
Sean Wills
Commented feature...
|
58
59
60
61
62
63
64
|
mapTypeId: 'roadmap',
zoom: 14,
mapTypeControl: false,
styles: [{
"featureType": "all",
"elementType": "labels.text.fill",
"stylers": [{
|
de63be91
Sean Wills
No settings
|
65
|
"saturation": 36
|
3ef35c23
Sean Wills
Commented feature...
|
66
67
68
69
70
|
},
{
"color": "#000000"
},
{
|
484036e0
Tarpit Grover
WIP
|
71
|
"lightness": 40
|
b2145b07
Tarpit Grover
WIP
|
72
|
}
|
3ef35c23
Sean Wills
Commented feature...
|
73
74
|
]
},
|
01ae2e35
Sean Wills
Falied smooth mov...
|
75
76
|
{
"featureType": "all",
|
01ae2e35
Sean Wills
Falied smooth mov...
|
77
|
"elementType": "labels.text.stroke",
|
856e1d58
Sean Wills
Search menu
|
78
|
"stylers": [{
|
3ef35c23
Sean Wills
Commented feature...
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
"visibility": "on"
},
{
"color": "#000000"
},
{
"lightness": 16
}
]
},
{
"featureType": "all",
"elementType": "labels.icon",
"stylers": [{
"visibility": "off"
}]
},
|
856e1d58
Sean Wills
Search menu
|
96
|
{
|
856e1d58
Sean Wills
Search menu
|
97
|
"featureType": "administrative",
|
ec938bf0
Tarpit Grover
first commit
|
98
|
"elementType": "geometry.fill",
|
3ef35c23
Sean Wills
Commented feature...
|
99
100
101
102
103
104
105
106
107
|
"stylers": [{
"color": "#000000"
},
{
"lightness": 20
}
]
},
{
|
93483f6d
Sean Wills
Settings Working,...
|
108
109
110
111
112
113
114
|
"featureType": "administrative",
"elementType": "geometry.stroke",
"stylers": [{
"color": "#000000"
},
{
"lightness": 17
|
3ef35c23
Sean Wills
Commented feature...
|
115
|
},
|
93483f6d
Sean Wills
Settings Working,...
|
116
117
118
119
120
|
{
"weight": 1.2
}
]
},
|
3ef35c23
Sean Wills
Commented feature...
|
121
122
123
124
|
{
"featureType": "landscape",
"elementType": "geometry",
"stylers": [{
|
93483f6d
Sean Wills
Settings Working,...
|
125
126
127
|
"color": "#000000"
},
{
|
3ef35c23
Sean Wills
Commented feature...
|
128
129
|
"lightness": 20
}
|
ec938bf0
Tarpit Grover
first commit
|
130
|
]
|
ec938bf0
Tarpit Grover
first commit
|
131
|
},
|
3ef35c23
Sean Wills
Commented feature...
|
132
|
{
|
01ae2e35
Sean Wills
Falied smooth mov...
|
133
134
135
136
137
|
"featureType": "poi",
"elementType": "geometry",
"stylers": [{
"color": "#000000"
},
|
b2145b07
Tarpit Grover
WIP
|
138
|
{
|
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
|
"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
}
]
}
]
});
$rootScope.map = map;
}
$scope.enableSettings = function(){
$( ".settingsMenu" ).css( "display", "block");
}
$scope.checkStop = function(i){
if (i == 0 || i == $scope.stops.length - 1) {
return true;
} else {
return false;
}
}
$scope.addStop = function() {
$scope.stops.splice($scope.stops.length - 1, 0, {
Description: "Start typing to search...",
lbl: "Stop"
})
}
$scope.removeStop = function(i){
$scope.stops.splice(stop, 1);
}
$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();
console.log(validstops)
for (var i = 0; i < validstops.length; i++) {
bounds.extend(validstops[i].$marker.getPosition());
}
map.fitBounds(bounds, 100);
}
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);
}
});
function calcRoute(start, end, waypoints) {
directionsService.route({
origin: start.$marker.getPosition(),
destination: end.$marker.getPosition(),
waypoints: waypoints.map(function(x) {
return {
location: x.Description,
stopover: true
};
}),
travelMode: 'DRIVING',
provideRouteAlternatives: false
}, function(response, status) {
if (status === 'OK') {
distance = response.routes[0].legs[0].distance.value * 0.000621371;
directionsDisplay.setMap(map);
directionsDisplay.setDirections(response);
directionsDisplay.setOptions({
suppressMarkers: true
});
slider();
getTime();
follow(response.routes[0].overview_path);
} else {
console.log("Need more Stops", start, end, waypoints)
|
b2145b07
Tarpit Grover
WIP
|
291
|
}
|
ec938bf0
Tarpit Grover
first commit
|
292
|
});
|
a0fba7c8
David Beech
david
|
293
|
}
|
ec938bf0
Tarpit Grover
first commit
|
294
|
|
01ae2e35
Sean Wills
Falied smooth mov...
|
295
|
function follow(overview_path) {
|
01ae2e35
Sean Wills
Falied smooth mov...
|
296
297
298
|
var marker = new SlidingMarker({
position: overview_path[0],
icon: {
|
b2145b07
Tarpit Grover
WIP
|
299
|
url: "../includes/images/car3x.png",
|
01ae2e35
Sean Wills
Falied smooth mov...
|
300
301
302
|
scaledSize: new google.maps.Size(32, 32),
anchor: new google.maps.Point(16, 16)
},
|
b2145b07
Tarpit Grover
WIP
|
303
|
map: map,
|
01ae2e35
Sean Wills
Falied smooth mov...
|
304
305
306
307
308
|
optimized: false,
duration: 0,
easing: "linear"
});
|
856e1d58
Sean Wills
Search menu
|
309
|
//Distances and Measurements
|
3ef35c23
Sean Wills
Commented feature...
|
310
311
312
313
314
315
316
317
|
var pre = [0];
var j = 0;
var rotateTime = 0;
var heading;
var metres;
function moveDriver() {
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());
|
93483f6d
Sean Wills
Settings Working,...
|
318
|
|
3ef35c23
Sean Wills
Commented feature...
|
319
320
321
322
323
324
325
|
map.setZoom(16);
map.panTo(marker.getPosition());
$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
|
01ae2e35
Sean Wills
Falied smooth mov...
|
326
327
328
329
330
|
if (distance < 50) {
stop.$marker.setMap(null);
stop.valid = false;
//Delete Marker
} else {
|
26ced867
Sean Wills
New commit
|
331
|
//Already removed
|
5b416886
Sean Wills
Move and rotate
|
332
|
}
|
01ae2e35
Sean Wills
Falied smooth mov...
|
333
|
}
|
b2145b07
Tarpit Grover
WIP
|
334
335
336
337
|
})
var heading = Math.round(google.maps.geometry.spherical.computeHeading(from, to));
|
01ae2e35
Sean Wills
Falied smooth mov...
|
338
339
|
pre.push(heading);
var turn = Math.abs(pre[0]) - Math.abs(pre[1]);
|
5b416886
Sean Wills
Move and rotate
|
340
341
342
|
if (Math.abs(turn) > 40 && Math.abs(turn) < 140) {
if ($scope.speed < 100) {
rotateTime = 1500;//secs
|
01ae2e35
Sean Wills
Falied smooth mov...
|
343
|
} else {
|
856e1d58
Sean Wills
Search menu
|
344
|
rotateTime = 500;//secs
|
5b416886
Sean Wills
Move and rotate
|
345
|
}
|
856e1d58
Sean Wills
Search menu
|
346
|
if (heading < 0) {
|
26ced867
Sean Wills
New commit
|
347
|
//Turning left
|
856e1d58
Sean Wills
Search menu
|
348
349
350
|
setTimeout(function(){
$('img[src="../includes/images/car3x.png"]').css({ 'transform': 'rotate(' + heading + 'deg)' });
}, rotateTime)
|
3ef35c23
Sean Wills
Commented feature...
|
351
|
} else {
|
b2145b07
Tarpit Grover
WIP
|
352
|
setTimeout(function(){
|
93483f6d
Sean Wills
Settings Working,...
|
353
|
$('img[src="../includes/images/car3x.png"]').css({ 'transform': 'rotate(' + heading + 'deg)' });
|
3ef35c23
Sean Wills
Commented feature...
|
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
}, rotateTime)
}
} else {
rotateTime = 0;
$('img[src="../includes/images/car3x.png"]').css({ 'transform': 'rotate(' + heading + 'deg)' });
}
//** 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
|
856e1d58
Sean Wills
Search menu
|
369
|
|
3ef35c23
Sean Wills
Commented feature...
|
370
|
j++;
|
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
|
marker.duration = speedPerMilli + rotateTime;
setTimeout(function(){
marker.setPosition(overview_path[j]);
}, rotateTime)
if (j < overview_path.length - 1) {
setTimeout(function(){
pre.shift();
moveDriver();
}, speedPerMilli + rotateTime)
}
}
moveDriver();
}
});
|
856e1d58
Sean Wills
Search menu
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
856e1d58
Sean Wills
Search menu
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
856e1d58
Sean Wills
Search menu
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
93483f6d
Sean Wills
Settings Working,...
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
93483f6d
Sean Wills
Settings Working,...
|
|
|
856e1d58
Sean Wills
Search menu
|
|
|
b2145b07
Tarpit Grover
WIP
|
|
|
1131cb0d
Sean Wills
First commit
|
|
|
b2145b07
Tarpit Grover
WIP
|
|
|
1131cb0d
Sean Wills
First commit
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
93483f6d
Sean Wills
Settings Working,...
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
93483f6d
Sean Wills
Settings Working,...
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
93483f6d
Sean Wills
Settings Working,...
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
93483f6d
Sean Wills
Settings Working,...
|
|
|
3ef35c23
Sean Wills
Commented feature...
|
|
|
856e1d58
Sean Wills
Search menu
|
|
|