@@ -825,6 +825,40 @@ function drawAltitudeProfile(c1, c2, alt_list, alt_max) {
825825 ctx2 . fill ( ) ;
826826}
827827
828+ // infobox
829+ var mapInfoBox = new google . maps . InfoWindow ( ) ;
830+
831+ var mapInfoBox_handle_path = function ( event ) {
832+ var value = "" ;
833+
834+ if ( offline . get ( 'opt_imperial' ) ) {
835+ value = Math . round ( this . vehicle . path_length * 0.000621371192 ) + " miles" ;
836+ } else {
837+ value = Math . round ( this . vehicle . path_length / 10 ) / 100 + " km" ;
838+ }
839+
840+ mapInfoBox . setContent ( "Ground length: " + value ) ;
841+ mapInfoBox . setPosition ( event . latLng ) ;
842+ mapInfoBox . open ( map ) ;
843+ }
844+ var mapInfoBox_handle_horizons = function ( event , obj , title ) {
845+ var value = "" ;
846+
847+ if ( offline . get ( 'opt_imperial' ) ) {
848+ value = Math . round ( obj . getRadius ( ) * 0.000621371192 ) + " miles" ;
849+ } else {
850+ value = Math . round ( obj . getRadius ( ) / 10 ) / 100 + " km" ;
851+ }
852+
853+
854+ mapInfoBox . setContent ( title + "<br/>Radius: " + value ) ;
855+ mapInfoBox . setPosition ( event . latLng ) ;
856+ mapInfoBox . open ( map ) ;
857+ }
858+
859+ var mapInfoBox_handle_truehorizon = function ( event ) { mapInfoBox_handle_horizons ( event , this , "True Horizon" ) ; }
860+ var mapInfoBox_handle_horizon = function ( event ) { mapInfoBox_handle_horizons ( event , this , "5° Horizon" ) ; }
861+
828862function addPosition ( position ) {
829863 // check if the vehicle is already in the list, if not create a new item
830864 if ( $ . inArray ( position . vehicle , vehicle_names ) == - 1 ) {
@@ -932,7 +966,7 @@ function addPosition(position) {
932966 strokeColor : '#00F' ,
933967 strokeOpacity : 0.6 ,
934968 strokeWeight : 3 ,
935- clickable : false ,
969+ clickable : true ,
936970 editable : false
937971 } ) ;
938972 horizon_circle . bindTo ( 'center' , marker_shadow , 'position' ) ;
@@ -945,7 +979,7 @@ function addPosition(position) {
945979 strokeColor : '#0F0' ,
946980 strokeOpacity : 0.8 ,
947981 strokeWeight : 3 ,
948- clickable : false ,
982+ clickable : true ,
949983 editable : false
950984 } ) ;
951985 subhorizon_circle . bindTo ( 'center' , marker_shadow , 'position' ) ;
@@ -959,6 +993,7 @@ function addPosition(position) {
959993 subhorizon_circle : subhorizon_circle ,
960994 num_positions : 0 ,
961995 positions : [ ] ,
996+ path_length : 0 ,
962997 curr_position : position ,
963998 line : [ ] ,
964999 polyline : [ new google . maps . Polyline ( {
@@ -967,7 +1002,7 @@ function addPosition(position) {
9671002 strokeColor : balloon_colors [ c ] ,
9681003 strokeOpacity : 0.8 ,
9691004 strokeWeight : 3 ,
970- clickable : false ,
1005+ clickable : true ,
9711006 draggable : false ,
9721007 } ) ] ,
9731008 prediction : null ,
@@ -1019,19 +1054,31 @@ function addPosition(position) {
10191054 var rainbow = [ "#ff0000" , "#fc9a00" , "#f6ff00" , "#38ff01" , "#009aff" , "#0000ff" ] ;
10201055 vehicle_info . polyline = [ ] ;
10211056
1022- for ( k in rainbow ) {
1057+ for ( var k in rainbow ) {
10231058 vehicle_info . polyline . push ( new google . maps . Polyline ( {
10241059 map : map ,
10251060 zIndex : ( Z_PATH - ( k * 1 ) ) ,
10261061 strokeColor : rainbow [ k ] ,
10271062 strokeOpacity : 1 ,
10281063 strokeWeight : ( k * 4 ) + 2 ,
1029- clickable : false ,
1064+ clickable : true ,
10301065 draggable : false ,
10311066 } ) ) ;
10321067 }
10331068 }
10341069
1070+ // hook infobox
1071+
1072+ // polyline
1073+ for ( var k in vehicle_info . polyline ) {
1074+ vehicle_info . polyline [ k ] . vehicle = vehicle_info ;
1075+ google . maps . event . addListener ( vehicle_info . polyline [ k ] , 'click' , mapInfoBox_handle_path ) ;
1076+ }
1077+
1078+ // horizon circles
1079+ if ( vehicle_info . horizon_circle ) google . maps . event . addListener ( vehicle_info . horizon_circle , 'click' , mapInfoBox_handle_truehorizon ) ;
1080+ if ( vehicle_info . subhorizon_circle ) google . maps . event . addListener ( vehicle_info . subhorizon_circle , 'click' , mapInfoBox_handle_horizon ) ;
1081+
10351082 // let the nyan free
10361083 vehicles . push ( vehicle_info ) ;
10371084 }
@@ -1083,6 +1130,9 @@ function addPosition(position) {
10831130 vehicle . curr_position = position ;
10841131 graphAddLastPosition ( vehicle_index ) ;
10851132 vehicle . updated = true ;
1133+
1134+ var poslen = vehicle . positions . length ;
1135+ if ( poslen > 1 ) vehicle . path_length += google . maps . geometry . spherical . computeDistanceBetween ( vehicle . positions [ poslen - 2 ] , vehicle . positions [ poslen - 1 ] ) ;
10861136 }
10871137 }
10881138 } else {
@@ -1091,6 +1141,9 @@ function addPosition(position) {
10911141 vehicle . num_positions ++ ;
10921142 vehicle . curr_position = position ;
10931143 graphAddLastPosition ( vehicle_index ) ;
1144+
1145+ var poslen = vehicle . positions . length ;
1146+ if ( poslen > 1 ) vehicle . path_length += google . maps . geometry . spherical . computeDistanceBetween ( vehicle . positions [ poslen - 2 ] , vehicle . positions [ poslen - 1 ] ) ;
10941147 }
10951148 } else { // if car
10961149 vehicle . updated = true ;
@@ -1427,6 +1480,8 @@ function refreshUI() {
14271480 for ( var i = 0 , ii = vehicle_names . length ; i < ii ; i ++ ) {
14281481 updateVehicleInfo ( i , vehicles [ i ] . curr_position ) ;
14291482 }
1483+
1484+ mapInfoBox . close ( ) ;
14301485}
14311486
14321487var status = "" ;
0 commit comments