Realtime Flight Tracking Map

Mapbox powered tracking of flights in and out of SFO airport in San Francisco, California.

Embed

L.RotatedMarker = L.Marker.extend({
    options: { angle: 0 },
    _setPos: function(pos) {
        L.Marker.prototype._setPos.call(this, pos);
        if (L.DomUtil.TRANSFORM) {
            // use the CSS transform rule if available
            this._icon.style[L.DomUtil.TRANSFORM] += ' rotate(' + this.options.angle + 'deg)';
        } else if (L.Browser.ie) {
            // fallback for IE6, IE7, IE8
            var rad = this.options.angle * L.LatLng.DEG_TO_RAD,
                costheta = Math.cos(rad),
                sintheta = Math.sin(rad);
            this._icon.style.filter += ' progid:DXImageTransform.Microsoft.Matrix(sizingMethod=\'auto expand\', M11=' +
                costheta + ', M12=' + (-sintheta) + ', M21=' + sintheta + ', M22=' + costheta + ')';
        }
    }
});
var pubnub = new PubNub({
  publishKey: 'demo',
  subscribeKey: 'demo'
});
var map = eon.map({
  id: 'map',
  mbId: 'YOUR_MAPBOX_ID',
  mbToken: 'YOUR_MAPBOX_TOKEN',
  pubnub: pubnub,
  channels: ['sfo-flight-data'],
  rotate: true,
  history: true,
  marker: function (latlng, data) {

    var marker = new L.RotatedMarker(latlng, {
      icon: L.icon({
        iconUrl: '/static/images/airplane.png',
        iconSize: [24, 24]
      })
    });

    var popup = '';
    if(data[1]) {
      popup = 'Flight ' + data[1] + '';
    }
    if(data[2]) {
      if(!popup.length) {
        popup = 'Flight from ' + data[2];
      } else {
        popup += ' from ' + data[2];
      }
    }
    if(data[12]) {
      if(!popup.length) {
        popup = 'Flight to ' + data[12];
      } else {
        popup += ' to ' + data[12];
      }
    }
    if(!popup.length) {
      var popup = 'No data available';
    }

    marker.bindPopup(popup);

    return marker;
  }
});

Publish

var pubnub = new PubNub({
  publishKey: 'demo',
  subscribeKey: 'demo'
});
setInterval(function(){

  pubnub.publish({
    channel: 'sfo-flight-data',
    message:  
      {
        66e234a: {
           latlng: [
             37.6271,
             -122.3858
           ],
           data: [
             "A33D8C",
             37.6271,
             -122.3858,
             118,
             0,
             23,
             "3765",
             "F-KSJC3",
             "DC10",
             "N308FE",
             1433383239,
             "SFO",
             "MEM",
             "FX1345",
             1,
             0,
             "FDX1345",
             0
           ]
         },
         //...
      }
  });

}, 1000);

Try PubNub Today

Try Our APIs
  • 1M Transactions
  • 1GB Data Persistence
  • All major Features