/** * This javascript is part of FlightAirmap. * * Copyright (c) Ycarus (Yannick Chabanois) * Licensed under AGPL license. * For more information see: https://www.flightairmap.com/ */ "use strict"; var globaldebug = true; var user = new L.FeatureGroup(); var geojsonLayer; var atcLayer; var polarLayer; var notamLayer; var airspaceLayer; //var archiveplayback; waypoints = ''; //initialize the layer group for the aircrft markers var layer_data = L.layerGroup(); // Show airports on map function airportPopup (feature, layer) { var output = ''; output += '
'; output += '
'; if (typeof feature.properties.image_thumb != 'undefined' && feature.properties.image_thumb != '') { output += ''; } output += '
'; output += '
'; output += '
'; output += '
'+feature.properties.name+'
'; output += '
'; output += '
'; output += '
'; output += ''+feature.properties.icao+''; output += '
'; output += '
'; output += '
'; output += '
'; output += '
'; output += '
'; output += 'City'; output += feature.properties.city; output += '
'; if (feature.properties.altitude != "" || feature.properties.altitude != 0) { output += '
'; output += 'Altitude'; output += Math.round(feature.properties.altitude*3,2809)+' feet - '+feature.properties.altitude+' m'; output += '
'; } output += '
'; output += 'Country'; output += feature.properties.country; output += '
'; if (feature.properties.homepage != "") { output += '
'; output += 'Links'; output += 'Homepage'; output += '
'; } output += '
'; output += ''; layer.bindPopup(output); }; function update_airportsLayer() { if (typeof airportsLayer != 'undefined') { if (map.hasLayer(airportsLayer) == true) { map.removeLayer(airportsLayer); } } if (map.getZoom() > 7) { var bbox = map.getBounds().toBBoxString(); var airportsLayerQuery = $.getJSON("/airport-geojson.php?coord="+bbox,function(data) { airportsLayer = L.geoJson(data,{ pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: feature.properties.icon, iconSize: [16, 18] //popupAnchor: [0, -28] }) }).on('click', function() { $("#pointident").attr('class',''); $(".showdetails").load("airport-data.php?"+Math.random()+"&airport_icao="+feature.properties.icao); }); } }).addTo(map); }); } }; $( document ).ready(function() { var zoom = map.getZoom(); if (map.getZoom() > 7) { if (getCookie("airspace") == 'true') { update_airspaceLayer(); } if (getCookie("waypoints") == 'true') { update_waypointsLayer(); } if (getCookie("notam") == 'true') { update_notamLayer(); } } map.on('moveend', function() { if (map.getZoom() > 7) { if (getCookie("displayairports") == 'true') update_airportsLayer(); if (getCookie("airspace") == 'true') { if (typeof airspaceLayer != 'undefined') map.removeLayer(airspaceLayer); update_airspaceLayer(); } if (getCookie("waypoints") == 'true') { if (typeof waypointsLayer != 'undefined') map.removeLayer(waypointsLayer); update_waypointsLayer(); } } else { if (getCookie("displayairports") == 'true') update_airportsLayer(); if (getCookie("airspace") == 'true') { if (typeof airspaceLayer != 'undefined') map.removeLayer(airspaceLayer); } if (getCookie("waypoints") == 'true') { if (typeof waypointsLayer != 'undefined') map.removeLayer(waypointsLayer); } } if (getCookie("notam") == 'true') { if (typeof notamLayer != 'undefined') map.removeLayer(notamLayer); update_notamLayer(); } }); map.on('zoomend', function() { if (archive === false) { if ((map.getZoom() > 7 && zoom < 7) || (map.getZoom() < 7 && zoom > 7)) { zoom = map.getZoom(); getLiveData(1); } } }); //update_waypointsLayer(); if (getCookie("displayairports") == 'true') update_airportsLayer(); if (archive === true) { function archive_update (props) { document.getElementById('archivebox').style.display = "block"; if (typeof props != 'undefined') { var thedate = new Date(props); $("#thedate").html(thedate.toUTCString()); // $("#archivebox").html('

Archive Date & Time

