diff --git a/Nasal/canvas/MapStructure.nas b/Nasal/canvas/MapStructure.nas
index 9ed93fe66..0afdcd213 100644
--- a/Nasal/canvas/MapStructure.nas
+++ b/Nasal/canvas/MapStructure.nas
@@ -186,7 +186,7 @@ Symbol.Controller.getpos = func(obj) {
die("bad ghost of type '"~ghosttype(obj)~"'");
if (typeof(obj) == 'hash')
if (isa(obj, geo.Coord))
- return obj.latlon();
+ return subvec(obj.latlon(), 0, 2);
if (isa(obj, props.Node))
return [
obj.getValue("position/latitude-deg") or obj.getValue("latitude-deg"),
@@ -380,8 +380,13 @@ var SymbolLayer = {
onAdded: func(model)
append(me.list, Symbol.new(me.type, me.group, model)),
# Removes a symbol.
- onRemoved: func(model)
- me.findsym(model, 1).del(),
+ onRemoved: func(model) {
+ if (me.findsym(model, 1)) die("model not found");
+ call(func model.del, nil, var err = []);
+ # ignore errors
+ # TODO: ignore only missing member del() errors? and only from the above line?
+ # Note: die(err[0]) rethrows it; die(err[0]~"") does not.
+ },
}; # of SymbolLayer
# Class to manage controlling a #SymbolLayer.
diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas
index 96f258b3f..349b59e7e 100644
--- a/Nasal/canvas/api.nas
+++ b/Nasal/canvas/api.nas
@@ -422,7 +422,7 @@ var Map = {
df_controller: nil,
new: func(ghost)
{
- return { parents: [Map, Group.new(ghost)] }.setController();
+ return { parents: [Map, Group.new(ghost)], layers:{} }.setController();
},
del: func()
{
@@ -451,9 +451,6 @@ var Map = {
},
addLayer: func(factory, type_arg=nil, priority=nil)
{
- if (!contains(me, "layers"))
- me.layers = {};
-
if(contains(me.layers, type_arg))
print("addLayer() warning: overwriting existing layer:", type_arg);
diff --git a/Nasal/canvas/map/TFC.lcontroller b/Nasal/canvas/map/TFC.lcontroller
index c766f6cac..41767e876 100644
--- a/Nasal/canvas/map/TFC.lcontroller
+++ b/Nasal/canvas/map/TFC.lcontroller
@@ -21,18 +21,22 @@ var new = func(layer) {
# Listen to ai model events
append(m.listeners, setlistener(
model_root.getNode("model-added"), func(n) {
+ #printlog(_MP_dbg_lvl, "Dynamically adding model at "~n.getValue());
var node = props.globals.getNode(n.getValue());
var name = node.getName();
if (name == "aircraft" or name == "multiplayer")
- layer.onAdded(TrafficModel.new(node));
+ if (m.in_range(node.getValue("position/latitude-deg"), node.getValue("position/longitude-deg")))
+ layer.onAdded(TrafficModel.new(node));
}
));
append(m.listeners, setlistener(
model_root.getNode("model-removed"), func(n) {
+ #printlog(_MP_dbg_lvl, "Dynamically deleting model at "~n.getValue());
var node = props.globals.getNode(n.getValue());
var name = node.getName();
if (name == "aircraft" or name == "multiplayer")
- layer.onRemoved(TrafficModel.new(node));
+ if (m.in_range(node.getValue("position/latitude-deg"), node.getValue("position/longitude-deg")))
+ layer.onRemoved(TrafficModel.new(node));
}
));
layer.searcher._equals = func(l,r) l.equals(r);
@@ -43,6 +47,19 @@ var del = func() {
foreach (var l; me.listeners)
removelistener(l);
};
+var in_range = func(lat,lon,myPositionVec=nil,max_dist_m=nil) {
+ if (lat == nil or lon == nil) return 0;
+ var pos = geo.Coord.new();
+ pos.set_latlon(lat,lon);
+ var myPosition = geo.Coord.new();
+ # FIXME: need a Map Controller for this, and all query_range's/get_position's
+ if (myPositionVec == nil)
+ var myPositionVec = me.get_position();
+ myPosition.set_latlon( myPositionVec[0], myPositionVec[1]);
+ if (max_dist_m == nil)
+ var max_dist_m = me.query_range()*NM2M;
+ return (pos.distance_to( myPosition ) <= max_dist_m )
+};
var TrafficModel = {
new: func(node, id=nil, layer=nil) {
@@ -50,13 +67,14 @@ var TrafficModel = {
var m = {
# Note: because this inherits from props.Node, Symbol.Controller.equals
# will call l.equals(r) -- the one defined below
- parents: [TrafficModel, geo.Coord, node],
+ parents: [TrafficModel, geo.Coord, node], # note we don't implement a full geo.Coord API
id: id,
node: node,
- pos: node.getNode("position"),
+ pos: node.getNode("position",1),
};
if (m.pos == nil)
m.latlon = func [nil,nil,nil];
+ #debug.dump(m); # why doesn't this print?
return m;
},
equals: func(other) other.id == me.id,
@@ -74,22 +92,20 @@ var searchCmd = func {
#print("Doing query: "~name);
var result = [];
- var pos = geo.Coord.new(); # FIXME: all of these should be instance variables
- var myPosition = geo.Coord.new();
# FIXME: need a Map Controller for this, and all query_range's/get_position's
var myPositionVec = me.get_position();
- myPosition.set_latlon( myPositionVec[0], myPositionVec[1]);
var max_dist_m = me.query_range()*NM2M;
# AI and Multiplayer traffic
- foreach (var traffic; [model_root.getChildren("aircraft"), model_root.getChildren("multiplayer")])
+ foreach (var traffic; [model_root.getChildren("aircraft"), model_root.getChildren("multiplayer")]) {
foreach(var t; traffic) {
- pos.set_latlon(t.getValue("position/latitude-deg"),
- t.getValue("position/longitude-deg"));
-
- if (pos.distance_to( myPosition ) <= max_dist_m )
+ if (me.in_range(t.getValue("position/latitude-deg"),
+ t.getValue("position/longitude-deg"),
+ myPositionVec,
+ max_dist_m))
append(result, TrafficModel.new(t, nil, me.layer));
}
+ }
#debug.dump(result);
#return [];
diff --git a/preferences.xml b/preferences.xml
index b4c7b0dc2..f99b8558e 100644
--- a/preferences.xml
+++ b/preferences.xml
@@ -66,10 +66,10 @@ Started September 2000 by David Megginson, david@megginson.com
default-pipeline
false
false
- 1.0
+ 0.6
true
true
- 1.0
+ 0.6
true
false
@@ -104,7 +104,7 @@ Started September 2000 by David Megginson, david@megginson.com
1.0
false
- true
+ false
false
@@ -229,13 +229,13 @@ Started September 2000 by David Megginson, david@megginson.com
true
false
- 4096
+ 2048
4
- 5.0
- 50.0
- 500.0
- 5000.0
- 2
+ 2.0
+ 8.0
+ 32.0
+ 128.0
+ 1
false
true