@@ -671,53 +671,60 @@ function launchSitePredictions(times, station, properties, marker) {
671671 deletePredictions ( marker ) ;
672672 popupContent = popupContent . split ( "<button onclick='deletePredictions(" ) [ 0 ] ;
673673 }
674- times = times . split ( "," ) ;
675674 position = station . split ( "," ) ;
676675 properties = properties . split ( ":" ) ;
677676 var now = new Date ( ) ;
678- var maxCount = 7
679- var count = 0 ;
680- var day = 0 ;
681- var dates = [ ] ;
682- while ( day < 8 ) {
683- for ( var i = 0 ; i < times . length ; i ++ ) {
684- var date = new Date ( ) ;
685- var time = times [ i ] . split ( ":" ) ;
686- if ( time [ 0 ] != 0 ) {
687- date . setDate ( date . getDate ( ) + ( 7 + time [ 0 ] - date . getDay ( ) ) % 7 ) ;
688- }
689- date . setUTCHours ( time [ 1 ] ) ;
690- date . setUTCMinutes ( time [ 2 ] ) ;
691- date . setSeconds ( 0 ) ;
692- date . setMilliseconds ( 0 ) ;
693- date . setMinutes ( date . getMinutes ( ) - 45 ) ;
694- while ( date < now ) {
695- if ( time [ 0 ] == 0 ) {
696- date . setDate ( date . getDate ( ) + 1 ) ;
697- } else {
698- date . setDate ( date . getDate ( ) + 7 ) ;
677+ if ( times . length > 0 ) {
678+ times = times . split ( "," ) ;
679+ var maxCount = 7
680+ var count = 0 ;
681+ var day = 0 ;
682+ var dates = [ ] ;
683+ while ( day < 8 ) {
684+ for ( var i = 0 ; i < times . length ; i ++ ) {
685+ var date = new Date ( ) ;
686+ var time = times [ i ] . split ( ":" ) ;
687+ if ( time [ 0 ] != 0 ) {
688+ date . setDate ( date . getDate ( ) + ( 7 + time [ 0 ] - date . getDay ( ) ) % 7 ) ;
699689 }
700- }
701- if ( day > 0 ) {
702- if ( time [ 0 ] == 0 ) {
703- date . setDate ( date . getDate ( ) + day ) ;
704- } else {
705- date . setDate ( date . getDate ( ) + ( 7 * day ) ) ;
690+ date . setUTCHours ( time [ 1 ] ) ;
691+ date . setUTCMinutes ( time [ 2 ] ) ;
692+ date . setSeconds ( 0 ) ;
693+ date . setMilliseconds ( 0 ) ;
694+ // launch time 45 minutes before target time
695+ date . setMinutes ( date . getMinutes ( ) - 45 ) ;
696+ while ( date < now ) {
697+ if ( time [ 0 ] == 0 ) {
698+ date . setDate ( date . getDate ( ) + 1 ) ;
699+ } else {
700+ date . setDate ( date . getDate ( ) + 7 ) ;
701+ }
706702 }
707- }
708- if ( count < maxCount ) {
709- if ( ( ( date - now ) / 36e5 ) < 170 ) {
710- dates . push ( date . toISOString ( ) . split ( '.' ) [ 0 ] + "Z" ) ;
711- count += 1 ;
703+ if ( day > 0 ) {
704+ if ( time [ 0 ] == 0 ) {
705+ date . setDate ( date . getDate ( ) + day ) ;
706+ } else {
707+ date . setDate ( date . getDate ( ) + ( 7 * day ) ) ;
708+ }
709+ }
710+ if ( count < maxCount ) {
711+ if ( ( ( date - now ) / 36e5 ) < 170 ) {
712+ dates . push ( date . toISOString ( ) . split ( '.' ) [ 0 ] + "Z" ) ;
713+ count += 1 ;
714+ }
712715 }
713716 }
717+ day += 1 ;
714718 }
715- day += 1 ;
719+ dates . sort ( ) ;
720+ } else {
721+ var date = new Date ( ) ;
722+ var dates = [ ] ;
723+ dates . push ( date . toISOString ( ) . split ( '.' ) [ 0 ] + "Z" ) ;
716724 }
717- dates . sort ( ) ;
718725 var completed = 0 ;
719726 for ( var i = 0 ; i < dates . length ; i ++ ) {
720- var lon = ( ( 360 + ( position [ 1 ] % 360 ) ) % 360 )
727+ var lon = ( ( 360 + ( position [ 1 ] % 360 ) ) % 360 ) ;
721728 //var url = "https://predict.cusf.co.uk/api/v1/?launch_latitude=" + position[0] + "&launch_longitude=" + lon + "&launch_datetime=" + dates[i] + "&ascent_rate=" + properties[0] + "&burst_altitude=" + properties[2] + "&descent_rate=" + properties[1];
722729 var url = "https://api.v2.sondehub.org/tawhiri?launch_latitude=" + position [ 0 ] + "&launch_longitude=" + lon + "&launch_datetime=" + dates [ i ] + "&ascent_rate=" + properties [ 0 ] + "&burst_altitude=" + properties [ 2 ] + "&descent_rate=" + properties [ 1 ] ;
723730 showPrediction ( url ) . done ( handleData ) . fail ( handleError ) ;
@@ -853,31 +860,49 @@ function showLaunchSites() {
853860 for ( var key in json ) {
854861 if ( json . hasOwnProperty ( key ) ) {
855862 var latlon = [ json [ key ] . position [ 1 ] , json [ key ] . position [ 0 ] ] ;
856- var sondes = json [ key ] . rs_types ;
857863 var sondesList = "" ;
858- for ( var y = 0 ; y < sondes . length ; y ++ ) {
859- if ( Array . isArray ( sondes [ y ] ) == false ) {
860- sondes [ y ] = [ sondes [ y ] ] ;
861- }
862- if ( sondeCodes . hasOwnProperty ( sondes [ y ] [ 0 ] ) ) {
863- sondesList += sondeCodes [ sondes [ y ] [ 0 ] ]
864- if ( sondes [ y ] . length > 1 ) {
865- sondesList += " (" + sondes [ y ] [ 1 ] + " MHz)" ;
866- }
867- } else if ( unsupportedSondeCodes . hasOwnProperty ( sondes [ y ] [ 0 ] ) ) {
868- sondesList += unsupportedSondeCodes [ sondes [ y ] [ 0 ] ] ;
869- sondesList += " (cannot track)" ;
870- } else {
871- sondesList += sondes [ y ] [ 0 ] + " (unknown WMO code)" ;
872- }
873- if ( y < sondes . length - 1 ) {
874- sondesList += ", " ;
875- }
876- }
864+ var popupContent = "" ;
865+ var ascent_rate = 5 ;
866+ var descent_rate = 6 ;
867+ var burst_altitude = 26000 ;
868+ var burst_samples = "" ;
869+ var descent_samples = "" ;
877870 var marker = new L . circleMarker ( latlon , { color : '#696969' , fillColor : "white" , radius : 8 } ) ;
878871 var popup = new L . popup ( { autoClose : false , closeOnClick : false } ) ;
879872 marker . bindPopup ( popup ) ;
880873 launches . addLayer ( marker ) ;
874+
875+ // Match sonde codes
876+ if ( json [ key ] . hasOwnProperty ( 'rs_types' ) ) {
877+ var sondes = json [ key ] . rs_types ;
878+ for ( var y = 0 ; y < sondes . length ; y ++ ) {
879+ if ( Array . isArray ( sondes [ y ] ) == false ) {
880+ sondes [ y ] = [ sondes [ y ] ] ;
881+ }
882+ if ( sondeCodes . hasOwnProperty ( sondes [ y ] [ 0 ] ) ) {
883+ sondesList += sondeCodes [ sondes [ y ] [ 0 ] ]
884+ if ( sondes [ y ] . length > 1 ) {
885+ sondesList += " (" + sondes [ y ] [ 1 ] + " MHz)" ;
886+ }
887+ } else if ( unsupportedSondeCodes . hasOwnProperty ( sondes [ y ] [ 0 ] ) ) {
888+ sondesList += unsupportedSondeCodes [ sondes [ y ] [ 0 ] ] ;
889+ sondesList += " (cannot track)" ;
890+ } else {
891+ sondesList += sondes [ y ] [ 0 ] + " (unknown WMO code)" ;
892+ }
893+ if ( y < sondes . length - 1 ) {
894+ sondesList += ", " ;
895+ }
896+ }
897+ if ( sondes . includes ( "11" ) || sondes . includes ( "82" ) ) { //LMS6
898+ ascent_rate = 5 ;
899+ descent_rate = 2.5 ;
900+ burst_altitude = 33500 ;
901+ }
902+ popupContent += "<font style='font-size: 13px'>" + json [ key ] . station_name + "</font><br><br><b>Sondes launched:</b> " + sondesList ;
903+ }
904+
905+ // Generate prefilled suggestion form
881906 var popupLink = "https://docs.google.com/forms/d/e/1FAIpQLSfIbBSQMZOXpNE4VpK4BqUbKDPCWCDgU9QxYgmhh-JD-JGSsQ/viewform?usp=pp_url&entry.796606853=Modify+Existing+Site" ;
882907 popupLink += "&entry.749833526=" + key ;
883908 if ( json [ key ] . hasOwnProperty ( 'station_name' ) ) {
@@ -901,34 +926,26 @@ function showLaunchSites() {
901926 if ( json [ key ] . hasOwnProperty ( 'notes' ) ) {
902927 popupLink += "&entry.197384117=" + json [ key ] [ "notes" ] . replace ( / \s / g, '+' ) ;
903928 }
929+
930+ // Update prediction data if provided
931+ if ( json [ key ] . hasOwnProperty ( 'ascent_rate' ) ) {
932+ ascent_rate = json [ key ] [ "ascent_rate" ] ;
933+ }
934+ if ( json [ key ] . hasOwnProperty ( 'descent_rate' ) ) {
935+ descent_rate = json [ key ] [ "descent_rate" ] ;
936+ }
937+ if ( json [ key ] . hasOwnProperty ( 'burst_altitude' ) ) {
938+ burst_altitude = json [ key ] [ "burst_altitude" ] ;
939+ }
940+ if ( json [ key ] . hasOwnProperty ( 'burst_samples' ) ) {
941+ burst_samples = json [ key ] [ "burst_samples" ] ;
942+ }
943+ if ( json [ key ] . hasOwnProperty ( 'descent_samples' ) ) {
944+ descent_samples = json [ key ] [ "descent_samples" ] ;
945+ }
946+
947+ // Process launch schedule if provided
904948 if ( json [ key ] . hasOwnProperty ( 'times' ) ) {
905- var popupContent = null ;
906- popupContent = "<font style='font-size: 13px'>" + json [ key ] . station_name + "</font><br><br><b>Sondes launched:</b> " + sondesList ;
907- var ascent_rate = 5 ;
908- var descent_rate = 6 ;
909- var burst_altitude = 26000 ;
910- var burst_samples = "" ;
911- var descent_samples = "" ;
912- if ( json [ key ] . rs_types . includes ( "11" ) || json [ key ] . rs_types . includes ( "82" ) ) { //LMS6
913- ascent_rate = 5 ;
914- descent_rate = 2.5 ;
915- burst_altitude = 33500 ;
916- }
917- if ( json [ key ] . hasOwnProperty ( 'ascent_rate' ) ) {
918- ascent_rate = json [ key ] [ "ascent_rate" ] ;
919- }
920- if ( json [ key ] . hasOwnProperty ( 'descent_rate' ) ) {
921- descent_rate = json [ key ] [ "descent_rate" ] ;
922- }
923- if ( json [ key ] . hasOwnProperty ( 'burst_altitude' ) ) {
924- burst_altitude = json [ key ] [ "burst_altitude" ] ;
925- }
926- if ( json [ key ] . hasOwnProperty ( 'burst_samples' ) ) {
927- burst_samples = json [ key ] [ "burst_samples" ] ;
928- }
929- if ( json [ key ] . hasOwnProperty ( 'descent_samples' ) ) {
930- descent_samples = json [ key ] [ "descent_samples" ] ;
931- }
932949 popupContent += "<br><b>Launch schedule:</b>" ;
933950 for ( var x = 0 ; x < json [ key ] [ 'times' ] . length ; x ++ ) {
934951 popupContent += "<br>- " ;
@@ -952,17 +969,20 @@ function showLaunchSites() {
952969 }
953970 popupContent += json [ key ] [ 'times' ] [ x ] . split ( ":" ) [ 1 ] + ":" + json [ key ] [ 'times' ] [ x ] . split ( ":" ) [ 2 ] + " UTC" ;
954971 }
955- if ( json [ key ] . hasOwnProperty ( 'notes' ) ) {
956- popupContent += "<br><b>Notes:</b> " + json [ key ] [ "notes" ] ;
957- }
958- popupContent += "<br><b>Know when this site launches?</b> Contribute <a href='" + popupLink + "' target='_blank'>here</a>" ;
972+ }
973+
974+ // Show notes if provided
975+ if ( json [ key ] . hasOwnProperty ( 'notes' ) ) {
976+ popupContent += "<br><b>Notes:</b> " + json [ key ] [ "notes" ] ;
977+ }
978+
979+ popupContent += "<br><b>Know when this site launches?</b> Contribute <a href='" + popupLink + "' target='_blank'>here</a>" ;
980+
981+ // Create prediction button
982+ if ( json [ key ] . hasOwnProperty ( 'times' ) ) {
959983 popupContent += "<br><button onclick='launchSitePredictions(\"" + json [ key ] [ 'times' ] . toString ( ) + "\", \"" + latlon . toString ( ) + "\", \"" + ascent_rate + ":" + descent_rate + ":" + burst_altitude + ":" + burst_samples + ":" + descent_samples + "\", \"" + launches . getLayerId ( marker ) + "\")' style='margin-bottom:0;'>Generate Predictions</button>" ;
960984 } else {
961- popupContent = "<font style='font-size: 13px'>" + json [ key ] . station_name + "</font><br><br><b>Sondes launched:</b> " + sondesList ;
962- if ( json [ key ] . hasOwnProperty ( 'notes' ) ) {
963- popupContent += "<br><b>Notes:</b> " + json [ key ] [ "notes" ] ;
964- }
965- popupContent += "<br><b>Know when this site launches?</b> Contribute <a href='" + popupLink + "' target='_blank'>here</a>" ;
985+ popupContent += "<br><button onclick='launchSitePredictions(\"" + "\", \"" + latlon . toString ( ) + "\", \"" + ascent_rate + ":" + descent_rate + ":" + burst_altitude + ":" + burst_samples + ":" + descent_samples + "\", \"" + launches . getLayerId ( marker ) + "\")' style='margin-bottom:0;'>Instant Prediction</button>" ;
966986 }
967987 popup . setContent ( popupContent ) ;
968988 }
0 commit comments