' + ''); } } } $(".showdetails").on("click",".close",function(){ $(".showdetails").empty(); $("#pointident").attr('class',''); if (archive === false) { getLiveData(1); } return false; }); $("#pointident").attr('class',''); var MapTrack = getCookie('MapTrack'); if (MapTrack != '') { $("#pointident").attr('class',MapTrack); $("#pointtype").attr('class','aircraft'); $(".showdetails").load("/aircraft-data.php?"+Math.random()+"&flightaware_id="+MapTrack); delCookie('MapTrack'); } function getLiveData(click) { var bbox = map.getBounds().toBBoxString(); //var layer_data_p = L.layerGroup(); var now = new Date(); var defurl = "/live/geojson?"+Math.random()+"&flightaware_id=151ED4-202407041942&history"; $.ajax({ dataType: "json", // url: "live/geojson?"+Math.random(), url: defurl, success: function(data) { map.removeLayer(layer_data); if (document.getElementById('pointident') && document.getElementById('pointident').className != "") { $(".showdetails").load("/aircraft-data.php?"+Math.random()+"&flightaware_id="+document.getElementById('pointident').className); } layer_data = L.layerGroup(); var nbaircraft = 0; var flightcount = 0; var datatable = ''; var live_data = L.geoJson(data, { pointToLayer: function (feature, latLng) { var markerLabel = ""; var callsign = feature.properties.c; var departure_airport_code = feature.properties.dac; var arrival_airport_code = feature.properties.aac; var flightaware_id = feature.properties.fi; var aircraft_shadow = feature.properties.as; var squawk = feature.properties.sq; var altitude = feature.properties.a; var heading = feature.properties.h; var type = feature.properties.t; flightcount = feature.properties.fc; if (typeof feature.properties.empty != 'undefined') { return; } if (type != "history") nbaircraft = nbaircraft+1; if (callsign != ""){ markerLabel += callsign; } if (departure_airport_code != "" && arrival_airport_code != "" && departure_airport_code != "NA" && arrival_airport_code != "NA"){ markerLabel += ' ( '+departure_airport_code+' - '+arrival_airport_code+' )'; } var iconURLpath = '/getImages.php?color=1a3151&filename='+aircraft_shadow; var iconURLShadowpath = '/getImages.php?color=8D93B9&filename='+aircraft_shadow; if (map.getZoom() > 7) { return new L.Marker(latLng, { rotationAngle: heading, autostart: true, iconAngle: heading, title: markerLabel, alt: callsign, icon: L.icon({ iconUrl: iconURLpath, iconSize: [30, 30], iconAnchor: [15, 30] /* shadowUrl: iconURLShadowpath, shadowSize: [30,30], shadowAnchor: [16,30] */ }) }) .on('click', function() { $("#pointident").attr('class',flightaware_id); $("#pointtype").attr('class','aircraft'); $(".showdetails").load("/aircraft-data.php?"+Math.random()+"&flightaware_id="+flightaware_id); getLiveData(1); }); } else { return new L.Marker(latLng, { rotationAngle: heading, autostart: true, iconAngle: heading, title: markerLabel, alt: callsign, icon: L.icon({ iconUrl: iconURLpath, iconSize: [15, 15], iconAnchor: [7, 15] /* shadowUrl: iconURLShadowpath, shadowSize: [15,15], shadowAnchor: [8,15] */ }) }) .on('click', function() { $("#pointident").attr('class',flightaware_id); $("#pointtype").attr('class','aircraft'); $(".showdetails").load("/aircraft-data.php?"+Math.random()+"&flightaware_id="+flightaware_id); getLiveData(1); }); } }, onEachFeature: function (feature, layer) { var id = feature.properties.fi; var altitude = feature.properties.a; var type = feature.properties.t; var callsign = feature.properties.c; var dairport = feature.properties.dac; var aairport = feature.properties.aac; var squawk = feature.properties.sq; var coord = feature.geometry.coordinates; var lastupdate = feature.properties.lu; var aircraft_icao = feature.properties.ai; var registration = feature.properties.reg; if (type == 'aircraft') { if (unitaltitudevalue == 'm') { var txtaltitude = Math.round(altitude*30.48)+' m (FL'+Math.round(altitude)+')'; } else { var txtaltitude = altitude+' feet (FL'+Math.round(altitude)+')'; } if (unitcoordinatevalue == 'dms') { var latitude = convertDMS(coord[1],'latitude'); var longitude = convertDMS(coord[0],'longitude'); } else if (unitcoordinatevalue == 'dm') { var latitude = convertDM(coord[1],'latitude'); var longitude = convertDM(coord[0],'longitude'); } else { var latitude = coord[1]; var longitude = coord[0]; } if (typeof squawk == 'undefined') squawk = 'NA'; var lastupdatedate = new moment.tz(lastupdate*1000,moment.tz.guess()).format("HH:mm:ss"); datatable += ''+callsign+''+registration+''+aircraft_icao+''+txtaltitude+''+dairport+''+aairport+''+squawk+''+latitude+''+longitude+''+lastupdatedate+''; } var output = ''; //individual aircraft if (feature.minimal == "false" && type == "aircraft"){ output += '
'; if (typeof feature.properties.image_source_website != 'undefined') { if (typeof feature.properties.image_copyright != 'undefined') { output += '
'+feature.properties.registration+' '+feature.properties.aircraft_name+'Image © '+ feature.properties.image_copyright+'
'; } else { output += '
'+feature.properties.registration+' '+feature.properties.aircraft_name+'
'; } } else { if (typeof feature.properties.image_copyright != 'undefined') { output += '
'+feature.properties.registration+' '+feature.properties.aircraft_name+'Image © '+ feature.properties.image_copyright+'
'; } else { output += '
'+feature.properties.registration+' '+feature.properties.aircraft_name+'
'; } } output += '
'; output += '
'; output += ''; output += '
'+feature.properties.airline_name+'
'; output += '
'; output += '
'; output += '
'; output += ''+feature.properties.departure_airport_code+''+feature.properties.departure_airport; if (typeof feature.properties.departure_airport_time != 'undefined') { output += '
'+feature.properties.departure_airport_time+''; } output += '
'; output += ''; output += '
'; output += ''+feature.properties.arrival_airport_code+''+feature.properties.arrival_airport; if (typeof feature.properties.arrival_airport_time != 'undefined') { output += '
'+feature.properties.arrival_airport_time+''; } output += '
'; output += '
'; if (typeof feature.properties.route_stop != 'undefined') { output += 'Route stop: '+feature.properties.route_stop; } output += '
'; output += '
'; output += '
'; output += '
'; output += '
'; output += ''+feature.properties.departure_airport_code+''+feature.properties.departure_airport; output += '
'; output += ''; output += '
'; output += ''+feature.properties.arrival_airport_code+''+feature.properties.arrival_airport; output += '
'; output += '
'; output += '
'; output += 'Aircraft'; if (feature.properties.aircraft_wiki != 'undefined') { output += ''; output += feature.properties.aircraft_name; output += ''; } else { output += feature.properties.aircraft_name; } output += '
'; if (feature.properties.altitude != "" || feature.properties.altitude != 0) { output += '
'; output += 'Altitude'; output += feature.properties.altitude+'00 feet - '+Math.round(feature.properties.altitude*30.48)+' m (FL'+feature.properties.altitude+')'; output += '
'; } if (feature.properties.registration != "") { output += '
'; output += 'Registration'; output += ''+feature.properties.registration+''; output += '
'; } output += '
'; output += 'Speed'; output += feature.properties.ground_speed+' knots - '+Math.round(feature.properties.ground_speed*1.852)+' km/h'; output += '
'; output += '
'; output += 'Coordinates'; output += feature.properties.latitude+", "+feature.properties.longitude; output += '
'; output += '
'; output += 'Heading'; output += feature.properties.heading; output += '
'; if (typeof feature.properties.pilot_name != 'undefined') { output += '
'; output += 'Pilot'; if (typeof feature.properties.pilot_id != 'undefined') { output += feature.properties.pilot_name+" ("+feature.properties.pilot_id+")"; } else { output += feature.properties.pilot_name; } output += '
'; } output += '
'; if (typeof feature.properties.waypoints != 'undefined') { output += '
Route'; output += feature.properties.waypoints; output += '
'; } if (typeof feature.properties.acars != 'undefined') { output += '
Latest ACARS message'; output += feature.properties.acars; output += '
'; } if (typeof feature.properties.squawk != 'undefined') { output += '
'; output += 'Squawk: '; output += feature.properties.squawk; if (typeof feature.properties.squawk_usage != 'undefined') { output += ' - '+feature.properties.squawk_usage; } output += '
'; } output += ''; layer_data.addLayer(layer); } else { layer_data.addLayer(layer); } if (type == "route"){ var style = { "color": "#c74343", "weight": 2, "opacity": 0.5 }; layer.setStyle(style); layer_data.addLayer(layer); } if (type == "routedest"){ var styled = { "color": "#945add", "weight": 2, "opacity": 1.0, "dashArray": "6" }; layer.setStyle(styled); layer_data.addLayer(layer); } //aircraft history position as a line if (type == "history"){ if (map.getZoom() > 7) { var style = { "color": getAltitudeColor(altitude), "weight": 3, "opacity": 0.6 }; layer.setStyle(style); layer_data.addLayer(layer); } else { var style = { "color": getAltitudeColor(altitude), "weight": 2, "opacity": 0.6 }; layer.setStyle(style); layer_data.addLayer(layer); } } } }); if (datatable != '') { $('#datatable').css('height','20em'); $('#datatable').html('
'+datatable+'
CallsignRegistrationAircraft ICAOAltitudeDeparture airportArrival airportSquawkLatitudeLongitudeLast update
'); $(".table-row").click(function () { $("#pointident").attr('class',$(this).data('id')); $("#pointtype").attr('class','aircraft'); $(".showdetails").load("/aircraft-data.php?"+Math.random()+"&flightaware_id="+$(this).data('id')); getLiveData(1); map.panTo([$(this).data('latitude'),$(this).data('longitude')]); }); } layer_data.addTo(map); //re-create the bootstrap tooltips on the marker //showBootstrapTooltip(); if (typeof info_update != "undefined") { if (typeof flightcount != "undefined" && flightcount != 0) { if (flightcount != nbaircraft) { info_update(nbaircraft+'/'+flightcount); } else { info_update(nbaircraft); } } else { info_update(nbaircraft); } } } }); // getLiveData(0); } function update_archiveLayer(click) { $("#infobox").html('Loading archive '); var bbox = map.getBounds().toBBoxString(); var begindate = parseInt(getCookie("archive_begin")); var enddate = parseInt(getCookie("archive_end")); //var finaldate = parseInt(getCookie("archive_end"))*1000; //var enddate = begindate+parseInt(getCookie("archive_update")); //var enddate = begindate+3600; var finaldate = enddate*1000; //console.log(finaldate); /* if (enddate > getCookie("archive_end")) { enddate = parseInt(getCookie("archive_end")); //clearInterval(reloadPage); } else { if (click != 1) { document.cookie = 'archive_begin='+enddate+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'; } } */ var archivespeed = parseInt(getCookie("archive_speed")); var lasticon; var playbackOptions = { orientIcons: true, clickCallback: function(event) { var flightaware_id = event.target.feature.properties.fi; var currentdate = (begindate + event.originalEvent.timeStamp)*1000; $("#pointident").attr('class',flightaware_id); $("#pointtype").attr('class','aircraft'); $(".showdetails").load("/aircraft-data.php?"+Math.random()+"&flightaware_id="+flightaware_id+"¤ttime="+currentdate); var aircraft_shadow = event.target.feature.properties.as; if (typeof lasticon != 'undefined') { lasticon.target._icon.src = '/getImages.php?color=1a3151&filename='+lasticon.target.feature.properties.as; } lasticon = event; event.target._icon.src = '/getImages.php?color=FF0000&filename='+aircraft_shadow; /* archiveplayback._tracksLayer.addLayer(event.target.feature); console.log(event); console.log(archiveplayback); */ }, marker: function(feature){ var aircraft_shadow = feature.properties.as; var iconURLpath = '/getImages.php?color=1a3151&filename='+aircraft_shadow; return { icon: L.icon({ iconUrl: iconURLpath, iconSize: [30, 30], iconAnchor: [15, 30] }) } }, layer: { onEachFeature : function (feature, layer) { var style = { "color": "#1a3151", "weight": 2, "opacity": 1 }; layer.setStyle(style); } }, fadeMarkersWhenStale: true, finalTime: finaldate, staleTime: 60, speed: archivespeed, orientIcons: true, maxInterpolationTime: 30*60*1000, tracksLayer: false, playControl: false, layerControl: false, sliderControl: false }; var alldata = []; var part = 0; //do { //part += 1; //console.log('part: '+part); var url = "/archive-geojson.php?"+Math.random()+"&coord="+bbox+"&history="+document.getElementById('pointident').className+"&archive&begindate="+begindate+"&enddate="+enddate+"&speed="+archivespeed+"&part="+part; var archivegeoJSONQuery = $.getJSON(url, function(data) { alldata = []; var archiveLayerGroup = L.layerGroup(); var archivegeoJSON = L.geoJson(data, { onEachFeature: function(feature,layer) { alldata.push(feature); } }); if (typeof archiveplayback == 'undefined') { $("#infobox").remove(); document.getElementById('archivebox').style.display = "block"; $("#archivebox").html('

Archive

' + '' + '

'+getCookie('archive_speed')+'
'); archiveplayback = new L.Playback(map,alldata,archive_update,playbackOptions); archiveplayback.setCursor(begindate*1000); archiveplayback.start(); } else { archiveplayback.addData(alldata); } }).fail(function(jqxhr, textStatus, error) { if (globaldebug) { var err = textStatus + ", " + error; console.log("Can't load archive json: "+err+"\nURL: "+url); msgbox("Can't load archive json: "+err+'
URL: '+location.href.substring(0, location.href.lastIndexOf('/'))+url+''); } }); //} while (alldata.length > 0); }; if (archive === false) { //load the function on startup getLiveData(0); } if (archive === true) { console.log('Load Archive geoJson'); var archiveupdatetime = parseInt(getCookie('archive_update')); //reloadPage = setInterval(function(){if (noTimeout) update_archiveLayer(0)},archiveupdatetime*1000); update_archiveLayer(0); } else { //then load it again every 30 seconds var reloadPage = setInterval(function(){if (noTimeout) getLiveData(0)},30000); } //adds the bootstrap hover to the map buttons $('.button').tooltip({ placement: 'right' }); }); function atcPopup (feature, layer) { var output = ''; output += '
'; output += '
'+feature.properties.ident+'
'; output += ' '+feature.properties.info+'
'; output += '
'; layer.bindPopup(output); }; function update_atcLayer() { var bbox = map.getBounds().toBBoxString(); var atcLayerQuery = $.getJSON("/atc-geojson.php?coord="+bbox,function(data) { atcLayer = L.geoJson(data, { onEachFeature: atcPopup, pointToLayer: function (feature, latlng) { if (feature.properties.atc_range > 0) { var atccolor = feature.properties.atccolor; return L.circle(latlng, feature.properties.atc_range*1, { fillColor: atccolor, color: atccolor, weight: 1, opacity: 0.3, fillOpacity: 0.3 }); } else { if (feature.properties.type == 'Delivery') { return L.marker(latlng, { icon: L.icon({ iconUrl: '/images/atc_del.png', iconSize: [15, 15], iconAnchor: [7, 7] }) }); } else if (feature.properties.type == 'Ground') { return L.marker(latlng, { icon: L.icon({ iconUrl: '/images/atc_gnd.png', iconSize: [20, 20], iconAnchor: [10, 10] }) }); } else if (feature.properties.type == 'Tower') { return L.marker(latlng, { icon: L.icon({ iconUrl: '/images/atc_twr.png', iconSize: [25, 25], iconAnchor: [12, 12] }) }); } else if (feature.properties.type == 'Approach') { return L.marker(latlng, { icon: L.icon({ iconUrl: '/images/atc_app.png', iconSize: [30, 30], iconAnchor: [15, 15] }) }); } else if (feature.properties.type == 'Departure') { return L.marker(latlng, { icon: L.icon({ iconUrl: '/images/atc_dep.png', iconSize: [35, 35], iconAnchor: [17, 17] }) }); } else if (feature.properties.type == 'Control Radar or Centre') { return L.marker(latlng, { icon: L.icon({ iconUrl: '/images/atc_ctr.png', iconSize: [40, 40], iconAnchor: [20, 20] }) }); } else { return L.marker(latlng, { icon: L.icon({ iconUrl: '/images/atc.png', iconSize: [30, 30], iconAnchor: [15, 30] }) }); } } } }).addTo(map); }); }; function update_polarLayer() { var polarLayerQuery = $.getJSON("/polar-geojson.php", function(data){ polarLayer = L.geoJson(data, { style: function(feature) { return feature.properties.style } }).addTo(map); }); }; function showNotam(cb) { createCookie('notam',cb.checked,9999); if (cb.checked == true) { update_notamLayer(); } else { if (typeof notamLayer != 'undefined') map.removeLayer(notamLayer); } } function notamscope(selectObj) { var idx = selectObj.selectedIndex; var scope = selectObj.options[idx].value; createCookie('notamscope',scope,9999); if (getCookie("notam") == 'true') { if (typeof notamLayer != 'undefined') map.removeLayer(notamLayer); update_notamLayer(); } } function iconColor(color) { createCookie('IconColor',color.substring(1),9999); window.location.reload(); } function iconColorAltitude(val) { createCookie('IconColorAltitude',val.checked,9999); window.location.reload(); } function airportDisplayZoom(zoom) { createCookie('AirportZoom',zoom,9999); window.location.reload(); } function clickFlightPopup(cb) { createCookie('flightpopup',cb.checked,9999); window.location.reload(); } function clickFlightPath(cb) { createCookie('flightpath',cb.checked,9999); window.location.reload(); } function clickFlightRoute(cb) { createCookie('MapRoute',cb.checked,9999); window.location.reload(); } function clickFlightRemainingRoute(cb) { createCookie('MapRemainingRoute',cb.checked,9999); window.location.reload(); } function clickFlightEstimation(cb) { createCookie('flightestimation',cb.checked,9999); window.location.reload(); } function notamPopup (feature, layer) { var output = ''; output += '
'; output += ' '+feature.properties.ref+' '+feature.properties.title+'
'; output += ' '+feature.properties.text+'
'; output += ' '+feature.properties.latitude+'/'+feature.properties.longitude+' '+feature.properties.radiusnm+'NM/'+feature.properties.radiusm+'m
'; output += '
'; layer.bindPopup(output); }; function update_notamLayer() { var bbox = map.getBounds().toBBoxString(); if (getCookie('notamscope') == '' || getCookie('notamscope') == 'All') { url = "/notam-geojson.php?coord="+bbox; } else { url = "/notam-geojson.php?coord="+bbox+"&scope="+getCookie("notamscope"); } //notamLayer = new L.GeoJSON.AJAX("/notam-geojson.php?coord="+bbox,{ var notamLayerQuery = $.getJSON(url,function(data) { notamLayer = L.geoJson(data, { // onEachFeature: notamPopup, pointToLayer: function (feature, latlng) { var circle = L.circle(latlng, feature.properties.radius, { fillColor: feature.properties.color, color: feature.properties.color, weight: 1, opacity: 0.3, fillOpacity: 0.3 }).on('click', function() { $("#pointident").attr('class',''); $(".showdetails").load("notam-data.php?"+Math.random()+"¬am="+encodeURI(feature.properties.ref)); }); return circle; } }).addTo(map); }); }; function update_waypointsLayer() { var bbox = map.getBounds().toBBoxString(); var lineStyle = { "color": "#ff7800", "weight": 1, "opacity": 0.65 }; var waypointsLayerQuery = $.getJSON("/waypoints-geojson.php?coord="+bbox,function(data) { waypointsLayer = L.geoJson(data, { onEachFeature: waypointsPopup, pointToLayer: function (feature, latlng) { return L.marker(latlng, { icon: L.icon({ iconUrl: feature.properties.icon, iconSize: [12, 13], iconAnchor: [2, 13] //popupAnchor: [0, -28] }) }); }, style: lineStyle }).addTo(map); }); }; function showWaypoints(cb) { createCookie('waypoints',cb.checked,9999); if (cb.checked == true) { update_waypointsLayer(); } else { if (typeof waypointsLayer != 'undefined') map.removeLayer(waypointsLayer); } } function waypointsPopup (feature, layer) { var output = ''; output += '
'; if (typeof feature.properties.segment_name != 'undefined') { output += ' Segment name: '+feature.properties.segment_name+'
'; output += ' From: '+feature.properties.name_begin+' To : '+feature.properties.name_end+'
'; } if (typeof feature.properties.ident != 'undefined') { output += ' Ident: '+feature.properties.ident+'
'; } if (typeof feature.properties.alt != 'undefined') { output += ' Altitude: '+feature.properties.alt*100+' feet - '; output += Math.round(feature.properties.alt*30,48)+' m (FL'+feature.properties.alt+')
'; } if (typeof feature.properties.base != 'undefined') { output += ' Base Altitude: '+feature.properties.base*100+' feet - '; output += Math.round(feature.properties.base*30,48)+' m (FL'+feature.properties.base+')
'; output += ' Top Altitude: '+feature.properties.top*100+' feet - '; output += Math.round(feature.properties.top*30,48)+' m (FL'+feature.properties.top+')
'; } // output += ' Control : '+feature.properties.control+'
 Usage : '+feature.properties.usage; output += '
