1
0
Fork 0
satnogsmap/static/globe/Worker.js

73 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-01-24 09:14:23 -07:00
self.importScripts("satellite.js");
2019-02-15 09:08:35 -07:00
self.importScripts("moment.min.js");
self.importScripts("https://cesiumjs.org/releases/1.53/Build/Cesium/Cesium.js")
2019-01-24 09:14:23 -07:00
norad = ""
groundStations = []
2019-02-15 09:08:35 -07:00
satrec = null
2019-01-24 09:14:23 -07:00
Orbits = []
2019-02-15 09:08:35 -07:00
name = ""
2019-01-24 09:14:23 -07:00
onmessage = function(e) {
norad = e.data[0]
2019-02-15 09:08:35 -07:00
name = e.data[1][0]
satrec = self.satellite_js.twoline2satrec(e.data[1][1],e.data[1][2]);
2019-01-24 09:14:23 -07:00
getStations()
2019-02-15 09:08:35 -07:00
Orbits = getObrit()
2019-01-24 09:14:23 -07:00
}
setInterval(function(){
getStations()
2019-02-15 09:08:35 -07:00
}, 10000);
2019-01-24 09:14:23 -07:00
setInterval(function(){
2019-02-15 09:08:35 -07:00
getObrit()
}, 60000*5);
setInterval(function(){
2019-01-24 09:14:23 -07:00
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)
2019-02-15 09:08:35 -07:00
2019-01-24 09:14:23 -07:00
if (groundStations[1] == undefined){
groundStations.push([])
}
2019-02-15 09:08:35 -07:00
postMessage([norad,name,self.Cesium.Ellipsoid.WGS84.cartographicToCartesian(new self.Cesium.Cartographic(positionGd.longitude, positionGd.latitude, (positionGd.height*1000))),groundStations[0],groundStations[1],Orbits])
2019-01-24 09:14:23 -07:00
2019-02-15 09:08:35 -07:00
}, 10000);
2019-01-24 09:14:23 -07:00
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;
};
2019-02-15 09:08:35 -07:00
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
}