/* * CUSF Landing Prediction Version 2 * Jon Sowman 2010 * jon@hexoc.com * http://www.hexoc.com * * http://github.com/jonsowman/cusf-standalone-predictor * */ // This function runs when the document object model is fully populated // and the page is loaded $(document).ready(function() { // Initialise the map canvas with parameters (lat, long, zoom-level) initMap(52, 0, 8); // Populate the launch site list from sites.json populateLaunchSite(); // Setup all event handlers in the UI using jQuery setupEventHandlers(); // Initialise UI elements such as draggable windows initUI(); // Check if an old prediction is to be displayed, and process if so displayOld(); // Plot the initial launch location plotClick(); // Initialise the burst calculator calc_init(); }); // See if an old UUID was supplied in the hashstring // If it was, extract it, then populate the launch card with its parameters // then display the prediction function displayOld() { // Are we trying to display an old prediction? if( window.location.hash != "" ) { var ln = window.location.hash.split("="); var posteq = ln[1]; if ( posteq.length != 40 ) { throwError("The supplied hashstring was not a valid UUID."); appendDebug("The hashstring was not the expected length"); } else { current_uuid = posteq; appendDebug("Got an old UUID to plot:
" + current_uuid); appendDebug("Trying to populate form with scenario data..."); populateFormByUUID(current_uuid); appendDebug("Trying to get progress JSON"); $.getJSON("preds/"+current_uuid+"/progress.json", function(progress) { appendDebug("Got progress JSON from server for UUID"); if ( progress['error'] || !progress['pred_complete'] ) { appendDebug("The prediction was not completed" + " correctly, quitting"); } else { appendDebug("JSON said the prediction completed " + "without errors"); writePredictionInfo(current_uuid, progress['run_time'], progress['gfs_timestamp']); getCSV(current_uuid); } }); } } } // A prediction has just been requested, so initialise the progress bar // and fade in the prediction progress window function predSub() { appendDebug(null, 1); // clear debug window appendDebug("Sending data to server..."); // Initialise progress bar $("#prediction_progress").progressbar({ value: 0 }); $("#prediction_status").html("Sending data to server..."); $("#status_message").fadeIn(250); } // Make an AJAX request to the server and get the scenario information // for a given UUID, then populate the launch card with it function populateFormByUUID(pred_uuid) { $.get("ajax.php", { "action":"getModelByUUID", "uuid":pred_uuid }, function(data) { if ( !data.valid ) { appendDebug("Populating form by UUID failed"); appendDebug("The server said the model it made was invalid"); } else { // we're good to go, populate the form $("#lat").val(data.latitude); $("#lon").val(data.longitude); $("#initial_alt").val(data.altitude); $("#hour").val(data.hour); // we need to make minutes be "04" instead of "4" var scenario_minute = data.minute; if ( scenario_minute < 10 ) scenario_minute = "0" + scenario_minute; $("#min").val(scenario_minute); $("#second").val(data.second); $("#day").val(data.day); $("#month").attr("selectedIndex", data.month-1); $("#year").val(data.year); // we have to use [] notation for // values that have -s in them $("#ascent").val(data['ascent-rate']); $("#drag").val(data['descent-rate']); $("#burst").val(data['burst-altitude']); $("#software").val(data.software); $("#delta_lat").val(data['lat-delta']); $("#delta_lon").val(data['lon-delta']); // now sort the map out SetSiteOther(); plotClick(); } }, 'json'); } // Add information to the hashstring of the current window function addHashLink(link) { var ln = "#!/" + link; window.location = ln; } // Clear the Launch Site dropdown and repopulate it with the information from // sites.json, as well as an "Other" option to open the saved locations window function populateLaunchSite() { $("#site > option").remove(); $.getJSON("sites.json", function(sites) { $.each(sites, function(sitename, site) { $("