@@ -124,6 +124,7 @@ export function getToggleHandlers({
124124 trafficLayerRef,
125125 locationProviderRef,
126126 jwt,
127+ focusSelectedRow,
127128} ) {
128129 const GenerateBubbles = ( bubbleName , cb ) => ( showBubble ) => {
129130 _ . forEach ( bubbleMapRef . current [ bubbleName ] , ( bubble ) => bubble . setMap ( null ) ) ;
@@ -422,12 +423,105 @@ export function getToggleHandlers({
422423 const bubbleName = "showTasksAsCreated" ;
423424 _ . forEach ( bubbleMapRef . current [ bubbleName ] , ( b ) => b . setMap ( null ) ) ;
424425 delete bubbleMapRef . current [ bubbleName ] ;
426+
427+ const getIcon = ( task ) => {
428+ const outcome = task . taskoutcome || "unknown" ;
429+ const urlBase = "http://maps.google.com/mapfiles/kml/shapes/" ;
430+ const icon = {
431+ url : urlBase ,
432+ scaledSize : new window . google . maps . Size ( 30 , 30 ) ,
433+ } ;
434+ if ( outcome . includes ( "SUCCEEDED" ) ) {
435+ icon . url += "flag.png" ;
436+ } else if ( outcome . includes ( "FAIL" ) ) {
437+ icon . url += "caution.png" ;
438+ } else {
439+ icon . url += "shaded_dot.png" ;
440+ }
441+ return icon ;
442+ } ;
443+
425444 if ( enabled ) {
426445 log ( `Enabling ${ bubbleName } ` ) ;
427- bubbleMapRef . current [ bubbleName ] = _ . map (
428- taskLogs . getTasks ( maxDate ) . value ( ) ,
429- ( t ) => new window . google . maps . Marker ( { map, position : t . plannedlocation . point } )
430- ) ;
446+ const tasks = taskLogs . getTasks ( maxDate ) . value ( ) ;
447+
448+ bubbleMapRef . current [ bubbleName ] = _ ( tasks )
449+ . map ( ( task ) => {
450+ if ( ! task . plannedlocation ?. point ) {
451+ return null ;
452+ }
453+
454+ const marker = new window . google . maps . Marker ( {
455+ position : {
456+ lat : task . plannedlocation . point . latitude ,
457+ lng : task . plannedlocation . point . longitude ,
458+ } ,
459+ map : map ,
460+ icon : getIcon ( task ) ,
461+ title : `${ task . state } : ${ task . taskid } - ${ task . trackingid } ` ,
462+ } ) ;
463+
464+ marker . addListener ( "click" , ( ) => {
465+ log ( `Task marker clicked: ${ task . taskid } ` ) ;
466+ const latestUpdateLog = _ . findLast ( tripLogs . rawLogs , ( le ) => {
467+ const type = le [ "@type" ] ;
468+ if ( type === "createTask" || type === "updateTask" || type === "getTask" ) {
469+ const idInResp = _ . get ( le , "response.name" , "" ) . split ( "/" ) . pop ( ) ;
470+ if ( idInResp === task . taskid ) return true ;
471+
472+ const idInReq = _ . get ( le , "request.taskid" ) ;
473+ if ( idInReq === task . taskid ) return true ;
474+ }
475+ return false ;
476+ } ) ;
477+
478+ if ( latestUpdateLog ) {
479+ log ( `Found matching log entry for task ${ task . taskid } ` , latestUpdateLog ) ;
480+ setFeaturedObject ( latestUpdateLog ) ;
481+ setTimeout ( ( ) => focusSelectedRow ( ) , 0 ) ;
482+ } else {
483+ setFeaturedObject ( task ) ;
484+ }
485+ } ) ;
486+
487+ const ret = [ marker ] ;
488+ if ( task . taskoutcomelocation ?. point && task . plannedlocation ?. point ) {
489+ log ( `Task ${ task . taskid } has taskoutcomelocation, drawing arrow.` ) ;
490+ const arrowColor = task . plannedVsActualDeltaMeters > 50 ? "#FF1111" : "#11FF11" ;
491+ const offSetPath = new window . google . maps . Polyline ( {
492+ path : [
493+ {
494+ lat : task . plannedlocation . point . latitude ,
495+ lng : task . plannedlocation . point . longitude ,
496+ } ,
497+ {
498+ lat : task . taskoutcomelocation . point . latitude ,
499+ lng : task . taskoutcomelocation . point . longitude ,
500+ } ,
501+ ] ,
502+ geodesic : true ,
503+ strokeColor : arrowColor ,
504+ strokeOpacity : 0.6 ,
505+ strokeWeight : 4 ,
506+ map : map ,
507+ icons : [
508+ {
509+ icon : {
510+ path : window . google . maps . SymbolPath . FORWARD_CLOSED_ARROW ,
511+ strokeColor : arrowColor ,
512+ strokeWeight : 4 ,
513+ } ,
514+ offset : "100%" ,
515+ } ,
516+ ] ,
517+ } ) ;
518+ ret . push ( offSetPath ) ;
519+ }
520+ return ret ;
521+ } )
522+ . flatten ( )
523+ . compact ( )
524+ . value ( ) ;
431525 }
432526 } ,
433527 showPlannedPaths : ( enabled ) => {
0 commit comments