Skip to content

Commit 8ce0a3c

Browse files
authored
Merge pull request projecthorus#147 from projecthorus/testing
Switch to using API for launch sites
2 parents f55c6b2 + 3770120 commit 8ce0a3c

File tree

2 files changed

+91
-805
lines changed

2 files changed

+91
-805
lines changed

js/tracker.js

Lines changed: 91 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -831,96 +831,102 @@ function deletePredictions(marker) {
831831
function showLaunchSites() {
832832
if (!launches) {
833833
launches = new L.LayerGroup();
834-
$.getJSON("launchSites.json", function(json) {
835-
for (var key in json) {
836-
if (json.hasOwnProperty(key)) {
837-
var latlon = [json[key].lat, json[key].lon];
838-
var sondes = json[key].rs_types;
839-
var sondesList = "";
840-
for (var y = 0; y < sondes.length; y++) {
841-
if (Array.isArray(sondes[y]) == false) {
842-
sondes[y] = [sondes[y]];
843-
}
844-
if (sondeCodes.hasOwnProperty(sondes[y][0])) {
845-
sondesList += sondeCodes[sondes[y][0]]
846-
if (sondes[y].length > 1) {
847-
sondesList += " (" + sondes[y][1] + " MHz)";
834+
launches_url = "https://api.v2.sondehub.org/sites";
835+
$.ajax({
836+
type: "GET",
837+
url: launches_url,
838+
dataType: "json",
839+
success: function(json, textStatus) {
840+
for (var key in json) {
841+
if (json.hasOwnProperty(key)) {
842+
var latlon = [json[key].position[1], json[key].position[0]];
843+
var sondes = json[key].rs_types;
844+
var sondesList = "";
845+
for (var y = 0; y < sondes.length; y++) {
846+
if (Array.isArray(sondes[y]) == false) {
847+
sondes[y] = [sondes[y]];
848848
}
849-
} else if (unsupportedSondeCodes.hasOwnProperty(sondes[y][0])) {
850-
sondesList += unsupportedSondeCodes[sondes[y][0]];
851-
sondesList += " (cannot track)";
852-
} else {
853-
sondesList += sondes[y][0] + " (unknown WMO code)";
854-
}
855-
if (y < sondes.length-1) {
856-
sondesList += ", ";
857-
}
858-
}
859-
var marker = new L.circleMarker(latlon, {color: '#696969', fillColor: "white", radius: 8});
860-
var popup = new L.popup({ autoClose: false, closeOnClick: false });
861-
marker.bindPopup(popup);
862-
launches.addLayer(marker);
863-
if (json[key].hasOwnProperty('times')) {
864-
var popupContent = null;
865-
popupContent = "<font style='font-size: 13px'>" + json[key].station_name + "</font><br><br><b>Sondes launched:</b> " + sondesList;
866-
var ascent_rate = 5;
867-
var descent_rate = 6;
868-
var burst_altitude = 26000;
869-
var burst_samples = "";
870-
var descent_samples = "";
871-
if (json[key].rs_types.includes("11") || json[key].rs_types.includes("82")) { //LMS6
872-
ascent_rate = 5;
873-
descent_rate = 2.5;
874-
burst_altitude = 33500;
875-
}
876-
if (json[key].hasOwnProperty('ascent_rate')) {
877-
ascent_rate = json[key]["ascent_rate"];
878-
}
879-
if (json[key].hasOwnProperty('descent_rate')) {
880-
descent_rate = json[key]["descent_rate"];
881-
}
882-
if (json[key].hasOwnProperty('burst_altitude')) {
883-
burst_altitude = json[key]["burst_altitude"];
884-
}
885-
if (json[key].hasOwnProperty('burst_samples')) {
886-
burst_samples = json[key]["burst_samples"];
887-
}
888-
if (json[key].hasOwnProperty('descent_samples')) {
889-
descent_samples = json[key]["descent_samples"];
890-
}
891-
popupContent += "<br><b>Launch schedule:</b>";
892-
for (var x = 0; x < json[key]['times'].length; x++) {
893-
popupContent += "<br>- ";
894-
var day = json[key]['times'][x].split(":")[0];
895-
if (day == 0) {
896-
popupContent += "Everyday at ";
897-
} else if (day == 1) {
898-
popupContent += "Monday at ";
899-
} else if (day == 2) {
900-
popupContent += "Tuesday at ";
901-
} else if (day == 3) {
902-
popupContent += "Wednesday at ";
903-
} else if (day == 4) {
904-
popupContent += "Thursday at ";
905-
} else if (day == 5) {
906-
popupContent += "Friday at ";
907-
} else if (day == 6) {
908-
popupContent += "Saturday at ";
909-
} else if (day == 7) {
910-
popupContent += "Sunday at ";
849+
if (sondeCodes.hasOwnProperty(sondes[y][0])) {
850+
sondesList += sondeCodes[sondes[y][0]]
851+
if (sondes[y].length > 1) {
852+
sondesList += " (" + sondes[y][1] + " MHz)";
853+
}
854+
} else if (unsupportedSondeCodes.hasOwnProperty(sondes[y][0])) {
855+
sondesList += unsupportedSondeCodes[sondes[y][0]];
856+
sondesList += " (cannot track)";
857+
} else {
858+
sondesList += sondes[y][0] + " (unknown WMO code)";
859+
}
860+
if (y < sondes.length-1) {
861+
sondesList += ", ";
911862
}
912-
popupContent += json[key]['times'][x].split(":")[1] + ":" + json[key]['times'][x].split(":")[2] + " UTC";
913863
}
914-
if (json[key].hasOwnProperty('notes')) {
915-
popupContent += "<br><b>Notes:</b> " + json[key]["notes"];
864+
var marker = new L.circleMarker(latlon, {color: '#696969', fillColor: "white", radius: 8});
865+
var popup = new L.popup({ autoClose: false, closeOnClick: false });
866+
marker.bindPopup(popup);
867+
launches.addLayer(marker);
868+
if (json[key].hasOwnProperty('times')) {
869+
var popupContent = null;
870+
popupContent = "<font style='font-size: 13px'>" + json[key].station_name + "</font><br><br><b>Sondes launched:</b> " + sondesList;
871+
var ascent_rate = 5;
872+
var descent_rate = 6;
873+
var burst_altitude = 26000;
874+
var burst_samples = "";
875+
var descent_samples = "";
876+
if (json[key].rs_types.includes("11") || json[key].rs_types.includes("82")) { //LMS6
877+
ascent_rate = 5;
878+
descent_rate = 2.5;
879+
burst_altitude = 33500;
880+
}
881+
if (json[key].hasOwnProperty('ascent_rate')) {
882+
ascent_rate = json[key]["ascent_rate"];
883+
}
884+
if (json[key].hasOwnProperty('descent_rate')) {
885+
descent_rate = json[key]["descent_rate"];
886+
}
887+
if (json[key].hasOwnProperty('burst_altitude')) {
888+
burst_altitude = json[key]["burst_altitude"];
889+
}
890+
if (json[key].hasOwnProperty('burst_samples')) {
891+
burst_samples = json[key]["burst_samples"];
892+
}
893+
if (json[key].hasOwnProperty('descent_samples')) {
894+
descent_samples = json[key]["descent_samples"];
895+
}
896+
popupContent += "<br><b>Launch schedule:</b>";
897+
for (var x = 0; x < json[key]['times'].length; x++) {
898+
popupContent += "<br>- ";
899+
var day = json[key]['times'][x].split(":")[0];
900+
if (day == 0) {
901+
popupContent += "Everyday at ";
902+
} else if (day == 1) {
903+
popupContent += "Monday at ";
904+
} else if (day == 2) {
905+
popupContent += "Tuesday at ";
906+
} else if (day == 3) {
907+
popupContent += "Wednesday at ";
908+
} else if (day == 4) {
909+
popupContent += "Thursday at ";
910+
} else if (day == 5) {
911+
popupContent += "Friday at ";
912+
} else if (day == 6) {
913+
popupContent += "Saturday at ";
914+
} else if (day == 7) {
915+
popupContent += "Sunday at ";
916+
}
917+
popupContent += json[key]['times'][x].split(":")[1] + ":" + json[key]['times'][x].split(":")[2] + " UTC";
918+
}
919+
if (json[key].hasOwnProperty('notes')) {
920+
popupContent += "<br><b>Notes:</b> " + json[key]["notes"];
921+
}
922+
popupContent += "<br><b>Know when this site launches?</b> Contribute <a href='https://github.com/projecthorus/sondehub-tracker/issues/114' target='_blank'>here</a>";
923+
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>";
924+
} else {
925+
popupContent = "<font style='font-size: 13px'>" + json[key].station_name + "</font><br><br><b>Sondes launched:</b> " + sondesList;
926+
popupContent += "<br><b>Know when this site launches?</b> Contribute <a href='https://github.com/projecthorus/sondehub-tracker/issues/114' target='_blank'>here</a>";
916927
}
917-
popupContent += "<br><b>Know when this site launches?</b> Contribute <a href='https://github.com/projecthorus/sondehub-tracker/issues/114' target='_blank'>here</a>";
918-
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>";
919-
} else {
920-
popupContent = "<font style='font-size: 13px'>" + json[key].station_name + "</font><br><br><b>Sondes launched:</b> " + sondesList;
921-
popupContent += "<br><b>Know when this site launches?</b> Contribute <a href='https://github.com/projecthorus/sondehub-tracker/issues/114' target='_blank'>here</a>";
928+
popup.setContent(popupContent);
922929
}
923-
popup.setContent(popupContent);
924930
}
925931
}
926932
});

0 commit comments

Comments
 (0)