diff --git a/Models/FlightDeck/a320.flightdeck.xml b/Models/FlightDeck/a320.flightdeck.xml
index 53e2b24b..d0e52b2a 100644
--- a/Models/FlightDeck/a320.flightdeck.xml
+++ b/Models/FlightDeck/a320.flightdeck.xml
@@ -1457,7 +1457,7 @@
property-toggle
- instrumentation/efis[0]/inputs/terr
+ instrumentation/efis/inputs/terr
diff --git a/Models/Instruments/ND/canvas/ND.nas b/Models/Instruments/ND/canvas/ND.nas
index 90d5321c..543b0722 100644
--- a/Models/Instruments/ND/canvas/ND.nas
+++ b/Models/Instruments/ND/canvas/ND.nas
@@ -64,7 +64,6 @@ var myCockpit_switches = {
"toggle_xtrk_error": {path: "/nd/xtrk-error", value: 0, type: "BOOL"},
"toggle_trk_line": {path: "/nd/trk-line", value: 0, type: "BOOL"},
"ADIRS3": {path: "/nd/ir-3", value: 0, type: "BOOL"},
- #"toggle_terrain": {path: "/nd/terrain-on-nd", value: 0, type: "BOOL"},
};
var canvas_nd_base = {
diff --git a/Models/Instruments/ND/canvas/framework/navdisplay.nas b/Models/Instruments/ND/canvas/framework/navdisplay.nas
index 0f5e116c..594b5fd0 100644
--- a/Models/Instruments/ND/canvas/framework/navdisplay.nas
+++ b/Models/Instruments/ND/canvas/framework/navdisplay.nas
@@ -375,9 +375,9 @@ canvas.NavDisplay.update = func() # FIXME: This stuff is still too aircraft spec
wxr_live_enabled = 0;
me.set_switch('toggle_weather_live', wxr_live_enabled);
- var terr_enabled = getprop("/controls/switches/terr_on_nd_l");
- if (terr_enabled == nil) terr_enabled = 0;
- if (me.get_switch('toggle_terrain') != terr_enabled) me.set_switch('toggle_terrain', terr_enabled);
+ #var terr_enabled = getprop("/controls/switches/terr_on_nd_l");
+ #if (terr_enabled == nil) terr_enabled = 0;
+ #if (me.get_switch('toggle_terrain') != terr_enabled) me.set_switch('toggle_terrain', terr_enabled);
call(me.update_sub, nil, nil, caller(0)[0]); # call this in the same namespace to "steal" its variables
diff --git a/Models/Instruments/ND/canvas/loaders.nas b/Models/Instruments/ND/canvas/loaders.nas
index ed72a08d..e8cb8782 100644
--- a/Models/Instruments/ND/canvas/loaders.nas
+++ b/Models/Instruments/ND/canvas/loaders.nas
@@ -28,7 +28,7 @@ setlistener("/nasal/canvas/loaded", func() {
#var code = call(compile, [code], var err=[]);
var code = call(func compile(code, file), [code], var err=[]);
if (size(err)) {
- print("handling error");
+ #print("handling error");
if (substr(err[0], 0, 12) == "Parse error:") { # hack around Nasal feature
var e = split(" at line ", err[0]);
if (size(e) == 2)
diff --git a/Models/Instruments/ND/canvas/map/TERRAIN.symbol b/Models/Instruments/ND/canvas/map/TERRAIN.symbol
index eafbf4a1..2e8e963d 100644
--- a/Models/Instruments/ND/canvas/map/TERRAIN.symbol
+++ b/Models/Instruments/ND/canvas/map/TERRAIN.symbol
@@ -7,22 +7,27 @@ DotSym.makeinstance( name, __self__ );
var element_type = "group";
-var terrain_visible = props.globals.initNode("/custom/terrain/visible", 0,"INT");
var terrain_minalt = props.globals.initNode("/custom/terrain/min-altitude", 0,"INT");
var terrain_maxalt = props.globals.initNode("/custom/terrain/max-altitude", -9999,"INT");
-var tile_list = ["*black*","tile_01.png","tile_02.png","tile_03.png","tile_04.png","tile_06.png","tile_09.png"];
+var tile_list = ["*black*","tile_01.png","tile_02.png","tile_03.png","tile_04.png","tile_06.png","tile_09.png","tile_s1.png"];
+var is_terrain = 0;
var get_elevation = func (lat, lon) {
var info = geodinfo(lat, lon);
var elevation = 0;
- if (info != nil) { elevation = int(info[0] * 3.2808399); }
+ if (info != nil) {
+ elevation = int(info[0] * 3.2808399);
+ me.is_terrain = (info[1] == nil) ? 1 : info[1].solid;
+ }
else { elevation = nil; }
return elevation;
}
-var updateTerrain = func(r_scaled){
+var updateTerrain = func {
+
+ if (me.reference == nil) return;
if(me.fetching) return;
@@ -36,18 +41,11 @@ var updateTerrain = func(r_scaled){
var RAD2DEG = 57.2957795;
var DEG2RAD = 0.016774532925;
- var pos = geo.aircraft_position();
- var pos_lat = pos.lat();
- var pos_lon = pos.lon();
+ var pos_lat = me.reference.lat();
+ var pos_lon = me.reference.lon();
- var heading = getprop("orientation/heading-magnetic-deg");
- var altitudeft = pos.alt() * 3.2808399;
-
- if (me.basealtitudeft == nil) {
- var basealtft = me.get_elevation(pos_lat,pos_lon);
- if (basealtft == nil) basealtft = 0;
- me.basealtitudeft = basealtft + 400;
- }
+ var heading = me.reference.heading;
+ var altitudeft = me.reference.altitudeft;
var side = (math.mod(me.radar_beacon,2)==0) ? "L" : "R";
var a = int(me.radar_beacon/2);
@@ -82,21 +80,26 @@ var updateTerrain = func(r_scaled){
var elev = me.get_elevation(point_lat, point_lon);
var grad = 0; #black
if (elev != nil) {
- if (elevme.max_altitude) me.max_altitude = elev;
- if (elev < me.basealtitudeft) grad = 0; # < 400 (at airport) use blank - trivial
- else {
- var diff = elev - altitudeft;
- if (diff>=0) {
- grad = int(diff/1000) + 3;
- if (grad>5) grad = 5;
- } else {
- if (diff>-500) grad = 3; # lite yellow
- else {
- grad = 2 + int(diff/1000);
- if (grad<0) grad = 0;
+ if (me.is_terrain) {
+ if (elevme.max_altitude) me.max_altitude = elev;
+ if (elev < me.basealtitudeft) grad = 0; # < 400 near runway use blank
+ else {
+ var diff = elev - altitudeft;
+ if (diff>=0) {
+ grad = int(diff/1000) + 3;
+ if (grad>5) grad = 5;
+ } else {
+ if (diff>-500) grad = 3; # lite yellow
+ else {
+ grad = 2 + int(diff/1000);
+ if (grad<0) grad = 0;
+ }
}
}
+ } else {
+ var diff = elev - altitudeft;
+ if (diff>=-2000) grad = 7; #sea
}
append(elevft,grad); # 0-5
} else {
@@ -149,10 +152,11 @@ var init = func {
me.radar_cycle = 0;
me.radar_cleared = 1;
me.request_clear = 0;
- me.basealtitudeft = nil;
me.visible = 0;
me.min_altitude = 9999;
me.max_altitude = -9999;
+ me.basealtitudeft = nil;
+ me.reference = nil;
var tile = me.tile;
@@ -192,14 +196,10 @@ var init = func {
me.terrlayer["R" ~ c] = grprx;
}
- #me.update_interval = 300;
- #me.last_request = 0;
+ setlistener("/controls/switches/terr_on_nd_l", func{
+ me.request_clear = 1;
+ });
- #var r_scaled = (me.fetchRad*me.viewport_radius)/me.range;
- #me.fetchWXRMap(r_scaled);
-
- #me.timeStamp = nil;
- #http.load("https://api.rainviewer.com/public/maps.json").done(func(r) me.timeStamp = processRequest(r));
};
var clear = func {
@@ -224,23 +224,42 @@ var clear = func {
var draw = func {
if(me.fetching) return;
-
+
+ if (me.radar_beacon == 0) { # update aircraft reference
+
+ var ref = geo.aircraft_position();
+ me.reference = ref;
+ if (ref != nil) {
+ me.reference.heading = getprop("orientation/heading-magnetic-deg");
+ me.reference.altitudeft = ref.alt() * 3.2808399;
+
+ if (me.basealtitudeft == nil) {
+ var basealtft = me.get_elevation(ref.lat,ref.lon);
+ if (basealtft == nil) basealtft = 0;
+ me.basealtitudeft = basealtft + 400;
+ }
+
+ if ((fmgc.FMGCInternal.phase <= 1 or fmgc.FMGCInternal.phase >= 5) and (me.basealtitudeft == 0)) {
+ var basealtft = me.get_elevation(ref.lat,ref.lon);
+ if (basealtft == nil) basealtft = 0;
+ me.basealtitudeft = basealtft + 400;
+ # me.reference.basealtitudeft = ft + 400 # <- TODO get departure/arrival runway altitude
+ }
+ else if ((fmgc.FMGCInternal.phase > 1 and fmgc.FMGCInternal.phase < 5) and (me.basealtitudeft != 0)) {
+ me.basealtitudeft = 0;
+ }
+ }
+ }
+
var range = me.layer.map.getRange(); # Range of Navigation Display
var update_size = (range != me.range);
me.range = range;
- me.fetchRad = me.model.fetchRad; # Radius of radar layer to fetch
- var r_scaled = (me.fetchRad*me.viewport_radius)/me.range;
if(update_size){
me.request_clear = 1;
}
- if(me.terrain_visible.getValue() == 0){
- me.request_clear = 1;
- me.terrain_visible.setValue(1);
- }
-
- me.updateTerrain(r_scaled); # left
- if (math.mod(me.radar_beacon,2)==1) me.updateTerrain(r_scaled); # right
+ me.updateTerrain(); # left
+ if (math.mod(me.radar_beacon,2)==1) me.updateTerrain(); # right
};
diff --git a/Models/Instruments/ND/canvas/res/terrain/tile_s1.png b/Models/Instruments/ND/canvas/res/terrain/tile_s1.png
new file mode 100644
index 00000000..ae16caf3
Binary files /dev/null and b/Models/Instruments/ND/canvas/res/terrain/tile_s1.png differ
diff --git a/Models/Instruments/ND/canvas/style.nas b/Models/Instruments/ND/canvas/style.nas
index 8e5e1924..4eb3dffa 100644
--- a/Models/Instruments/ND/canvas/style.nas
+++ b/Models/Instruments/ND/canvas/style.nas
@@ -12,7 +12,6 @@ var adirs_3 = props.globals.getNode("/instrumentation/efis[0]/nd/ir-3", 1);
var vhdg_bug = props.globals.getNode("/it-autoflight/input/hdg",0); # ND compass position deg
-var terrain_visible = props.globals.getNode("/custom/terrain/visible", 0);
var terrain_minalt = props.globals.getNode("/custom/terrain/min-altitude", 0);
var terrain_maxalt = props.globals.getNode("/custom/terrain/max-altitude", -9999);
@@ -95,13 +94,11 @@ canvas.NDStyles["Airbus"] = {
#print("TERRAIN TOGGLE: " ~ nd.get_switch("toggle_terrain"));
var visible = nd.get_switch("toggle_terrain") and
nd.get_switch("toggle_display_mode") != "PLAN" and (nd.rangeNm() <= 40) and !nd.get_switch("toggle_centered") and
- (nd.adirs_property.getValue() == 1 or (adirs_3.getValue() == 1 and att_switch.getValue() == nd.attitude_heading_setting));
- layer.group.setVisible(visible);
+ (nd.adirs_property.getValue() == 1 or (adirs_3.getValue() == 1 and att_switch.getValue() == nd.attitude_heading_setting));
if (visible) {
layer.update();
- } else {
- #terrain_visible.setValue(0);
}
+ layer.group.setVisible(visible);
}, # end of layer update predicate
options: {
viewport_radius: 670, #512, #706,