/* ----------------------------------------------------------------------------
* Name: positionObject (obect)
* Creates a Vars object.
* Parameters:
* t: Time this position is valid for.
* p: GLatLng of new position.
* v: Variable data for satellite information.
* Returns: Pointer to itself
*/
function satPositionObject(t, p, v) {
this.time = t;
this.point = p;
this.vars = v;
return this;
} // satPositionObject
/* ----------------------------------------------------------------------------
* Name: Satellite (obect)
* Creates a Vars object.
* Parameters:
* nm: Satellite index number.
* n: Timestamp from server of satellites current position.
* m: Gmarker for satellite.
* nam: Satellite name for label.
* i: Image name of the marker icon.
* Returns: Pointer to itself
*/
function Satellite(nm, n, m, nam, i) {
this.timeIndex = n;
this.number = nm;
this.name = nam;
this.positionCount = 0;
this.marker = m;
this.label = undefined;
this.trackingLabel = undefined;
this.polylines = new Array();
this.positions = new Map();
this.circle = undefined;
this.compassLine = undefined;
this.isCompassLine = false;
this.isGroundCircle = false;
this.isTracking = false;
this.trailPoints = new Array();
this.trailPolylines = new Array();
this.trailSkipCount = 0;
this.trailPolylineCount = 0;
this.image = i;
return this;
} // Satellite
Satellite.prototype.enableCompassLine = function() {
this.isCompassLine = true;
} // Satellite::enableCompassLine
Satellite.prototype.disableCompassLine = function() {
if (this.compassLine != undefined) {
map.removeOverlay(this.compassLine);
this.compassLine = undefined;
} // if
this.isCompassLine = false;
} // Satellite::enableCompassLine
Satellite.prototype.enableGroundCircle = function() {
this.isGroundCircle = true;
} // Satellite::enableGroundcircle
Satellite.prototype.disableGroundCircle = function() {
if (this.circle != undefined) {
map.removeOverlay(this.circle);
this.circle = undefined;
} // if
this.isGroundCircle = false;
} // Satellite::disableGroundCircle
Satellite.prototype.enableTracking = function() {
this.enableGroundCircle();
this.enableCompassLine();
this.isTracking = true;
return;
} // Satellite::enableTracking
Satellite.prototype.disableTracking = function() {
this.disableGroundCircle();
this.disableCompassLine();
this.isTracking = false;
return;
} // Satellite::disableTracking
/* ----------------------------------------------------------------------------
* Name: syncIndex
* Updates the current reference time index for satellite.
* Parameters:
* t: Timestamp of new position.
* i: Image path of the image to set to.
* Returns: Updated time index.
*/
Satellite.prototype.syncIndex = function(t, i) {
this.timeIndex = t;
if (i != this.image) {
var img = "http://www.opensats.net/images/icons/satellite/small/" + i;
this.marker.setImage(img);
this.image = i;
log('Satellite: Image change for satellite number '+this.number+'.');
} // if
return t;
} // Satellite::syncIndex
/* ----------------------------------------------------------------------------
* Name: addPosition
* Adds a new future position to the map.
* Parameters:
* t: Timestamp of new position.
* p: GLatLng position point.
* v: Variable satellite data.
* Returns: True if add was succesful, false if key already existed.
*/
Satellite.prototype.addPosition = function(t, p, v) {
if (this.positions.isKey(t))
return false;
var np = new satPositionObject(t, p, v);
this.positions.add(t, np);
return true;
} // Satellite::addPosition
/* ----------------------------------------------------------------------------
* Name: removePastPositions
* Adds a new future position to the map.
* Parameters:
* t: Timestamp of new position.
* Returns: True if add was succesful, false if key already existed.
*/
Satellite.prototype.removePastPositions = function(t) {
var keys = this.positions.getKeys();
var num_rows = 0;
var keys = this.positions.getKeys();
for(var i=0; i < keys.length; i++) {
if (keys[i] < this.timeIndex) {
this.positions.remove(keys[i]);
num_rows++;
} // if
} // for
return num_rows;
} // Satellite::removePastPositions
/* ----------------------------------------------------------------------------
* Name: incrementPosition
* Moves satellite to next position.
* Parameters:
* none
* Returns: True if add was succesful, false if key already existed.
*/
Satellite.prototype.incrementPosition = function() {
this.timeIndex++;
this.positionCount++;
this.removePastPositions();
if (!this.positions.isKey(this.timeIndex)) {
// Show when clock is out of sync.
changeById('clock', this.timeIndex);
return false;
} // if
var p = this.positions.get(this.timeIndex);
this.changePosition(p);
this.plotTrail(p);
var lat = p.point.lat();
var lng = p.point.lng();
// Try and draw ground circle if possible.
if (p.vars.isName("rng")) {
var rng = parseFloat(p.vars.getField("rng"));
this.plotGroundCircle(lat, lng, (rng*1000/2));
} // if
return true;
} // Satellite::incrementPosition
/* ----------------------------------------------------------------------------
* Name: changePosition
* Changes a satellites actual position on Google Maps.
* Parameters:
* p: GLatLng point.
* Returns: True if add was succesful, false if key already existed.
*/
Satellite.prototype.changePosition = function(p) {
if (this.label != undefined)
map.removeOverlay(this.label);
// Create new label for satellite.
var label = new ELabel(p.point, this.name, "satLabelName", new GSize(-50, +20), 90);
this.marker.setLatLng(p.point);
this.label = label;
map.addOverlay(label);
// Recenter map to current satellite position if we're
// tracking it.
if (isChecked('OpenSATS:Form:Autocenter')
&& (this.timeIndex % 2) == 0
&& this.isTracking)
map.setCenter(p.point);
return true;
} // Satellite::changePosition
/* ----------------------------------------------------------------------------
* Name: changeTrackingLabel
* Changes a satellites actual position on Google Maps.
* Parameters:
* p: Point to change label for.
* Returns: True if add was succesful, false if key already existed.
*/
Satellite.prototype.changeTrackingLabel = function(p) {
if (!this.positions.isKey(this.timeIndex))
return false;
if (this.trackingLabel != undefined)
map.removeOverlay(this.trackingLabel);
if (!this.isTracking) {
this.trackingLabel = undefined;
return false;
} // if
var p2 = this.positions.get(this.timeIndex);
v = p2.vars;
if (!v.isName("alt"))
return false;
var lat1 = p.lat();
var lng1 = p.lng();
var lat2 = this.marker.getLatLng().lat();
var lng2 = this.marker.getLatLng().lng();
var alt = parseFloat(v.getField("alt"));
var bearing = Math.round(LatLon.bearing(lat1, lng1, lat2, lng2)*10)/10;
var out = "Az: " + bearing + "°"
var elevation = Math.round( toElevation2(lat1, lng1, 0, lat2, lng2)*10)/10;
var el = round(toElevation3(lat1, lng1, 0, lat2, lng2, alt), 1);
if (this.number == "-1" || this.number == "-2")
el = round(Elevation2(lng2, lat1, lng1, 0), 1);
out += " El: " + el + "°";
out += "
Alt: " + round(alt, 1) + "mi";
var label = new ELabel(new GLatLng(lat2, lng2), out,"satLabel",new GSize(-20,90), 60);
this.trackingLabel = label;
map.addOverlay(label);
var alt = parseFloat(v.getField("alt"));
var el = round(toElevation(lat1,lng1,lng2), 2);
var el2 = round(toElevation3(lat1,lng1, 0,lat2, lng2, alt), 2);
if (this.number == "-1" || this.number == "-2")
el2 = round(toElevation(lat1, lng1, lng2), 2);
var d = round(toDistance(lat1, lng1, lat2, lng2), 2);
var los = alt.toGroundRange();
var dte = new Date();
var day = dte.getUTCDate();
var mon = dte.getUTCMonth()+1;
var year = dte.getUTCFullYear();
var hour = dte.getUTCHours();
var min = dte.getUTCMinutes();
var second = dte.getUTCSeconds();
var day = day + ((hour/24+(min/1440)+(second/86400)));
//var daynum = JulianDayNumber(day, mon, year, hour, min, second);
var daynum2 = calcJulianDayNumber(day, mon, year);
//var daynum = dte.julianDate();
//var today = new Date();
//var daynum = Math.floor((today.valueOf() / (1000 * 60 * 60 * 24)) - 0.5) + 2440588;
var daynum = Cal2JD(year, mon, dte.getUTCDate(), hour, min, second);
// Change side info stuff
var info = "" + this.name + "
"
+ '