self.importScripts("satellite.js"); norad = "" groundStations = [] TLE = [] Orbits = [] onmessage = function(e) { norad = e.data[0] TLE = e.data[1] getStations() getOrbit() } 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 curLat = degress(positionGd.latitude) var curLng = degress(positionGd.longitude) if (groundStations[1] == undefined){ groundStations.push([]) } postMessage([norad,TLE[0],[curLat,curLng],groundStations[0],groundStations[1],Orbits]) }, 1000); 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; }; function getOrbit(){ var satrec = self.satellite_js.twoline2satrec(TLE[1],TLE[2]); gmst = self.satellite_js.gstime(new Date()); while(Orbits.length < 300){ gmst = gmst+0.00833333333 if (gmst > 6.28318530718){ return } positionAndVelocity = self.satellite_js.propagate(satrec, (new Date() / 1000/60)); positionEci = positionAndVelocity.position positionGd = self.satellite_js.eciToGeodetic(positionEci, gmst) Orbits.push([degress(positionGd.latitude),degress(positionGd.longitude)]) } }