@@ -1176,55 +1176,55 @@ function addPosition(position) {
11761176
11771177 if ( vehicle . vehicle_type == "balloon" ) {
11781178 var new_latlng = new google . maps . LatLng ( position . gps_lat , position . gps_lon ) ;
1179+ var dt = ( convert_time ( position . gps_time ) - convert_time ( vehicle . curr_position . gps_time ) ) / 1000 ; // convert to seconds
11791180
1180- // if position array has at least 1 position
1181- if ( vehicle . num_positions > 0 ) {
1182- if ( convert_time ( vehicle . curr_position . gps_time ) == convert_time ( position . gps_time ) ) {
1183- if ( ( "," + vehicle . curr_position . callsign + "," ) . indexOf ( "," + position . callsign + "," ) === - 1 ) {
1184- vehicle . curr_position . callsign += "," + position . callsign ;
1185- }
1186-
1187- vehicle . updated = true ;
1188- } else {
1189- var dt = ( convert_time ( position . gps_time ) - convert_time ( vehicle . curr_position . gps_time ) ) / 1000 ; // convert to seconds
1190-
1191- if ( dt > 0 ) {
1192- // calculate vertical rate
1193- var rate = ( position . gps_alt - vehicle . curr_position . gps_alt ) / dt ;
1194- vehicle . ascent_rate = 0.7 * rate
1195- + 0.3 * vehicle . ascent_rate ;
1196-
1197- // calculate horizontal rate
1198- vehicle . horizontal_rate = google . maps . geometry . spherical . computeDistanceBetween ( new google . maps . LatLng ( position . gps_lat , position . gps_lon ) ,
1199- new google . maps . LatLng ( vehicle . curr_position . gps_lat , vehicle . curr_position . gps_lon ) ) / dt ;
1200-
1201- // only record altitude values in 2minute interval
1202- if ( convert_time ( vehicle . curr_position . gps_time ) - vehicle . time_last_alt >= 120000 ) { // 120s = 2minutes
1203- vehicle . time_last_alt = convert_time ( vehicle . curr_position . gps_time ) ;
1204- var alt = parseInt ( vehicle . curr_position . gps_alt ) ;
1205-
1206- if ( alt > vehicle . alt_max ) vehicle . alt_max = alt ; // larged value in the set is required for encoding later
1207-
1208- vehicle . alt_list . push ( alt ) ; // push value to the list
1209- }
1210- }
1181+ if ( dt == 0 ) {
1182+ if ( ( "," + vehicle . curr_position . callsign + "," ) . indexOf ( "," + position . callsign + "," ) === - 1 ) {
1183+ vehicle . curr_position . callsign += "," + position . callsign ;
12111184 }
1185+
1186+ vehicle . updated = true ;
12121187 }
1188+ else if ( dt > 0 ) {
1189+ if ( vehicle . num_positions > 0 ) {
1190+ // calculate vertical rate
1191+ var rate = ( position . gps_alt - vehicle . curr_position . gps_alt ) / dt ;
1192+ vehicle . ascent_rate = 0.7 * rate
1193+ + 0.3 * vehicle . ascent_rate ;
1194+
1195+ // calculate horizontal rate
1196+ vehicle . horizontal_rate = google . maps . geometry . spherical . computeDistanceBetween ( new google . maps . LatLng ( position . gps_lat , position . gps_lon ) ,
1197+ new google . maps . LatLng ( vehicle . curr_position . gps_lat , vehicle . curr_position . gps_lon ) ) / dt ;
1198+ }
1199+
1200+ // record altitude values for the drowing a mini profile
1201+ // only record altitude values in 2minute interval
1202+ if ( convert_time ( vehicle . curr_position . gps_time ) - vehicle . time_last_alt >= 120000 ) { // 120s = 2minutes
1203+ vehicle . time_last_alt = convert_time ( vehicle . curr_position . gps_time ) ;
1204+ var alt = parseInt ( vehicle . curr_position . gps_alt ) ;
1205+
1206+ if ( alt > vehicle . alt_max ) vehicle . alt_max = alt ; // larged value in the set is required for encoding later
1207+
1208+ vehicle . alt_list . push ( alt ) ; // push value to the list
1209+ }
12131210
1214- if ( ! vehicle . curr_position
1215- || vehicle . curr_position . gps_lat != position . gps_lat
1216- || vehicle . curr_position . gps_lon != position . gps_lon ) {
12171211 // add the new position
1218- vehicle . positions . push ( new_latlng ) ;
1219- vehicle . num_positions ++ ;
1220-
1221- vehicle . curr_position = position ;
1222- graphAddLastPosition ( vehicle_index ) ;
1223- vehicle . updated = true ;
1212+ if ( ! vehicle . curr_position
1213+ || vehicle . curr_position . gps_lat != position . gps_lat
1214+ || vehicle . curr_position . gps_lon != position . gps_lon ) {
1215+ // add the new position
1216+ vehicle . positions . push ( new_latlng ) ;
1217+ vehicle . num_positions ++ ;
1218+
1219+ vehicle . curr_position = position ;
1220+ graphAddLastPosition ( vehicle_index ) ;
1221+ vehicle . updated = true ;
12241222
1225- var poslen = vehicle . num_positions ;
1226- if ( poslen > 1 ) vehicle . path_length += google . maps . geometry . spherical . computeDistanceBetween ( vehicle . positions [ poslen - 2 ] , vehicle . positions [ poslen - 1 ] ) ;
1223+ var poslen = vehicle . num_positions ;
1224+ if ( poslen > 1 ) vehicle . path_length += google . maps . geometry . spherical . computeDistanceBetween ( vehicle . positions [ poslen - 2 ] , vehicle . positions [ poslen - 1 ] ) ;
1225+ }
12271226 }
1227+
12281228 } else { // if car
12291229 vehicle . updated = true ;
12301230 vehicle . curr_position = position ;
0 commit comments