From b580027223ca3a02815bb7ce1e4895d48c435e7e Mon Sep 17 00:00:00 2001 From: jonsowman Date: Tue, 8 Jun 2010 16:44:00 +0100 Subject: [PATCH] Loading launch sites from sites.json, and ajax getting site data only when required --- predict/index.php | 11 ++--------- predict/js/pred.js | 29 +++++++++++++++++++++++++++-- predict/sites.json | 27 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 predict/sites.json diff --git a/predict/index.php b/predict/index.php index 2b6459c..84f1f5e 100644 --- a/predict/index.php +++ b/predict/index.php @@ -50,6 +50,7 @@ function initialize() { } initMap(52, 0, 8); + populateLaunchSite(); setupEventHandlers(); // make launch card draggable $("#input_form").draggable({containment: '#map_canvas'}); @@ -134,15 +135,7 @@ No guarantee is given for the accuracy, precision or reliability of the data pro Launch Site: - diff --git a/predict/js/pred.js b/predict/js/pred.js index e42210b..af64eec 100644 --- a/predict/js/pred.js +++ b/predict/js/pred.js @@ -75,6 +75,29 @@ function showMousePos(GLatLng) { } +function populateLaunchSite() { + $.getJSON("sites.json", function(sites) { + $.each(sites, function(sitename, site) { + $("#site").append($('').val(sitename).html(sitename)); + }); + $("#site").append($('').val("Other").html("Other")); + }); +} + +function changeLaunchSite() { + var selectedName = $("#site").val(); + $.getJSON("sites.json", function(sites) { + $.each(sites, function(sitename, site) { + if ( selectedName == sitename ) { + $("#lat").val(site.latitude); + $("#lon").val(site.longitude); + $("#initial_alt").val(site.altitude); + } + }); + plotClick(); + }); +} + function throwError(data) { $("#error_message").html(data); $("#error_window").fadeIn(); @@ -530,6 +553,9 @@ function setupEventHandlers() { $("#delta_lon").change(function() { drawDeltaSquare(map); }); + $("#site").change(function() { + changeLaunchSite(); + }); google.maps.event.addListener(map, 'mousemove', function(event) { showMousePos(event.latLng); }); @@ -576,8 +602,7 @@ function UpdateLaunchSite(id) { } function SetSiteOther() { - optOther = document.getElementById("other"); - optOther.selected = true; + $("#site").val("Other"); } rad = function(x) {return x*Math.PI/180;} diff --git a/predict/sites.json b/predict/sites.json new file mode 100644 index 0000000..255918f --- /dev/null +++ b/predict/sites.json @@ -0,0 +1,27 @@ +{ + "Churchill": { + "latitude" : 52.2135, + "longitude" : 0.0964, + "altitude" : 0, + }, + "EARS": { + "latitude" : 52.2511, + "longitude" : -0.0927, + "altitude" : 0. + }, + "Glenrothes": { + "latitude" : 56.13, + "longitude" : -3.06, + "altitude" : 0, + }, + "Bujaraloz, Monegros": { + "latitude" : 41.4958, + "longitude" : -0.15797, + "altitude" : 0, + }, + "Adelaide": { + "altitude" : 0, + "latitude" : -34.9499, + "longitude" : 138.5194, + } +}