Blame view

src/js/app.js 9.55 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

///////////
//Controller
///////////
856e1d58   Sean Wills   Search menu
7
8

app.controller('myCtrl', function($scope, $http, $timeout) {
01ae2e35   Sean Wills   Falied smooth mov...
9

3ef35c23   Sean Wills   Commented feature...
10
    var initializing = true;
93483f6d   Sean Wills   Settings Working,...
11
    var map = null;
3ef35c23   Sean Wills   Commented feature...
12
13
14
15
16
17
18
19
20
21
    var waypoints = [];
    var markers = [];
    var route = null;
    var map = null;
    var marker = null;
    var markers = [];
    var myLatLng = { lat: 0, lng: 0 };
    var directionsService = new google.maps.DirectionsService;
    var directionsDisplay = new google.maps.DirectionsRenderer({
      polylineOptions: {
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
      strokeColor: "#d8d8d8"
    }
    });
    var end;
    var marked;
    var valid = true;
    initMap();

    $scope.stops = [{
        "Description": "Start typing to search...",
        "changed": false

    }, {
        "Description": "Start typing to search...",
        "changed": false

    }]

    $scope.$watchCollection('stops', function () {

      if (initializing) {
        $timeout(function() { initializing = false; });
      } else {
        if ($scope.stops[$scope.stops.length -1].Description != "Start typing to search...") {
          $scope.stops.forEach(function(stop, i){
              if (stop.Description != "Start typing to search...") {
                valid = true;
              } else {
                valid = false;
              }
          })
        } else {
          valid = false;
        }

        $scope.stops.forEach(function(stop, i){
3ef35c23   Sean Wills   Commented feature...
58
59
60
61
62
63
64
          if (stop.Description != "Start typing to search..." && stop.changed == false) {
            if (i != 0 && i != $scope.stops.length-1) {
              drawMarker(stop.Latitude, stop.Longitude);
              waypoints.push({
                location: stop.Description,
                stopover: true
              });
de63be91   Sean Wills   No settings
65
            } else {
3ef35c23   Sean Wills   Commented feature...
66
67
68
69
70
              drawMarker(stop.Latitude, stop.Longitude);
            }
          }
        })

484036e0   Tarpit Grover   WIP
71
        if (valid == true) {
b2145b07   Tarpit Grover   WIP
72
          calculateAndDisplayRoute($scope.stops[0].Description, $scope.stops[$scope.stops.length - 1].Description);
3ef35c23   Sean Wills   Commented feature...
73
74
        }
      }
01ae2e35   Sean Wills   Falied smooth mov...
75
76

    }, true);
01ae2e35   Sean Wills   Falied smooth mov...
77

856e1d58   Sean Wills   Search menu
78
    function calculateAndDisplayRoute(start, end) {
3ef35c23   Sean Wills   Commented feature...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
        directionsService.route({
            origin: start,
            destination: end,
            waypoints: waypoints,
            travelMode: 'DRIVING',
            provideRouteAlternatives: false
        }, function(response, status) {
            if (status === 'OK') {
                directionsDisplay.setDirections(response);
                directionsDisplay.setOptions( { suppressMarkers: true } );
                pinA = new google.maps.Marker({
          				position: start,
          				map: map,
          				icon: '.././includes/images/c1.png'
          			}),
          			pinB = new google.maps.Marker({
          				position: end,
856e1d58   Sean Wills   Search menu
96
          				map: map,
856e1d58   Sean Wills   Search menu
97
          				icon: '.././includes/images/c1.png'
ec938bf0   Tarpit Grover   first commit
98
          			});
3ef35c23   Sean Wills   Commented feature...
99
100
101
102
103
104
105
106
107
            } else {
                console.log("Need more Stops", start, end, waypoints)
            }
        });
    }

    function clearMarkers() {
        markers = [];
    }
93483f6d   Sean Wills   Settings Working,...
108
109
110
111
112
113
114

    function setMapOnAll(map) {
        for (var i = 0; i < markers.length; i++) {
            markers[i].setMap(map);
        }
    }

3ef35c23   Sean Wills   Commented feature...
115
    function drawMarker(lat, lng) {
93483f6d   Sean Wills   Settings Working,...
116
117
118
119
120
        var marker = new google.maps.Marker({
            position: {lat: lat, lng: lng},
            icon: '.././includes/images/c1.png',
            map: map,
        });
3ef35c23   Sean Wills   Commented feature...
121
122
123
124
        markers.push(marker);
    }

    function initMap() {
93483f6d   Sean Wills   Settings Working,...
125
126
127

        map = new google.maps.Map(document.getElementById('map-div'), {
            center: { lat: 51.491903, lng: -0.024640 },
3ef35c23   Sean Wills   Commented feature...
128
129
            zoom: 10,
            mapTypeControl: false,
ec938bf0   Tarpit Grover   first commit
130
            styles: [{
ec938bf0   Tarpit Grover   first commit
131
                    "featureType": "all",
3ef35c23   Sean Wills   Commented feature...
132
                    "elementType": "labels.text.fill",
01ae2e35   Sean Wills   Falied smooth mov...
133
134
135
136
137
                    "stylers": [{
                            "saturation": 36
                        },
                        {
                            "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": 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
                        }
                    ]
                }
            ]
        });
        directionsDisplay.setMap(map);
    }
    });


// if (initializing) {
//   $timeout(function() { initializing = false; });
// } else {
b2145b07   Tarpit Grover   WIP
291
//   $scope.stops.forEach(function(stop, i){
ec938bf0   Tarpit Grover   first commit
292
//     if (i != 0 && i != $scope.stops.length-1) {
a0fba7c8   David Beech   david
293
//       directionsDisplay.set('directions', null);
ec938bf0   Tarpit Grover   first commit
294
//       if (stop.Description == "Start typing to search...") {
01ae2e35   Sean Wills   Falied smooth mov...
295
//         console.log("Typing not complete");
01ae2e35   Sean Wills   Falied smooth mov...
296
297
298
//       } else {
//         waypoints.push({
//           location: stop.Description,
b2145b07   Tarpit Grover   WIP
299
//           stopover: true
01ae2e35   Sean Wills   Falied smooth mov...
300
301
302
//         });
//         calculateAndDisplayRoute($scope.stops[0].Description, $scope.stops[$scope.stops.length - 1].Description);
//       }
b2145b07   Tarpit Grover   WIP
303
//
01ae2e35   Sean Wills   Falied smooth mov...
304
305
306
307
308
//
//
//     } else {
//       if (stop.Latitude != undefined && stop.Longitude != undefined) {
//           console.log(stop.Longitude);
856e1d58   Sean Wills   Search menu
309
//           console.log("Typing not complete");
3ef35c23   Sean Wills   Commented feature...
310
311
312
313
314
315
316
317
//
//           drawMarker(stop.Latitude, stop.Longitude);
//
//           directionsDisplay.set('directions', null);
//
//           calculateAndDisplayRoute($scope.stops[0].Description, $scope.stops[$scope.stops.length - 1].Description);
//
//        }
93483f6d   Sean Wills   Settings Working,...
318
//     }
3ef35c23   Sean Wills   Commented feature...
319
320
//   })
// }
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