diff --git a/Models/Instruments/ND/canvas/framework/navdisplay.nas b/Models/Instruments/ND/canvas/framework/navdisplay.nas index 04a59949..0f5e116c 100644 --- a/Models/Instruments/ND/canvas/framework/navdisplay.nas +++ b/Models/Instruments/ND/canvas/framework/navdisplay.nas @@ -69,7 +69,7 @@ canvas.NavDisplay.newMFD = func(canvas_group, parent=nil, nd_options=nil, update # because things are much better configurable that way # now look up all required SVG elements and initialize member fields using the same name to have a convenient handle foreach(var element; ["dmeLDist","dmeRDist","dmeL","dmeR","vorL","vorR","vorLId","vorRId", - "status.wxr","status.wpt","status.sta","status.arpt"]) + "status.wxr","status.wpt","status.sta","status.arpt","terrHI","terrLO"]) me.symbols[element] = me.nd.getElementById(element); # load elements from vector image, and create instance variables using identical names, and call updateCenter() on each diff --git a/Models/Instruments/ND/canvas/map/TERRAIN.lcontroller b/Models/Instruments/ND/canvas/map/TERRAIN.lcontroller index dfe9f333..4fba3af4 100644 --- a/Models/Instruments/ND/canvas/map/TERRAIN.lcontroller +++ b/Models/Instruments/ND/canvas/map/TERRAIN.lcontroller @@ -14,8 +14,6 @@ canvas.SymbolLayer.add(name, { } }); -var terrain_tree = "/instrumentation/terrain"; - var new = func(layer) { var m = { parents: [__self__], @@ -36,14 +34,10 @@ var del = func() { var searchCmd = func { if(me.map.getRange() == nil) return []; - #var lat = getprop(terrain_tree~"/center/latitude-deg"); - #var lon = getprop(terrain_tree~"/center/longitude-deg"); - #if(lat == nil or lon == nil) { - var pos = geo.aircraft_position(); - lat = pos.lat(); - lon = pos.lon(); - #} + var pos = geo.aircraft_position(); + lat = pos.lat(); + lon = pos.lon(); var result = geo.Coord.new(); result.set_latlon(lat, lon); diff --git a/Models/Instruments/ND/canvas/map/TERRAIN.symbol b/Models/Instruments/ND/canvas/map/TERRAIN.symbol index 48c384d9..65467122 100644 --- a/Models/Instruments/ND/canvas/map/TERRAIN.symbol +++ b/Models/Instruments/ND/canvas/map/TERRAIN.symbol @@ -7,20 +7,19 @@ 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 radar_beacon = 0; -var radar_cycle = 0; -var rader_cleared = 0; var get_elevation = func (lat, lon) { - var info = geodinfo(lat, lon); var elevation = 0; if (info != nil) { elevation = int(info[0] * 3.2808399); } else { elevation = nil; } return elevation; - } var updateTerrain = func(r_scaled){ @@ -28,7 +27,11 @@ var updateTerrain = func(r_scaled){ if(me.fetching) return; me.fetching = 1; - me.rader_cleared = 0; + + if (me.request_clear == 1) { + me.request_clear = 0; + me.clear(); + } var RAD2DEG = 57.2957795; var DEG2RAD = 0.016774532925; @@ -54,80 +57,85 @@ var updateTerrain = func(r_scaled){ col = -1 + (-1 * a); } - #var col = me.radar_beacon - me.tileradius; + var trn = me.terrlayer[side ~ a]; - #for (var a=0; a < me.tileradius; a+=1) { + var len = size(trn); + var range = me.range; - #var trnL = me.terrlayer["L" ~ a]; - #var trnR = me.terrlayer["R" ~ a]; - var trn = me.terrlayer[side ~ a]; + var tiles = me.tile_list; - var len = size(trn); - var range = me.range; + var proj_lon = pos_lon + ((col * (range/30) * math.sin(DEG2RAD * (heading - 90))) / 40); + var proj_lat = pos_lat + ((col * (range/30) * math.cos(DEG2RAD * (heading - 90))) / 40); - var tiles = me.tile_list; + var elevft = []; - var proj_lon = pos_lon + ((col * (range/30) * math.sin(DEG2RAD * (heading - 90))) / 40); - var proj_lat = pos_lat + ((col * (range/30) * math.cos(DEG2RAD * (heading - 90))) / 40); + for (var row = 0; row < len; row += 1) { - var elevft = []; + if (trn[row] == nil) { + append(elevft,-1); + continue; + } - for (var row = 0; row < len; row += 1) { + var point_lon = proj_lon + ((row * (range/30) / 40) * math.sin(DEG2RAD * heading)); + var point_lat = proj_lat + ((row * (range/30) / 40) * math.cos(DEG2RAD * heading)); - if (trn[row] == nil) { - append(elevft,-1); - continue; - } - - var point_lon = proj_lon + ((row * (range/30) / 40) * math.sin(DEG2RAD * heading)); - var point_lat = proj_lat + ((row * (range/30) / 40) * math.cos(DEG2RAD * heading)); - - var elev = me.get_elevation(point_lat, point_lon); - var grad = 0; #black - if (elev != nil) { - 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; - } + 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; } } - append(elevft,grad); # 0-5 - } else { - append(elevft,6); # magenta } - + append(elevft,grad); # 0-5 + } else { + append(elevft,6); # magenta } + + } - for (var r=0; r < len; r+=1) { + me.radar_cleared = 0; - var imgx = elevft[r]; - if (imgx == -1) continue; - if (imgx < 1) trn[r].hide(); - else trn[r].setFile(me.imgpath ~ me.tile_list[imgx]).show(); - #trnR[r].setFile(me.imgpath ~ me.tile_list[2-imgx]).show(); - - } - - #} + for (var r=0; r < len; r+=1) { + var imgx = elevft[r]; + if (imgx == -1) continue; + if (imgx < 1) trn[r].hide(); + else trn[r].setFile(me.imgpath ~ me.tile_list[imgx]).show(); + } me.radar_beacon += 1; - if (me.radar_beacon >= (me.tileradius*2)) { - me.radar_beacon = 0; - me.radar_cycle += 1; + if (me.radar_beacon >= (me.tileradiusw*2)) { + me.update_altitudes(); + me.restart_beacon(); } #me.last_request = getprop("sim/time/elapsed-sec"); me.fetching = 0; }; +var update_altitudes = func { + me.terrain_minalt.setValue(me.min_altitude); + me.terrain_maxalt.setValue(me.max_altitude); +} + +var restart_beacon = func { + me.radar_beacon = 0; + me.radar_cycle += 1; + me.min_altitude = 9999; + me.max_altitude = -9999; +}; + var init = func { #print('TERRAIN init'); me.tile = 33; # preferred 34 @@ -137,24 +145,31 @@ var init = func { me.range = me.model.rangeNm; # Range of Navigation Display me.viewport_radius = me.getOption('viewport_radius', 670); me.imgpath = get_local_path('res/terrain/'); - me.rader_cleared = 1; + me.radar_beacon = 0; + 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; var tile = me.tile; var gx = int(me.viewport_radius / tile); - me.tileradius = gx; - me.terrlayer = {}; #me.element.createChild("image").set("z-index", -100).hide(); + var limx = int((512/tile)+0.5); # horiz space is smaller + me.tileradiusw = limx; - var centx = 0; #me.viewport_radius * -0.5; + me.terrlayer = {}; + + var centx = 0; var centy = -me.viewport_radius; var group = me.group.createChild("group").set("z-index", -100); #me.element - for (var c=0; cTERR000000 -image/svg+xmlGijs de Rooy▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ diff --git a/Models/Instruments/ND/canvas/style.nas b/Models/Instruments/ND/canvas/style.nas index f3174d52..4b51decc 100644 --- a/Models/Instruments/ND/canvas/style.nas +++ b/Models/Instruments/ND/canvas/style.nas @@ -12,6 +12,9 @@ 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); canvas.NDStyles["Airbus"] = { font_mapper: func(family, weight) { @@ -86,23 +89,22 @@ canvas.NDStyles["Airbus"] = { layers: [ { name:"TERRAIN", - isMapStructure:1, - always_update: 1, - update_on:[ {rate_hz: 0.4}, "toggle_range","toggle_display_mode","toggle_terrain"], + isMapStructure: 1, + update_on:[ {rate_hz: 18}, "toggle_range","toggle_display_mode","toggle_terrain"], predicate: func(nd, layer) { #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.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); if (visible) { layer.update(); + } else { + #terrain_visible.setValue(0); } }, # end of layer update predicate options: { viewport_radius: 670, #512, #706, - #position_callback: func(nd, pos){ - # pos = me.startpos; - #} }, "z-index": -100, }, @@ -1980,6 +1982,26 @@ canvas.NDStyles["Airbus"] = { nd.symbols.offsetLbl.hide(); } } + }, + { + id: "terrGroup", + impl: { + init: func(nd,symbol), + predicate: func(nd) ( 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)) ), + is_true: func(nd){ + if (terrain_maxalt.getValue() != -9999) { + nd.symbols.terrLO.setText(sprintf("%03d",int(terrain_minalt.getValue()/100))); + nd.symbols.terrHI.setText(sprintf("%03d",int(terrain_maxalt.getValue()/100))); + nd.symbols.terrGroup.show(); + terrain_maxalt.setValue(-9999); #update visual once at radar cycle + } + }, + is_false: func(nd){ + nd.symbols.terrGroup.hide(); + } + } } ], # end of vector with features