2017-11-24 23:04:46 +00:00
|
|
|
# Navigation Map
|
2017-12-27 19:51:54 +00:00
|
|
|
var NavigationMap =
|
2017-11-24 23:04:46 +00:00
|
|
|
{
|
2017-12-10 22:15:21 +00:00
|
|
|
new : func (mfd, myCanvas, device, svg)
|
2017-11-24 23:04:46 +00:00
|
|
|
{
|
|
|
|
var obj = {
|
2017-12-27 19:51:54 +00:00
|
|
|
parents : [
|
|
|
|
NavigationMap,
|
|
|
|
MFDPage.new(mfd, myCanvas, device, svg, "NavigationMap", "MAP - NAVIGATION MAP")
|
|
|
|
],
|
2017-11-24 23:04:46 +00:00
|
|
|
};
|
|
|
|
|
2018-01-29 21:43:43 +00:00
|
|
|
# Center the map's origin, modified to take into account the surround.
|
|
|
|
obj._group.setTranslation(
|
|
|
|
fg1000.MAP_FULL.CENTER.X - (1024/2),
|
|
|
|
fg1000.MAP_FULL.CENTER.Y - (768/2)
|
|
|
|
);
|
|
|
|
|
2017-11-24 23:04:46 +00:00
|
|
|
obj.MFDMap = obj._group.createChild("map");
|
2018-01-14 20:46:50 +00:00
|
|
|
|
2017-12-27 19:51:54 +00:00
|
|
|
obj.MFDMap.setScreenRange(689/2.0);
|
2017-11-24 23:04:46 +00:00
|
|
|
|
2017-12-27 19:51:54 +00:00
|
|
|
# Labels for map range and orientation. Two sets - one for the full display
|
|
|
|
# and another for the partial display.
|
|
|
|
obj.addTextElements(["RangeDisplay", "Orientation"]);
|
|
|
|
obj.addTextElements(["RangeDisplayPartial", "OrientationPartial"]);
|
2017-11-24 23:04:46 +00:00
|
|
|
|
2017-12-31 16:10:52 +00:00
|
|
|
obj._labelsFull = svg.getElementById("NavigationMapGroup");
|
|
|
|
assert(obj._labelsFull != nil, "Unable to find NavigationMapGroup");
|
2017-11-24 23:04:46 +00:00
|
|
|
|
2017-12-27 19:51:54 +00:00
|
|
|
obj._labelsPartial = svg.getElementById("NavigationMapGroupPartial");
|
|
|
|
assert(obj._labelsPartial != nil, "Unable to find NavigationMapGroupPartial");
|
|
|
|
|
|
|
|
# Initialize the controllers:
|
2017-11-24 23:04:46 +00:00
|
|
|
var ctrl_ns = canvas.Map.Controller.get("Aircraft position");
|
|
|
|
var source = ctrl_ns.SOURCES["current-pos"];
|
|
|
|
if (source == nil) {
|
|
|
|
# TODO: amend
|
|
|
|
var source = ctrl_ns.SOURCES["current-pos"] = {
|
|
|
|
getPosition: func subvec(geo.aircraft_position().latlon(), 0, 2),
|
|
|
|
getAltitude: func getprop('/position/altitude-ft'),
|
|
|
|
getHeading: func {
|
|
|
|
if (me.aircraft_heading)
|
|
|
|
getprop('/orientation/heading-deg')
|
|
|
|
else 0
|
|
|
|
},
|
|
|
|
aircraft_heading: 1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
setlistener("/sim/gui/dialogs/map-canvas/aircraft-heading-up", func(n) {
|
|
|
|
source.aircraft_heading = n.getBoolValue();
|
|
|
|
}, 1);
|
|
|
|
# Make it move with our aircraft:
|
|
|
|
obj.MFDMap.setController("Aircraft position", "current-pos"); # from aircraftpos.controller
|
|
|
|
|
|
|
|
var r = func(name,vis=1,zindex=nil) return caller(0)[0];
|
|
|
|
# TODO: we'll need some z-indexing here, right now it's just random
|
2018-01-29 21:43:43 +00:00
|
|
|
foreach(var type; [r('GRID'),r('DTO',0),r('TFC',0),r('APT'),r('DME'),r('VOR'),r('NDB'),r('FIX',0),r('GPS'),r('RTE'),r('WPT'),r('FLT'),r('WXR',0),r('APS')] ) {
|
2018-01-26 19:06:06 +00:00
|
|
|
obj.MFDMap.addLayer(
|
|
|
|
factory: canvas.SymbolLayer,
|
|
|
|
type_arg: type.name,
|
|
|
|
priority: 4,
|
|
|
|
style: obj.Styles.getStyle(type.name),
|
|
|
|
options: obj.Options.getOption(type.name),
|
|
|
|
visible: type.vis);
|
2017-11-24 23:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach(var type; [ r('STAMEN_terrain'),r('STAMEN'), r('OpenAIP') ]) {
|
2018-01-26 19:06:06 +00:00
|
|
|
obj.MFDMap.addLayer(
|
|
|
|
factory: canvas.OverlayLayer,
|
|
|
|
type_arg: type.name,
|
|
|
|
priority: 1,
|
|
|
|
style: obj.Styles.getStyle(type.name),
|
|
|
|
options: obj.Options.getOption(type.name),
|
|
|
|
visible: 0);
|
2017-11-24 23:04:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-31 16:10:52 +00:00
|
|
|
#obj.topMenu(device, obj, nil);
|
2017-11-24 23:04:46 +00:00
|
|
|
|
2018-01-26 19:06:06 +00:00
|
|
|
obj.setController(fg1000.NavigationMapController.new(obj, svg));
|
2017-12-27 19:51:54 +00:00
|
|
|
|
2017-11-24 23:04:46 +00:00
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
toggleLayerVisible : func(name) {
|
|
|
|
(var l = me.MFDMap.getLayer(name)).setVisible(l.getVisible());
|
|
|
|
},
|
|
|
|
setLayerVisible : func(name,n=1) {
|
|
|
|
me.MFDMap.getLayer(name).setVisible(n);
|
|
|
|
},
|
2017-12-27 19:51:54 +00:00
|
|
|
setRange : func(range, label) {
|
2017-11-24 23:04:46 +00:00
|
|
|
me.MFDMap.setRange(range);
|
2017-12-27 19:51:54 +00:00
|
|
|
me.setTextElement("RangeDisplay", label);
|
|
|
|
me.setTextElement("RangeDisplayPartial", label);
|
|
|
|
},
|
|
|
|
setOrientation : func(orientation) {
|
|
|
|
me.setTextElement("Orientation", orientation);
|
|
|
|
me.setTextElement("OrientationPartial", orientation);
|
2017-11-24 23:04:46 +00:00
|
|
|
},
|
|
|
|
setScreenRange : func(range) {
|
|
|
|
me.MFDMap.setScreenRange(range);
|
|
|
|
},
|
2018-01-26 19:06:06 +00:00
|
|
|
offdisplay : func(controller=1) {
|
2017-11-24 23:04:46 +00:00
|
|
|
me._group.setVisible(0);
|
|
|
|
|
|
|
|
# Reset the menu colours. Shouldn't have to do this here, but
|
|
|
|
# there's not currently an obvious other location to do so.
|
|
|
|
for(var i = 0; i < 12; i +=1) {
|
|
|
|
var name = sprintf("SoftKey%d",i);
|
|
|
|
me.device.svg.getElementById(name ~ "-bg").setColorFill(0.0,0.0,0.0);
|
|
|
|
me.device.svg.getElementById(name).setColor(1.0,1.0,1.0);
|
|
|
|
}
|
2018-01-26 19:06:06 +00:00
|
|
|
if (controller == 1) me.getController().offdisplay();
|
2017-11-24 23:04:46 +00:00
|
|
|
},
|
2018-01-26 19:06:06 +00:00
|
|
|
ondisplay : func(controller=1) {
|
2017-11-24 23:04:46 +00:00
|
|
|
me._group.setVisible(1);
|
2017-12-27 19:51:54 +00:00
|
|
|
|
|
|
|
# Center the map's origin, modified to take into account the surround.
|
|
|
|
me.MFDMap.setTranslation(
|
|
|
|
fg1000.MAP_FULL.CENTER.X,
|
|
|
|
fg1000.MAP_FULL.CENTER.Y
|
|
|
|
);
|
|
|
|
|
|
|
|
me._labelsFull.setVisible(1);
|
|
|
|
me._labelsPartial.setVisible(0);
|
|
|
|
|
2017-12-10 22:15:21 +00:00
|
|
|
me.mfd.setPageTitle(me.title);
|
2018-01-26 19:06:06 +00:00
|
|
|
if (controller == 1) me.getController().ondisplay();
|
2017-11-24 23:04:46 +00:00
|
|
|
},
|
2017-12-27 19:51:54 +00:00
|
|
|
|
|
|
|
# Display functions when we're displaying the NavigationMap as part of another
|
|
|
|
# page - e.g. NearestAirports.
|
|
|
|
ondisplayPartial : func() {
|
|
|
|
me._group.setVisible(1);
|
|
|
|
me.MFDMap.setTranslation(
|
|
|
|
fg1000.MAP_PARTIAL.CENTER.X,
|
|
|
|
fg1000.MAP_PARTIAL.CENTER.Y
|
|
|
|
);
|
|
|
|
|
|
|
|
me._labelsFull.setVisible(0);
|
|
|
|
me._labelsPartial.setVisible(1);
|
|
|
|
|
2018-01-26 19:06:06 +00:00
|
|
|
#me.getController().ondisplayPartial();
|
2017-12-27 19:51:54 +00:00
|
|
|
},
|
|
|
|
offdisplayPartial : func() {
|
|
|
|
me._group.setVisible(0);
|
2018-01-26 19:06:06 +00:00
|
|
|
#me.getController().offdisplayPartial();
|
2017-12-27 19:51:54 +00:00
|
|
|
},
|
2017-12-31 16:10:52 +00:00
|
|
|
|
|
|
|
# Softkey assigments. For some pages (notably the NEAREST pages)
|
|
|
|
# the MAP softkey is available as key 2:
|
|
|
|
# pg.addMenuItem(2, "MAP", pg, pg.mfd.NavigationMap.mapMenu);
|
|
|
|
|
|
|
|
|
|
|
|
topMenu : func(device, pg, menuitem) {
|
|
|
|
pg.clearMenu();
|
|
|
|
pg.resetMenuColors();
|
|
|
|
pg.addMenuItem(0, "ENGINE", pg, pg.mfd.EIS.engineMenu);
|
|
|
|
pg.addMenuItem(2, "MAP", pg, pg.mfd.NavigationMap.mapMenu);
|
2018-01-26 19:06:06 +00:00
|
|
|
pg.addMenuItem(8, "DCLTR", pg, func(dev, pg, mi) { pg.getController().incrDCLTR(dev, mi); } );
|
2017-12-31 16:10:52 +00:00
|
|
|
#pg.addMenuItem(9, "SHW CHRT", pg); # Optional
|
|
|
|
#pg.addMenuItem(10, "CHKLIST", pg); # Optional
|
|
|
|
device.updateMenus();
|
|
|
|
},
|
|
|
|
|
|
|
|
mapMenu : func(device, pg, menuitem) {
|
|
|
|
pg.clearMenu();
|
|
|
|
pg.resetMenuColors();
|
|
|
|
pg.addMenuItem(0, "TRAFFIC", pg,
|
2018-02-01 22:28:39 +00:00
|
|
|
func(dev, pg, mi) { pg.mfd.NavigationMap.getController().toggleLayer("TFC"); device.updateMenus(); }, # callback
|
2017-12-31 16:10:52 +00:00
|
|
|
func(svg, mi) { pg.mfd.NavigationMap.display_toggle(device, svg, mi, "TFC"); }
|
|
|
|
);
|
|
|
|
|
|
|
|
pg.addMenuItem(1, "PROFILE", pg);
|
|
|
|
pg.addMenuItem(2, "TOPO", pg,
|
2018-02-01 22:28:39 +00:00
|
|
|
func(dev, pg, mi) { pg.mfd.NavigationMap.getController().toggleLayer("STAMEN"); device.updateMenus(); }, # callback
|
2017-12-31 16:10:52 +00:00
|
|
|
func(svg, mi) { pg.mfd.NavigationMap.display_toggle(device, svg, mi, "STAMEN"); }
|
|
|
|
);
|
|
|
|
|
|
|
|
pg.addMenuItem(3, "TERRAIN", pg,
|
2018-02-01 22:28:39 +00:00
|
|
|
func(dev, pg, mi) { pg.mfd.NavigationMap.getController().toggleLayer("STAMEN_terrain"); device.updateMenus(); }, # callback
|
2017-12-31 16:10:52 +00:00
|
|
|
func(svg, mi) { pg.mfd.NavigationMap.display_toggle(device, svg, mi, "STAMEN_terrain"); }
|
|
|
|
);
|
|
|
|
|
2018-02-01 22:28:39 +00:00
|
|
|
pg.addMenuItem(4, "AIRWAYS", pg, func(dev, pg, mi) { pg.mfd.NavigationMap.getController().incrAIRWAYS(dev, mi); } );
|
2017-12-31 16:10:52 +00:00
|
|
|
#pg.addMenuItem(5, "STRMSCP", pg); Optional
|
|
|
|
#pg.addMenuItem(6, "PRECIP", pg); Optional, or NEXRAD
|
|
|
|
#pg.addMenuItem(7, "XM LTNG", pg); Optional, or DL LTNG
|
|
|
|
#pg.addMenuItem(8, "METAR", pg);
|
|
|
|
#pg.addMenuItem(9, "LEGEND", pg); Optional - only available with NEXRAD/XM LTNG/METAR/PROFILE selected
|
|
|
|
pg.addMenuItem(10, "BACK", pg, pg.topMenu); # Or should this just be the next button?
|
|
|
|
device.updateMenus();
|
|
|
|
},
|
|
|
|
|
|
|
|
# Display map toggle softkeys which change color depending
|
|
|
|
# on whether a particular layer is enabled or not.
|
|
|
|
display_toggle : func(device, svg, mi, layer) {
|
|
|
|
var bg_name = sprintf("SoftKey%d-bg",mi.menu_id);
|
2018-01-26 19:06:06 +00:00
|
|
|
if (me.getController().isEnabled(layer)) {
|
2017-12-31 16:10:52 +00:00
|
|
|
device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5);
|
|
|
|
svg.setColor(0.0,0.0,0.0);
|
|
|
|
} else {
|
|
|
|
device.svg.getElementById(bg_name).setColorFill(0.0,0.0,0.0);
|
|
|
|
svg.setColor(1.0,1.0,1.0);
|
|
|
|
}
|
|
|
|
svg.setText(mi.title);
|
|
|
|
svg.setVisible(1); # display function
|
|
|
|
},
|
|
|
|
|
2017-11-24 23:04:46 +00:00
|
|
|
};
|