| 1 |
# See: http://wiki.flightgear.org/MapStructure |
| 2 |
# GPS line. Displays GPS leg information |
| 3 |
|
| 4 |
# Class things: |
| 5 |
var name = 'GPS'; |
| 6 |
var parents = [SymbolLayer.Controller]; |
| 7 |
var __self__ = caller(0)[0]; |
| 8 |
SymbolLayer.Controller.add(name, __self__); |
| 9 |
SymbolLayer.add(name, { |
| 10 |
parents: [MultiSymbolLayer], |
| 11 |
type: name, # Symbol type |
| 12 |
df_controller: __self__, # controller to use by default -- this one |
| 13 |
df_options: { # default configuration options |
| 14 |
from_node : "/instrumentation/gps/wp/wp[0]", |
| 15 |
to_node : "/instrumentation/gps/wp/wp[1]", |
| 16 |
|
| 17 |
trigger_node1 : "/instrumentation/gps/wp/wp[1]/longitude-deg", |
| 18 |
trigger_node2 : "/instrumentation/gps/wp/wp[1]/latitude-deg", |
| 19 |
trigger_node3 : "/instrumentation/gps/wp/wp[1]/altitude-ft", |
| 20 |
} |
| 21 |
}); |
| 22 |
var new = func(layer) { |
| 23 |
var m = { |
| 24 |
parents: [__self__], |
| 25 |
layer: layer, |
| 26 |
map: layer.map, |
| 27 |
listeners: [], |
| 28 |
last_result: [], |
| 29 |
}; |
| 30 |
layer.searcher._equals = func(l,r) 0; # TODO: create model objects instead? |
| 31 |
|
| 32 |
append(m.listeners, setlistener(layer.options.trigger_node1, func m.layer.update(), 0, 0)); |
| 33 |
append(m.listeners, setlistener(layer.options.trigger_node2, func m.layer.update(), 0, 0)); |
| 34 |
append(m.listeners, setlistener(layer.options.trigger_node3, func m.layer.update(), 0, 0)); |
| 35 |
|
| 36 |
m.addVisibilityListener(); |
| 37 |
return m; |
| 38 |
}; |
| 39 |
var del = func() { |
| 40 |
foreach (var l; me.listeners) |
| 41 |
removelistener(l); |
| 42 |
}; |
| 43 |
|
| 44 |
var searchCmd = func() { |
| 45 |
var coords = []; |
| 46 |
|
| 47 |
var from = props.globals.getNode(me.layer.options.from_node); |
| 48 |
var to = props.globals.getNode(me.layer.options.to_node); |
| 49 |
|
| 50 |
# Perform various checks for valid data. Unfortunately to avoid either |
| 51 |
# having continual triggering every frame as the property values are updated |
| 52 |
# (though not changed), we need to trigger this on any changes to the waypoint. |
| 53 |
# In an initial case, not all the properties may have been initialized yet. |
| 54 |
if ((from == nil) or (to == nil)) return []; |
| 55 |
if (to.getNode("valid").getBoolValue() == 0) return []; |
| 56 |
if (to.getValue("longitude-deg") == nil) return []; |
| 57 |
if (to.getValue("latitude-deg") == nil) return []; |
| 58 |
|
| 59 |
# Nil altitude is valid - set to 0. |
| 60 |
# if (to.getValue("altitude-ft") == nil) return []; |
| 61 |
|
| 62 |
append(coords, {lon: from.getValue("longitude-deg"), |
| 63 |
lat: from.getValue("latitude-deg"), |
| 64 |
alt: from.getValue("altitude-ft") }); |
| 65 |
|
| 66 |
append(coords, {lon: to.getValue("longitude-deg"), |
| 67 |
lat: to.getValue("latitude-deg"), |
| 68 |
alt: to.getValue("altitude-ft") or 0.0}); |
| 69 |
|
| 70 |
var lines = []; |
| 71 |
|
| 72 |
append(lines, { |
| 73 |
id: to.getNode("name", 1).getValue(), |
| 74 |
type: "gps", |
| 75 |
path: coords, |
| 76 |
equals: func(o){ |
| 77 |
return (me.path == o.path and me.type == o.type); |
| 78 |
} |
| 79 |
}); |
| 80 |
|
| 81 |
return lines; |
| 82 |
}; |