diff --git a/public_html/gmap.html b/public_html/gmap.html index 9d41c9f..07935c0 100644 --- a/public_html/gmap.html +++ b/public_html/gmap.html @@ -13,7 +13,10 @@
Click on a plane for info.
diff --git a/public_html/script.js b/public_html/script.js index cb04863..eab9f48 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -11,31 +11,54 @@ if (localStorage['CenterLat']) { CenterLat = Number(localStorage['CenterLat']); if (localStorage['CenterLon']) { CenterLon = Number(localStorage['CenterLon']); } if (localStorage['ZoomLvl']) { ZoomLvl = Number(localStorage['ZoomLvl']); } -function getIconForPlane(plane) { +function getIconForPlane(plane, deselect) { + var selected = false; + var track = 0; var r = 255, g = 255, b = 0; var maxalt = 40000; // Max altitude in the average case - var invalt = maxalt-plane.altitude; - var selected = (Selected == plane.hex); - + var invalt = 0; + + // If there is plane object + if (plane) { + invalt = maxalt-plane.altitude; + if (Selected == plane.hex && !deselect) { + selected = true; + } + track = plane.track; + } + if (invalt < 0) invalt = 0; b = parseInt(255/maxalt*invalt); + return { strokeWeight: (selected ? 2 : 1), path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW, scale: 5, fillColor: 'rgb('+r+','+g+','+b+')', fillOpacity: 0.9, - rotation: plane.track + rotation: track }; } +/* Gets hex code of selected plane as string or nothing. * + * Select not valid ICAO24 (hex) address to clear selection. */ function selectPlane(selectedPlane) { if (selectedPlane.length) this.planehex = selectedPlane; - if (!Planes[this.planehex]) return; + + // Deselect all planes + if (!Planes[this.planehex]) { + Planes[Selected].marker.setIcon(getIconForPlane(Planes[Selected], true)); + Selected = null; + refreshSelectedInfo(); + refreshTableInfo(); + return; + } + var old = Selected; Selected = this.planehex; + if (Planes[old]) { - /* Remove the highlight in the previously selected plane. */ + // Remove the highlight in the previously selected plane. Planes[old].marker.setIcon(getIconForPlane(Planes[old])); } Planes[Selected].marker.setIcon(getIconForPlane(Planes[Selected])); @@ -55,6 +78,7 @@ function refreshSelectedInfo() { var i = document.getElementById('selinfo'); var p = Planes[Selected]; + // If no plane is selected if (!p) { p = {}; p.flight = ""; @@ -82,30 +106,36 @@ function refreshSelectedInfo() { } function refreshTableInfo() { - var i = document.getElementById('tabinfo'); - var html = 'Flight | Squawk | Altitude | '; - html += 'Speed | Track | Seen | '; - html += 'Msgs | '; + html += 'hex | Flight | Squawk | Altitude | '; + html += 'Speed | Track | '; + html += 'Msgs | Seen | '; for (var p in Planes) { if (p == Selected) { - html += '
' + Planes[p].hex + ' | '; html += '' + Planes[p].flight + ' | '; html += '' + Planes[p].squawk + ' | '; html += '' + Planes[p].altitude + ' | '; html += '' + Planes[p].speed + ' | '; html += '' + Planes[p].track + ' | '; - html += '' + Planes[p].seen + ' | '; html += '' + Planes[p].messages + ' | '; + html += '' + Planes[p].seen + ' | '; html += '