Blame view

src/js/app.js 9.53 KB
856e1d58   Sean Wills   Search menu
1
//AIzaSyAPYatPrCcmNcVdAO_MF0YhO3c1mgdLvuQ
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, $timeout, $rootScope, $interval) {

    var map;
856e1d58   Sean Wills   Search menu
7
8
    $scope.stops = [{
        "Description": "Start typing to search...",
01ae2e35   Sean Wills   Falied smooth mov...
9
        valid: false,
3ef35c23   Sean Wills   Commented feature...
10
        id: 1
93483f6d   Sean Wills   Settings Working,...
11

3ef35c23   Sean Wills   Commented feature...
12
13
14
15
16
17
18
19
20
21
    }, {
        "Description": "Start typing to search...",
        valid: false,
        id: 2
    }]

    var directionsService = new google.maps.DirectionsService;
    var directionsDisplay = new google.maps.DirectionsRenderer();


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

    initMap();
    $scope.timer = 0;
    $scope.timeTaken = 0;

    function initMap() {
        map = new google.maps.Map(document.getElementById('map-div'), {
            center: {
                lat: 51.491903,
                lng: -0.024640
            },
            mapTypeId: 'roadmap',
            zoom: 14,
            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"
3ef35c23   Sean Wills   Commented feature...
58
59
60
61
62
63
64
                        },
                        {
                            "lightness": 16
                        }
                    ]
                },
                {
de63be91   Sean Wills   No settings
65
                    "featureType": "all",
3ef35c23   Sean Wills   Commented feature...
66
67
68
69
70
                    "elementType": "labels.icon",
                    "stylers": [{
                        "visibility": "off"
                    }]
                },
484036e0   Tarpit Grover   WIP
71
                {
b2145b07   Tarpit Grover   WIP
72
                    "featureType": "administrative",
3ef35c23   Sean Wills   Commented feature...
73
74
                    "elementType": "geometry.fill",
                    "stylers": [{
01ae2e35   Sean Wills   Falied smooth mov...
75
76
                            "color": "#000000"
                        },
01ae2e35   Sean Wills   Falied smooth mov...
77
                        {
856e1d58   Sean Wills   Search menu
78
                            "lightness": 20
3ef35c23   Sean Wills   Commented feature...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
                        }
                    ]
                },
                {
                    "featureType": "administrative",
                    "elementType": "geometry.stroke",
                    "stylers": [{
                            "color": "#000000"
                        },
                        {
                            "lightness": 17
                        },
                        {
                            "weight": 1.2
                        }
                    ]
                },
856e1d58   Sean Wills   Search menu
96
                {
856e1d58   Sean Wills   Search menu
97
                    "featureType": "landscape",
ec938bf0   Tarpit Grover   first commit
98
                    "elementType": "geometry",
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": "poi",
                    "elementType": "geometry",
                    "stylers": [{
                            "color": "#000000"
                        },
                        {
                            "lightness": 21
3ef35c23   Sean Wills   Commented feature...
115
                        }
93483f6d   Sean Wills   Settings Working,...
116
117
118
119
120
                    ]
                },
                {
                    "featureType": "road.highway",
                    "elementType": "geometry.fill",
3ef35c23   Sean Wills   Commented feature...
121
122
123
124
                    "stylers": [{
                            "color": "#000000"
                        },
                        {
93483f6d   Sean Wills   Settings Working,...
125
126
127
                            "lightness": 17
                        }
                    ]
3ef35c23   Sean Wills   Commented feature...
128
129
                },
                {
ec938bf0   Tarpit Grover   first commit
130
                    "featureType": "road.highway",
ec938bf0   Tarpit Grover   first commit
131
                    "elementType": "geometry.stroke",
3ef35c23   Sean Wills   Commented feature...
132
                    "stylers": [{
01ae2e35   Sean Wills   Falied smooth mov...
133
134
135
136
137
                            "color": "#000000"
                        },
                        {
                            "lightness": 29
                        },
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
                            "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.addStop = function() {
        $scope.stops.push({
            Description: "Start typing to search..."
        })
    }
    $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) {
            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) {
        console.log(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') {
                directionsDisplay.setMap(map);
                directionsDisplay.setDirections(response);
                directionsDisplay.setOptions({
                    suppressMarkers: true
                });
                $scope.timer = response.routes[0].overview_path.length;
                follow(response.routes[0].overview_path, start, end);
            } else {
                console.log("Need more Stops", start, end, waypoints)
            }
        });
    }

    function follow(overview_path, start, end) {

        var marker = new google.maps.Marker({
            position: overview_path[0],
            icon: {
                url: "../includes/images/car3x.png",
                scaledSize: new google.maps.Size(32, 32),
                anchor: new google.maps.Point(16, 16)
            },
            map: map,
            optimized: false
        });
        var from;
        var to;
        var heading;
        var arrOfRots = [];
        var pre = [0];
        var turn;
        var c = 0;
        var i = 1;
        var j = 1;

        function moveDriver() {
            setTimeout(function() {


                function rotateDriver() {
                    setTimeout(function() {
                        var from = new google.maps.LatLng(overview_path[j - 1].lat(), overview_path[j - 1].lng());
                        var to = new google.maps.LatLng(overview_path[j].lat(), overview_path[j].lng());
                        var heading = Math.round(google.maps.geometry.spherical.computeHeading(from, to));
                        if (Math.abs(heading) > 0) {
                            $('img[src="../includes/images/car3x.png"]').css({ 'transform': 'rotate(' + heading + 'deg)' });
                        }

                        j++;
                        if (j < 180) {
                            rotateDriver();
b2145b07   Tarpit Grover   WIP
291
                        }
ec938bf0   Tarpit Grover   first commit
292
                    }, 500)
a0fba7c8   David Beech   david
293
                }
ec938bf0   Tarpit Grover   first commit
294
                rotateDriver();
01ae2e35   Sean Wills   Falied smooth mov...
295

01ae2e35   Sean Wills   Falied smooth mov...
296
297
298

                j=1;
                marker.setPosition(overview_path[i]);
b2145b07   Tarpit Grover   WIP
299
                i++;
01ae2e35   Sean Wills   Falied smooth mov...
300
301
302
                if (i < overview_path.length) {
                    moveDriver();
                }
b2145b07   Tarpit Grover   WIP
303
            }, 1000)
01ae2e35   Sean Wills   Falied smooth mov...
304
305
306
307
308
        }
        moveDriver();

    }

856e1d58   Sean Wills   Search menu
309
});
3ef35c23   Sean Wills   Commented feature...

93483f6d   Sean Wills   Settings Working,...

3ef35c23   Sean Wills   Commented feature...

01ae2e35   Sean Wills   Falied smooth mov...

26ced867   Sean Wills   New commit

5b416886   Sean Wills   Move and rotate

01ae2e35   Sean Wills   Falied smooth mov...

b2145b07   Tarpit Grover   WIP

01ae2e35   Sean Wills   Falied smooth mov...

5b416886   Sean Wills   Move and rotate

01ae2e35   Sean Wills   Falied smooth mov...

856e1d58   Sean Wills   Search menu

5b416886   Sean Wills   Move and rotate

856e1d58   Sean Wills   Search menu

26ced867   Sean Wills   New commit

856e1d58   Sean Wills   Search menu

3ef35c23   Sean Wills   Commented feature...

b2145b07   Tarpit Grover   WIP

93483f6d   Sean Wills   Settings Working,...

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...

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