Loading launch sites from sites.json, and ajax getting site data only when required
rodzic
2819cc3025
commit
b580027223
|
@ -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
|
|||
<tr>
|
||||
<td>Launch Site:</td>
|
||||
<td>
|
||||
<select id="site" name="launchsite" onchange="UpdateLaunchSite(this.selectedIndex)">
|
||||
<option value="Churchill">Churchill</option>
|
||||
<option value="EARS">EARS</option>
|
||||
<option value="Glenrothes">Glenrothes</option>
|
||||
<option value="Bujaraloz, Monegros">Bujaraloz, Monegros</option>
|
||||
<option value="Adelaide Airport">Adelaide Airport</option>
|
||||
<option id="other" value="other"<?php
|
||||
if ($current_uuid !=0) echo " selected=\"selected\"";
|
||||
?>>Other</option>
|
||||
<select id="site" name="launchsite">
|
||||
</select>
|
||||
</td>
|
||||
<tr>
|
||||
|
|
|
@ -75,6 +75,29 @@ function showMousePos(GLatLng) {
|
|||
|
||||
}
|
||||
|
||||
function populateLaunchSite() {
|
||||
$.getJSON("sites.json", function(sites) {
|
||||
$.each(sites, function(sitename, site) {
|
||||
$("#site").append($('<option></option>').val(sitename).html(sitename));
|
||||
});
|
||||
$("#site").append($('<option></option>').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;}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue