var g_map_object = null; function init_map() { var latlng = new google.maps.LatLng(52, 0); var options = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map_canvas'), options) g_map_object = map; } function prediction_entry_convert_date(when) { var time = new Date(); time.setUTCFullYear(when.year); time.setUTCMonth(when.month - 1); time.setUTCDate(when.day); time.setUTCHours(when.hour); time.setUTCMinutes(when.minute); time.setUTCSeconds(when.second); return time; } var g_predictions = { }; function show_prediction(uuid, launch_time, landing_time) { if(g_predictions[uuid] != null) { return; } $.get('data/' + uuid + '/output.csv', null, function(data, textStatus) { var lines = data.split('\n'); var path = [ ]; var max_height = -10; var max_point = null; $.each(lines, function(idx, line) { entry = line.split(','); if(entry.length >= 4) { var point = new google.maps.LatLng( parseFloat(entry[1]), parseFloat(entry[2]) ); if(parseFloat(entry[3]) > max_height) { max_height = parseFloat(entry[3]); max_point = point; } path.push(point); } }); var path_polyline = new google.maps.Polyline({ path: path, strokeColor: '#000000', strokeWeight: 3, strokeOpacity: 0.75, }); path_polyline.setMap(g_map_object); var pop_icon = new google.maps.MarkerImage('images/pop-marker.png', new google.maps.Size(16, 16), new google.maps.Point(0, 0), new google.maps.Point(8, 8)); var pop_marker = new google.maps.Marker({ position: max_point, map: g_map_object, icon: pop_icon, title: 'Baloon burst (max. altitude: ' + max_height + 'm)', }); google.maps.event.addListener(path_polyline, 'click', function() { hide_prediction(uuid); }); google.maps.event.addListener(pop_marker, 'click', function() { hide_prediction(uuid); }); // Add a row to the prediction table var new_row = $( 'table#trails tbody').append('
Launch time: ' + launch_time.format('%d/%b/%Y %H:%M:%S') + '
' + 'Landing time: ' + landing_time.format('%d/%b/%Y %H:%M:%S') + '
' + 'Landing location: ' + where.latitude + '°N ' + where.longitude + '°E
' + 'Raw output data (opens in new window)
' }); google.maps.event.addListener(marker, 'click', function() { show_prediction(prediction.uuid, launch_time, landing_time); }); google.maps.event.addListener(marker, 'rightclick', function() { info_window.open(g_map_object, marker); }); g_prediction_map_objects[prediction.uuid] = { 'info_window': info_window, 'marker': marker, }; }); // Plot a path for the predictions var pred_path = new google.maps.Polyline({ path: prediction_coords, strokeColor: '#ff4444', strokeOpacity: 0.5, strokeWeight: 2, }); pred_path.setMap(g_map_object); var template = data['scenario-template']; $('#launch-lat').text(template['launch-site'].latitude); $('#launch-lon').text(template['launch-site'].longitude); $('#launch-alt').text(template['launch-site'].altitude); $('#ascent-rate').text(template['altitude-model']['ascent-rate']); $('#descent-rate').text(template['altitude-model']['descent-rate']); $('#burst-alt').text(template['altitude-model']['burst-altitude']); } ); } function generateLinks(uuid) { var html; html = 'log, '; html += 'output, '; html += 'KML output'; return html; } function refreshPredictionTable() { // Clear any existing pred_table. predictions_table.fnClearTable(); $.getJSON('list.cgi', null, function(data) { $.each(data, function() { predictions_table.fnAddData([ this.creation, this.creation ], false); }); predictions_table.fnDraw(); } ); } function POSIXtoDate(timestamp) { var d = new Date(); d.setTime(timestamp * 1000); return d.format('%d/%b/%Y %H:%M:%S') } $(document).ready(function() { init_map(); populate_map(); }); // vim:et:ts=8:sw=8:autoindent