'; layer.bindPopup(output); }; function showAirspace(cb) { createCoookie('airspace',cb.checked,9999); if (cb.checked == true) { update_airspaceLayer(); } else { if (typeof airspaceLayer != 'undefined') map.removeLayer(airspaceLayer); } } function airspacePopup (feature, layer) { var output = ''; output += '
'; if (typeof feature.properties.title != 'undefined') { output += ' Title: '+feature.properties.title+'
'; } if (typeof feature.properties.type != 'undefined') { output += ' Type: '+feature.properties.type+'
'; } if (typeof feature.properties.tops != 'undefined') { output += ' Tops: '+feature.properties.tops+'
'; } if (typeof feature.properties.base != 'undefined') { output += ' Base: '+feature.properties.base+'
'; } output += '
'; layer.bindPopup(output); }; function update_airspaceLayer() { var bbox = map.getBounds().toBBoxString(); var airspaceLayerQuery = $.getJSON("/airspace-geojson.php?coord="+bbox,function(data) { airspaceLayer = L.geoJson(data,{ onEachFeature: airspacePopup, pointToLayer: function (feature, latlng) { }, style: function(feature) { return { "color": feature.properties.color, "weight": 1, "opacity": 0.2 }; /* if (feature.properties.type == 'RESTRICTED') { return { "color": '#cf2626', "weight": 1, "opacity": 0.2 }; } else if (feature.properties.type == 'CLASS D') { return { "color": '#1a74b3', "weight": 1, "opacity": 0.2 }; } else if (feature.properties.type == 'CLASS B') { return { "color": '#1a74b3', "weight": 1, "opacity": 0.2 }; } else if (feature.properties.type == 'GSEC') { return { "color": '#1b5acf', "weight": 1, "opacity": 0.2 }; } else if (feature.properties.type == 'CLASS C') { return { "color": '#9b6c9d', "weight": 1, "opacity": 0.3 }; } else if (feature.properties.type == 'PROHIBITED') { return { "color": '#1b5acf', "weight": 1, "opacity": 0.2 }; } else if (feature.properties.type == 'DANGER') { return { "color": '#781212', "weight": 1, "opacity": 0.55 }; } else if (feature.properties.type == 'OTHER' || feature.properties.type == 'CLASS A') { return { "color": '#ffffff', "weight": 1, "opacity": 0.55 }; } else { return { "color": '#afffff', "weight": 1, "opacity": 0.55 }; } */ } }).addTo(map); }); }; function getAltitudeColor(x) { return x < 10 ? '#ea0000': x < 30 ? '#ea3a00': x < 60 ? '#ea6500': x < 80 ? '#ea8500': x < 100 ? '#eab800': x < 120 ? '#eae300': x < 140 ? '#d3ea00': x < 160 ? '#b0ea00': x < 180 ? '#9cea00': x < 200 ? '#8cea00': x < 220 ? '#46ea00': x < 240 ? '#00ea4a': x < 260 ? '#00eac7': x < 280 ? '#00cfea': x < 300 ? '#009cea': x < 320 ? '#0065ea': x < 340 ? '#001bea': x < 360 ? '#3e00ea': x < 380 ? '#6900ea': x < 400 ? '#a400ea': x < 500 ? '#cb00ea': x < 600 ? '#ea00db': '#3e00ea' ; // return '#' + ('00000' + (x*2347 | 0).toString(16)).substr(-6); };