Skip to content

Commit 20b40c6

Browse files
Small updates and fixes in waypoints logic
1 parent 1c2911c commit 20b40c6

File tree

3 files changed

+75
-26
lines changed

3 files changed

+75
-26
lines changed

app/controller/NavigationController.js

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -329,34 +329,66 @@ SDL.NavigationController = Em.Object.create(
329329
'currentWayPointData',
330330
JSON.stringify(SDL.NavigationModel.WayPointDetails[itemID], null, 2)
331331
);
332+
333+
function rebuildRoute(){
334+
var travelMode = google.maps.DirectionsTravelMode.DRIVING;
335+
var waypoints = SDL.NavigationController.getWaypointsRequestParam();
336+
var destination = waypoints.pop();
337+
var request = {
338+
origin: SDL.NavigationModel.vehicleLocationMarker.getPosition(),
339+
destination: destination.location,
340+
waypoints: waypoints,
341+
optimizeWaypoints: true,
342+
travelMode: travelMode
343+
};
344+
SDL.NavigationController.polyline = new google.maps.Polyline({
345+
path: [],
346+
strokeColor: '#0000FF',
347+
strokeWeight: 3
348+
});
349+
SDL.NavigationController.directionsService.route(
350+
request,
351+
SDL.NavigationController.makeRouteCallback()
352+
);
353+
};
354+
332355
SDL.NavigationView.codeEditor.activate(
333356
function(data, isDeleted) {
334357
if (isDeleted) {
335358
var location = SDL.NavigationModel.WayPointDetails[itemID];
336359
SDL.NavigationModel.WayPointDetails.removeObject(location);
337-
var wp = SDL.NavigationModel.waypoints[itemID];
338-
SDL.NavigationModel.waypoints.removeObject(wp);
339360
var marker = SDL.NavigationModel.WayPointMarkers[itemID];
361+
SDL.NavigationModel.WayPointMarkers.removeObject(marker);
340362
marker.setMap(null);
341363
if (SDL.NavigationModel.WayPointDetails.length == 0) {
342-
SDL.NavigationModel.set('wp', false);
364+
SDL.NavigationController.clearRoutes();
365+
FFW.Navigation.onWayPointChange([]);
366+
} else {
367+
rebuildRoute();
343368
}
344369
} else {
345370
var locations = SDL.deepCopy(SDL.NavigationModel.WayPointDetails);
346-
var old_coords = locations[itemID].coordinate;
347-
var new_location = JSON.parse(data);
371+
var newLocation = JSON.parse(data);
348372
locations.splice(itemID, 1);
349373
var dt =
350-
SDL.NavigationController.convertDateTimeStructure(new_location.timeStamp);
374+
SDL.NavigationController.convertDateTimeStructure(newLocation.timeStamp);
351375
var insertInd =
352376
SDL.NavigationController.getInsertLocationIndex(locations, dt);
353377

354378
if (insertInd >= 0) {
355-
locations.splice(insertInd, 0, new_location);
379+
locations.splice(insertInd, 0, newLocation);
356380
} else {
357-
locations.push(new_location);
381+
locations.push(newLocation);
358382
}
359383
SDL.NavigationModel.set('WayPointDetails', locations);
384+
385+
var marker = SDL.NavigationModel.WayPointMarkers[itemID];
386+
var newCoords = new google.maps.LatLng(
387+
newLocation.coordinate.latitudeDegrees,
388+
newLocation.coordinate.longitudeDegrees
389+
);
390+
marker.setPosition(newCoords);
391+
rebuildRoute();
360392
}
361393
}
362394
);
@@ -655,7 +687,8 @@ SDL.NavigationController = Em.Object.create(
655687
this.map.panTo(marker.getPosition());
656688
},
657689
addWP: function() {
658-
if (SDL.NavigationModel.selectedLocationMarker == null) {
690+
if (SDL.NavigationModel.selectedLocationMarker == null ||
691+
SDL.NavigationModel.selectedLocationMarker.getMap() == null) {
659692
SDL.PopUp.create().appendTo('body').popupActivate(
660693
'Error: Please, select WayPoint'
661694
);
@@ -666,10 +699,7 @@ SDL.NavigationController = Em.Object.create(
666699
map: SDL.NavigationController.map
667700
});
668701
SDL.NavigationModel.WayPointMarkers.push(marker);
669-
SDL.NavigationModel.waypoints.push({
670-
location: SDL.NavigationModel.selectedLocationMarker.getPosition(),
671-
stopover: true
672-
});
702+
SDL.NavigationModel.selectedLocationMarker.setMap(null);
673703
},
674704
addWaypointLocation: function(latlng) {
675705
var res = SDL.NavigationController.getLocationByCoord(
@@ -761,6 +791,16 @@ SDL.NavigationController = Em.Object.create(
761791
SDL.NavigationController.addPOIMarker(latlng.lat(), latlng.lng());
762792
SDL.NavigationView.codeEditor.deactivate();
763793
},
794+
getWaypointsRequestParam: function() {
795+
var result = [];
796+
for (i = 0; i < SDL.NavigationModel.WayPointMarkers.length; ++i) {
797+
result.push({
798+
location: SDL.NavigationModel.WayPointMarkers[i].getPosition(),
799+
stopover: true
800+
});
801+
}
802+
return result;
803+
},
764804
getManeuverImageName: function(maneuver, instructions) {
765805
var locationImageValue = '';
766806
switch (maneuver) {
@@ -887,15 +927,16 @@ SDL.NavigationController = Em.Object.create(
887927
},
888928
clearRoutes: function() {
889929
SDL.NavigationController.toggleProperty('isRouteSet');
930+
if (SDL.NavigationModel.WayPointDetails.length > 0) {
931+
FFW.Navigation.onWayPointChange([]);
932+
}
890933
SDL.NavigationController.clearWaypointMarkers();
891934
SDL.NavigationController.directionsRenderer.setMap(null);
892935
SDL.NavigationModel.vehicleLocationMarker.setAnimation(null);
893936
SDL.NavigationController.set('endLocation', null);
894-
SDL.NavigationModel.set('waypoints', []);
895937
if (SDL.NavigationModel.wp) {
896938
SDL.NavigationModel.toggleProperty('wp');
897939
}
898-
899940
},
900941
setRoutes: function() {
901942
if (SDL.NavigationModel.selectedLocationMarker == null) {
@@ -936,7 +977,7 @@ SDL.NavigationController = Em.Object.create(
936977
var request = {
937978
origin: SDL.NavigationModel.vehicleLocationMarker.getPosition(),
938979
destination: SDL.NavigationModel.selectedLocationMarker.getPosition(),
939-
waypoints: SDL.NavigationModel.waypoints,
980+
waypoints: SDL.NavigationController.getWaypointsRequestParam(),
940981
optimizeWaypoints: true,
941982
travelMode: travelMode
942983
};
@@ -953,7 +994,8 @@ SDL.NavigationController = Em.Object.create(
953994
tick: 500, // milliseconds
954995
eol: [],
955996
animate: function(d) {
956-
if (d > SDL.NavigationController.eol) {
997+
if (d > SDL.NavigationController.eol ||
998+
SDL.NavigationModel.WayPointMarkers.length == 0) {
957999
SDL.NavigationModel.vehicleLocationMarker.setPosition(
9581000
SDL.NavigationController.endLocation
9591001
);
@@ -1009,6 +1051,10 @@ SDL.NavigationController = Em.Object.create(
10091051
SDL.NavigationModel.WayPointMarkers.removeObject(
10101052
markersToRemove[i]
10111053
);
1054+
if (SDL.NavigationModel.WayPointMarkers.length == 1) {
1055+
SDL.NavigationController.endLocation =
1056+
SDL.NavigationModel.WayPointMarkers[0].getPosition();
1057+
}
10121058
}
10131059
SDL.NavigationModel.WayPointDetails.removeObject(
10141060
SDL.NavigationModel.WayPointDetails[0]);
@@ -1037,6 +1083,9 @@ SDL.NavigationController = Em.Object.create(
10371083
if (this.model.poi) {
10381084
this.model.toggleProperty('poi');
10391085
}
1086+
if (this.model.wp) {
1087+
this.model.toggleProperty('wp');
1088+
}
10401089
if (SDL.SDLVehicleInfoModel.vehicleData.speed == 0) {
10411090
SDL.SDLVehicleInfoModel.set('vehicleData.speed', 80);
10421091
}

app/model/NavigationModel.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ SDL.NavigationModel = Em.Object.create({
9393
/**
9494
* Waypoint markers array
9595
*/
96-
WayPointMarkers: [],
97-
98-
/**
99-
*
100-
*/
101-
waypoints: []
102-
96+
WayPointMarkers: []
10397
}
10498
);

app/view/navigationView.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ SDL.NavigationView = Em.ContainerView.create(
148148
),
149149
WPButton: SDL.Button.extend(
150150
{
151+
isButtonDisabled: function() {
152+
return SDL.NavigationModel.WayPointDetails.length == 0 ||
153+
SDL.NavigationController.isAnimateStarted;
154+
}.property('SDL.NavigationModel.WayPointDetails',
155+
'SDL.NavigationController.isAnimateStarted'),
151156
classNameBindings: 'SDL.FuncSwitcher.rev::is-disabled',
157+
disabledBinding: 'isButtonDisabled',
152158
elementId: 'WPButton',
153159
classNames: 'WPButton button',
154160
text: 'Waypoints',
@@ -159,6 +165,7 @@ SDL.NavigationView = Em.ContainerView.create(
159165
AddWP: SDL.Button.extend(
160166
{
161167
classNameBindings: 'SDL.FuncSwitcher.rev::is-disabled',
168+
disabledBinding: 'SDL.NavigationController.isRouteSet',
162169
elementId: 'AddWP',
163170
classNames: 'AddWP button',
164171
text: 'Add waypoint',
@@ -205,7 +212,6 @@ SDL.NavigationView = Em.ContainerView.create(
205212
action: 'startAnimation',
206213
target: 'SDL.NavigationController'
207214
}
208-
),
209-
215+
)
210216
}
211217
);

0 commit comments

Comments
 (0)