48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
self.importScripts("satellite.js");
|
|
|
|
norad = ""
|
|
groundStations = []
|
|
TLE = []
|
|
|
|
onmessage = function(e) {
|
|
norad = e.data[0]
|
|
TLE = e.data[1]
|
|
getStations()
|
|
}
|
|
|
|
setInterval(function(){
|
|
getStations()
|
|
}, 20000);
|
|
|
|
setInterval(function(){
|
|
var satrec = self.satellite_js.twoline2satrec(TLE[1],TLE[2]);
|
|
var gmst = self.satellite_js.gstime(new Date());
|
|
var positionAndVelocity = self.satellite_js.propagate(satrec, new Date());
|
|
var positionEci = positionAndVelocity.position
|
|
var positionGd = self.satellite_js.eciToGeodetic(positionEci, gmst)
|
|
var longitude = positionGd.longitude
|
|
var latitude = positionGd.latitude
|
|
|
|
if (groundStations[1] == undefined){
|
|
groundStations.push([])
|
|
}
|
|
|
|
postMessage([norad,TLE[0],[degress(latitude),degress(longitude)],groundStations[0],groundStations[1]])
|
|
|
|
|
|
}, 500);
|
|
|
|
function getStations(){
|
|
var xhttp = new XMLHttpRequest();
|
|
xhttp.onreadystatechange = function() {
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
groundStations = JSON.parse(this.responseText);
|
|
}
|
|
};
|
|
xhttp.open("GET", "/stations_from_sat/"+norad, true);
|
|
xhttp.send();
|
|
}
|
|
|
|
function degress (radians) {
|
|
return radians * 180 / Math.PI;
|
|
}; |