@@ -14,6 +14,7 @@ var receivers = [];
1414var num_updates = 0 ;
1515var got_positions = false ;
1616var zoomed_in = false ;
17+ var expanded_onload = false ;
1718var max_positions = 0 ; // maximum number of positions that ajax request should return (0 means no maximum)
1819var selector = null ;
1920var window_selector = null ;
@@ -222,8 +223,9 @@ function updateZoom() {
222223function followVehicle ( index ) {
223224 if ( follow_vehicle != - 1 ) vehicles [ follow_vehicle ] . follow = false ;
224225
226+ panTo ( index ) ;
227+
225228 if ( follow_vehicle != index ) {
226- panTo ( index ) ;
227229 follow_vehicle = index ;
228230 vehicles [ follow_vehicle ] . follow = true ;
229231 }
@@ -281,19 +283,23 @@ function updateVehicleInfo(index, position) {
281283
282284 var image = vehicles [ index ] . image_src ;
283285
284- //var container = $('vehicle' + index);
285286 var elm = $ ( '.vehicle' + index ) ;
286287 if ( elm . length == 0 ) {
287- var active = ( index == 0 ) ? 'active' : '' ;
288+ var active = '' ;
289+ if ( ! expanded_onload && vehicles [ index ] . vehicle_type == "balloon" ) {
290+ active = 'active' ;
291+ expanded_onload = true ;
292+ }
288293 $ ( '.portrait' ) . append ( '<div class="row ' + active + ' vehicle' + index + '"></div>' ) ;
289294 $ ( '.landscape' ) . append ( '<div class="row ' + active + ' vehicle' + index + '"></div>' ) ;
290-
295+
291296 }
292297
293298 var ascent_text = position . gps_alt != 0 ? vehicles [ index ] . ascent_rate . toFixed ( 1 ) + ' m/s' : '' ;
294299
295300 var coords_text ;
296301 var ua = navigator . userAgent . toLowerCase ( ) ;
302+ // determine how to link the vehicle coordinates to a native app, if on a mobile device
297303 if ( ua . indexOf ( 'iphone' ) > - 1 ) {
298304 coords_text = '<a id="launch_mapapp" href="http://maps.google.com/?q=' + position . gps_lat + ',' + position . gps_lon + '">'
299305 + roundNumber ( position . gps_lat , 6 ) + ', ' + roundNumber ( position . gps_lon , 6 ) + '</a>'
@@ -489,38 +495,6 @@ function convert_time(gps_time) {
489495 return date . getTime ( ) / 1000 ; // seconds since 1/1/1970 @ 12:00 AM
490496}
491497
492- function findPosition ( positions , other ) {
493- var sequence = other . sequence ;
494- if ( ! sequence || sequence == '' || sequence == 0 ) {
495- return - 1 ;
496- }
497- for ( var i = 0 , ii = positions . length ; i < ii ; i ++ ) {
498- if ( positions [ i ] . sequence != sequence ) continue ;
499- if ( positions [ i ] . gps_lat != other . gps_lat ) continue ;
500- if ( positions [ i ] . gps_lon != other . gps_lon ) continue ;
501- if ( positions [ i ] . gps_time != other . gps_time ) continue ;
502- return i ;
503- }
504- return - 1 ;
505- }
506-
507-
508-
509- function insertPosition ( vehicle , position ) {
510- var i = vehicle . positions . length ;
511- while ( i -- ) {
512- if ( i >= 0 && convert_time ( vehicle . positions [ i ] . server_time ) < convert_time ( position . server_time ) ) {
513- break ;
514- }
515- }
516- vehicle . positions . splice ( i + 1 , 0 , position ) ;
517- // add the point to form new lines
518- vehicle . line . splice ( i + 1 , 0 , new google . maps . LatLng ( position . gps_lat , position . gps_lon ) ) ;
519- var curr_time = convert_time ( position . server_time ) * 1000 ;
520- vehicle . alt_data . splice ( i + 1 , 0 , new Array ( curr_time , position . gps_alt ) ) ;
521- return vehicle . positions [ vehicle . positions . length - 1 ] ;
522- }
523-
524498function addPosition ( position ) {
525499
526500 position . sequence = position . sequence ? parseInt ( position . sequence , 10 ) : null ;
@@ -625,7 +599,7 @@ function addPosition(position) {
625599 horizon_circle : horizon_circle ,
626600 subhorizon_circle : subhorizon_circle ,
627601 num_positions : 0 ,
628- positions : new google . maps . MVCArray ,
602+ positions : [ ] ,
629603 curr_position : position ,
630604 line : [ ] ,
631605 polyline : new google . maps . Polyline ( {
@@ -750,7 +724,7 @@ function refreshPredictions() {
750724}
751725
752726var periodical , periodical_receivers , periodical_predictions ;
753- var timer_seconds = 30 ;
727+ var timer_seconds = 3 ;
754728
755729function startAjax ( ) {
756730 // prevent insane clicks to start numerous requests
@@ -775,16 +749,6 @@ function stopAjax() {
775749 clearTimeout ( periodical ) ;
776750}
777751
778- function centerAndZoomOnBounds ( bounds ) {
779- var center = bounds . getCenter ( ) ;
780- var newZoom = map . getBoundsZoomLevel ( bounds ) ;
781- if ( map . getZoom ( ) != newZoom ) {
782- map . setCenter ( center , newZoom ) ;
783- } else {
784- map . panTo ( center ) ;
785- }
786- }
787-
788752var currentPosition = null ;
789753
790754function updateCurrentPosition ( lat , lon ) {
@@ -900,15 +864,28 @@ function update(response) {
900864 }
901865
902866 if ( got_positions && ! zoomed_in ) {
903- map . panTo ( vehicles [ 0 ] . marker . getPosition ( ) ) ;
904- /*
905- if(vehicles[0].polyline) {
906- centerAndZoomOnBounds(vehicles[0].polyline.getBounds());
907- } else {
908- map.setCenter(vehicles[0].line[0]);
909- map.setZoom(10);
910- }
911- */
867+ // find a the first balloon
868+ var i = 0 ;
869+ while ( ! vehicles [ i ] . marker_shadow ) i ++ ;
870+
871+ // find the bounds of the ballons first and last positions
872+ var bounds = new google . maps . LatLngBounds ( ) ;
873+ bounds . extend ( vehicles [ i ] . marker . getPosition ( ) ) ;
874+ bounds . extend ( vehicles [ i ] . positions [ 0 ] ) ;
875+
876+ // fit the map to those bounds
877+ map . fitBounds ( bounds ) ;
878+
879+ // limit the zoom level to 11
880+ if ( map . getZoom ( ) > 11 ) map . setZoom ( 11 ) ;
881+
882+ // pan and follow that balloon
883+ followVehicle ( i ) ;
884+
885+ // scroll list to the expanded element
886+ listScroll . refresh ( ) ;
887+ listScroll . scrollToElement ( '.portrait .vehicle' + i ) ;
888+
912889 zoomed_in = true ;
913890 }
914891
0 commit comments