1
0
Fork 0
satnogsmap/static/Worker.js

44 lines
1.1 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
postMessage([norad,TLE[0],[degress(latitude),degress(longitude)],groundStations])
}, 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;
};