66c15d5b89
Without this it will cause a nil dereference resulting in Nasal runtime error: non-objects have no members at D:/Program Files/FlightGear 2018.2.2/data/Nasal/canvas/map/WPT.lcontroller, line 57 called from: D:/Program Files/FlightGear 2018.2.2/data/Nasal/canvas/map/WPT.lcontroller, line 79 called from: D:/Program Files/FlightGear 2018.2.2/data/Nasal/canvas/MapStructure.nas, line 1088 called from: D:/Program Files/FlightGear 2018.2.2/data/Nasal/geo.nas, line 384 called from: D:/Program Files/FlightGear 2018.2.2/data/Nasal/canvas/MapStructure.nas, line 1051 called from: D:/Program Files/FlightGear 2018.2.2/data/Nasal/canvas/MapStructure.nas, line 1059 called from: D:/Program Files/FlightGear 2018.2.2/data/Nasal/canvas/map/WPT.lcontroller, line 26 called from: D:/Program Files/FlightGear 2018.2.2/data/Nasal/globals.nas, line 119
90 lines
2.4 KiB
Text
90 lines
2.4 KiB
Text
# See: http://wiki.flightgear.org/MapStructure
|
|
# Class things:
|
|
var name = 'WPT'; # for waypoints
|
|
var parents = [SymbolLayer.Controller];
|
|
var __self__ = caller(0)[0];
|
|
SymbolLayer.Controller.add(name, __self__);
|
|
SymbolLayer.add(name, {
|
|
parents: [MultiSymbolLayer],
|
|
type: name, # Symbol type
|
|
df_controller: __self__, # controller to use by default -- this one
|
|
df_options: { # default configuration options
|
|
active_node: "/autopilot/route-manager/active",
|
|
current_wp_node: "/autopilot/route-manager/current-wp",
|
|
wp_num: "/autopilot/route-manager/route/num",
|
|
}
|
|
});
|
|
var new = func(layer) {
|
|
var m = {
|
|
parents: [__self__],
|
|
layer: layer,
|
|
options: layer.options,
|
|
map: layer.map,
|
|
listeners: [],
|
|
};
|
|
layer.searcher._equals = func(l,r) l.equals(r);
|
|
append(m.listeners, setlistener(layer.options.active_node, func m.layer.update() ), setlistener(layer.options.wp_num, func m.layer.update() ));
|
|
var driver = opt_member(m.layer.options, 'route_driver');
|
|
if(driver == nil){
|
|
driver = RouteDriver.new();
|
|
}
|
|
var driver_listeners = driver.getListeners();
|
|
foreach(var listener; driver_listeners){
|
|
append(m.listeners, setlistener(listener, func m.layer.update()));
|
|
}
|
|
m.route_driver = driver;
|
|
m.addVisibilityListener();
|
|
|
|
return m;
|
|
};
|
|
var del = func() {
|
|
#print(name~"VOR.lcontroller.del()");
|
|
foreach (var l; me.listeners)
|
|
removelistener(l);
|
|
};
|
|
|
|
var WPT_model = {
|
|
new: func(fp, idx, offset=0) {
|
|
var m = { parents:[WPT_model], idx:(idx+offset) };
|
|
var wp = fp.getWP(idx);
|
|
m.name = wp.wp_name;
|
|
|
|
var alt = wp.alt_cstr;
|
|
if (alt != 0)
|
|
m.name ~= "\n"~alt;
|
|
|
|
var wp2idx = 1; # next waypoint
|
|
|
|
if (!idx) { # first point
|
|
if(fp.getPlanSize(idx) == 1) # if only have one wpt then it must be at element 0.
|
|
wp2idx = 0;
|
|
}
|
|
if (idx) var n = wp.path()[-1];
|
|
else var n = fp.getWP(wp2idx).path()[0];
|
|
|
|
(m.lat,m.lon) = (n.lat,n.lon);
|
|
return m;
|
|
},
|
|
equals: func(other) {
|
|
# this is set on symbol init, so use this for equality...
|
|
me.name == other.name
|
|
},
|
|
};
|
|
|
|
var searchCmd = func {
|
|
printlog(_MP_dbg_lvl, "Running query: "~name);
|
|
|
|
if (!getprop(me.options.active_node)) return [];
|
|
var driver = me.route_driver;
|
|
driver.update();
|
|
var result = [];
|
|
var planCount = driver.getNumberOfFlightPlans();
|
|
for(var idx = 0; idx < planCount; idx += 1){
|
|
var fp = driver.getFlightPlan(idx);
|
|
var fpSize = fp.getPlanSize(idx);
|
|
for (var i = 0; i < fpSize; i+=1)
|
|
append(result, WPT_model.new(fp, i));
|
|
}
|
|
return result;
|
|
};
|
|
|