This is the documentation for the OpenFlightsMap widget, meant for programmers who want to reuse the OpenFlights code in their own websites. If this is not you, then you're probably in the wrong place. How about taking a look at our data or the FAQ?
The widget is a work in progress. Suggestions about how to make the widget easier to setup, easier to use or more flexible are welcome!
OpenFlightsMap Widget demo (opens in new window)
To start, it's easiest just to grab the entire Git tree from GitHub:
git clone https://github.com/jpatokal/openflights.git
Or browse online.
- Apache web server
- MySQL 5.x database
- PHP 5.x with gettext
Once you have these set up, the sql/create.sql script can be used to generate the OpenFlights database schema and the sql/load_data.sql script can be used to load in the standard airport, airline and route databases:
mysql -u root <sql/create.sql
mysql -u openflights flightdb2 <sql/load-data.sql
OpenFlights differentiates between flight data (table flights), which is entered by users, and route data (table routes, which is data about what airlines fly where. While fundamentally the same -- every row has two airports and an optional airline -- the two differ in the additional details attached to the flights. A clean install of OpenFlights has no flight data, but a full set of route data.
Flight map data sets are generated by php/map.php. Route map data is generated by php/routes.php. Both also require the locale.php, db.php, helper.php and filter.php files; you must modify db.php so that it can find your database.
To validate your server installation, try to open either of the following URLs in a browser:
|http://localhost/php/routes.php?apid=32||32;6;Cambridge Bay (YCB) ...|
If you get any errors, check the Apache log (/var/log/apache2/error.log).
Note: The above is just a sanity check, do not attempt to parse responses from map.php or routes.php manually. The format is undocumented and unstable.
A web page using the OpenFlightsMap widget, such as widget/demo.html (launch), must include the following:
One by one:
- Your CSS file (demo.css) must define your map element (#map, although this can be renamed), the map title (#maptitle), a "Loading" icon (#ajaxloader) and, optionally, a #debug element. The CSS required by the underlying OpenLayers library is also included here.
- The OpenLayers library (OpenLayers.js), version 1.7 or higher.
- The OpenFlightsMap class itself (map.js).
- The code that initializes and run the widget (demo.js).
Once you've got all that set up, to actually initialize your widget, you need to:
- Set up an OpenLayers map layer
- Pass a suitable DOM element (by default "map") and the layer to the OpenFlightsMap constructor
- Load the map data from the server
To catch the user's clicks on airports, you'll also want to set up the onAirportSelect() and onAirportUnselect() callbacks. All this and more is demonstrated in widget/demo.html.
If you encounter any problems getting demo.html to run (blank map, error messages etc), check the error console of your browser (Tools > Error Console on Firefox) for clues.
The autogenerated JSDocs for OpenFlightsMap class and widget/demo.html are available under widget/jsdoc.