dump1090/public_html/planeObject.js
Brian Davenport 8b5c74ded8 Split into multiple JS files,
Selecting planes now works,
Started work on settings window,
Created extension.js, an area for new ideas to be tested or loaded out of.
2013-05-24 02:15:37 +00:00

223 lines
5.6 KiB
JavaScript

var planeObject = {
oldlat : null,
oldlon : null,
oldalt : null,
// Basic location information
altitude : null,
speed : null,
track : null,
latitude : null,
longitude : null,
// Info about the plane
flight : null,
squawk : null,
icao : null,
is_selected : false,
// Data packet numbers
messages : null,
seen : null,
// Vaild...
vPosition : false,
vTrack : false,
// GMap Details
marker : null,
markerColor : MarkerColor,
lines : [],
trackdata : new Array(),
trackline : new Array(),
// When was this last updated?
updated : null,
reapable : false,
// Appends data to the running track so we can get a visual tail on the plane
// Only useful for a long running browser session.
funcAddToTrack : function(){
// TODO: Write this function out
this.trackdata.push([this.latitude, this.longitude, this.altitude, this.track, this.speed]);
this.trackline.push(new google.maps.LatLng(this.latitude, this.longitude));
},
// This is to remove the line from the screen if we deselect the plane
funcClearLine : function() {
console.log("Clearing line for: " + this.icao);
if (this.line) {
this.line.setMap(null);
this.line = null;
}
},
// Should create an icon for us to use on the map...
funcGetIcon : function() {
// If this marker is selected we should make it lighter than the rest.
if (this.is_selected == true) {
this.markerColor = SelectedColor;
}
// If the squawk code is one of the international emergency codes,
// match the info window alert color.
if (this.squawk == 7500) {
this.markerColor = "rgb(255, 85, 85)";
}
if (this.squawk == 7600) {
this.markerColor = "rgb(0, 255, 255)";
}
if (this.squawk == 7700) {
this.markerColor = "rgb(255, 255, 0)";
}
// If we have not overwritten color by now, an extension still could but
// just keep on trucking. :)
return {
strokeWeight: (this.is_selected ? 2 : 1),
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 5,
fillColor: this.markerColor,
fillOpacity: 0.9,
rotation: this.track
};
},
// TODO: Trigger actions of a selecting a plane
funcSelectPlane : function(selectedPlane){
selectPlaneByHex(this.icao);
},
// Update our data
funcUpdateData : function(data){
// So we can find out if we moved
var oldlat = this.latitude;
var oldlon = this.longitude;
var oldalt = this.altitude;
// Update all of our data
this.updated = new Date().getTime();
this.altitude = data.altitude;
this.speed = data.speed;
this.track = data.track;
this.latitude = data.lat;
this.longitude = data.lon;
this.flight = data.flight;
this.squawk = data.squawk;
this.icao = data.hex;
this.messages = data.messages;
this.seen = data.seen;
// If no packet in over 58 seconds, consider the plane reapable
// This way we can hold it, but not show it just in case the plane comes back
if (this.seen > 58) {
this.reapable = true;
if (this.marker) {
this.marker.setMap(null);
this.marker = null;
}
if (this.line) {
this.line.setMap(null);
this.line = null;
}
if (SelectedPlane == this.icao) {
if (this.is_selected) {
this.is_selected = false;
}
SelectedPlane = null;
}
} else {
if (this.reapable == true) {
console.log(this.icao + ' has come back into range before the reaper!');
}
this.reapable = false;
}
// Is the position valid?
if ((data.validposition == 1) && (this.reapable == false)) {
this.vPosition = true;
// Detech if the plane has moved
changeLat = false;
changeLon = false;
changeAlt = false;
if (oldlat != this.latitude) {
changeLat = true;
}
if (oldlon != this.longitude) {
changeLon = true;
}
if (oldalt != this.altitude) {
changeAlt = true;
}
// Right now we only care about lat/long, if alt is updated only, oh well
if ((changeLat == true) || (changeLon == true)) {
this.funcAddToTrack();
if (this.is_selected) {
this.line = this.funcUpdateLines();
}
}
this.marker = this.funcUpdateMarker();
PlanesOnMap++;
} else {
this.vPosition = false;
}
// Do we have a valid track for the plane?
if (data.validtrack == 1)
this.vTrack = true;
else
this.vTrack = false;
},
// Update our marker on the map
funcUpdateMarker: function() {
if (this.marker) {
this.marker.setPosition(new google.maps.LatLng(this.latitude, this.longitude));
this.marker.setIcon(this.funcGetIcon());
} else {
this.marker = new google.maps.Marker({
position: new google.maps.LatLng(this.latitude, this.longitude),
map: GoogleMap,
icon: this.funcGetIcon(),
visable: true,
});
// This is so we can match icao address
this.marker.icao = this.icao;
// Trap clicks for this marker.
google.maps.event.addListener(this.marker, 'click', this.funcSelectPlane);
}
// Setting the marker title
if (this.flight.length == 0) {
this.marker.setTitle(this.hex);
} else {
this.marker.setTitle(this.flight+' ('+this.icao+')');
}
return this.marker;
},
// Update our planes tail line,
// TODO: Make this multi colored based on options
// altitude (default) or speed
funcUpdateLines: function() {
if (this.line) {
var path = this.line.getPath();
path.push(new google.maps.LatLng(this.latitude, this.longitude));
} else {
console.log("Starting new line");
this.line = new google.maps.Polyline({
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 3,
map: GoogleMap,
path: this.trackline,
});
}
return this.line;
},
};