@@ -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 }
0 commit comments