73 lines
2.2 KiB
JavaScript
73 lines
2.2 KiB
JavaScript
|
self.importScripts("satellite.js");
|
||
|
self.importScripts("moment.min.js");
|
||
|
self.importScripts("https://cesiumjs.org/releases/1.53/Build/Cesium/Cesium.js")
|
||
|
|
||
|
norad = ""
|
||
|
groundStations = []
|
||
|
satrec = null
|
||
|
Orbits = []
|
||
|
name = ""
|
||
|
|
||
|
onmessage = function(e) {
|
||
|
norad = e.data[0]
|
||
|
name = e.data[1][0]
|
||
|
satrec = self.satellite_js.twoline2satrec(e.data[1][1],e.data[1][2]);
|
||
|
getStations()
|
||
|
Orbits = getObrit()
|
||
|
}
|
||
|
|
||
|
setInterval(function(){
|
||
|
getStations()
|
||
|
}, 10000);
|
||
|
|
||
|
setInterval(function(){
|
||
|
getObrit()
|
||
|
}, 60000*5);
|
||
|
|
||
|
setInterval(function(){
|
||
|
|
||
|
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)
|
||
|
|
||
|
if (groundStations[1] == undefined){
|
||
|
groundStations.push([])
|
||
|
}
|
||
|
|
||
|
postMessage([norad,name,self.Cesium.Ellipsoid.WGS84.cartographicToCartesian(new self.Cesium.Cartographic(positionGd.longitude, positionGd.latitude, (positionGd.height*1000))),groundStations[0],groundStations[1],Orbits])
|
||
|
|
||
|
|
||
|
}, 10000);
|
||
|
|
||
|
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 getObrit(){
|
||
|
|
||
|
satelliteOrbit = []
|
||
|
for (var i = 0; i < 30; i++){
|
||
|
time = moment().subtract(10,"m").add(i*1,"m")
|
||
|
var gmst = self.satellite_js.gstime(new Date(time.valueOf()));
|
||
|
var positionAndVelocity = self.satellite_js.propagate(satrec, new Date(time.valueOf()));
|
||
|
var positionEci = positionAndVelocity.position
|
||
|
var positionGd = self.satellite_js.eciToGeodetic(positionEci, gmst)
|
||
|
|
||
|
satelliteOrbit = satelliteOrbit.concat(self.Cesium.Ellipsoid.WGS84.cartographicToCartesian(new self.Cesium.Cartographic(positionGd.longitude, positionGd.latitude, positionGd.height*1000)));
|
||
|
}
|
||
|
return satelliteOrbit
|
||
|
|
||
|
}
|