MapStructure Snippets

From FlightGear wiki
Jump to navigation Jump to search
WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
See history for the latest developments.

Position Sources

Each MapStructure layer needs to provide a searchCmd method which returns a vector with positions that are to be dispayled on the map, these can be FGPositioned ghosts (C++ objects read from the NavCache) or geo.Coord objects. The searchCmd() method only ever deals with positions, it doesn't bother with visual stuff (i.e. drawing) or updating semantics, the former is handled by .symbol files and the latter by controllers.

Ghosts (C++ objects)

As of 10/2015 (FG 3.6), MapStructure directly supports thefollowing FGPosotopned objects:

  • positioned
  • Navaid
  • Fix
  • flightplan-leg
  • FGAirport

This means that these objects can be directly processed without having to provide/implement any custom routines. To add support for additional ghosts, the vector in the canvas namespace needs to be extended, or appended to at run-time.

Navaids

For navaids, there is a generator provided to create the corresponding searchCmd function automatically, the only thing that needs to be provided is the name of the query:

VOR

var searchCmd = NavaidSymbolLayer.make('vor');

NDB

var searchCmd = NavaidSymbolLayer.make('ndb');

DME

var searchCmd = NavaidSymbolLayer.make('dme');

Geographic Positions

For Nasal-space objects, geo.Coord objects should be used - the most basic searchCmd function would simply return a vector with a single position object:

var searchCmd = func() {
    return [geo.Coord.aircraft_position()];
}

(this returns the current position of the aircraft)

Alternatively, you can also come up with a helper class that either wraps geo.Coord or which inherits from it (extending it). Typically, such a helper class is called FooModel - for example referring to the TFC/WPT layer:


Subsequently, you would simply return new instances of the corresponding class, by passing any relevant information via the constructor:

Spatial Filtering

Typically, you will have dozens of objects per layer, so it makes sense to filter (exclude) objects based on the range to the map's center position:

var searchCmd = func() {
    var offset_deg = 30;
    var offset_distance = 16000;
    if (me.map.getRange() == nil) {
        return;
    }

    var result = [];

    for (var i = 0; i < 360; i += offset_deg) {
        var pos = geo.aircraft_position();
        pos.apply_course_distance(i, (1 + i) * offset_distance);
        var (lat, lon) = (pos.lat, pos.lon);
        if (me.map.controller.in_range(lat, lon)) {
            append(result, geo.Coord.new(lat, lon));
        }
        else {
            print("Skipping position that is not in range");
        }
    }
    return result;
}

Flight Path History

AI Traffic

Weather

Route Manager

Visualization

Text Labels

Caching & Styling

Vector Images

Raster Images

Animations

Controllers

  • aircraft position
  • AI traffic
  • interactive

Testing

Debugging

Benchmarking