zkv1000 / Nasal / map.nas /
Newer Older
136 lines | 5.627kb
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
1
var mapClass = {
2
    new : func (device) {
3
        var m = { parents : [ mapClass ] };
4
        m.device = device;
5

            
6
        m.device.data.mapview = [
7
            m.device.display.display.get('view[0]'),
8
            m.device.display.display.get('view[1]')
9
        ];
10
        m.device.data.mapsize = [
11
            m.device.display.display.get('size[0]'),
12
            m.device.display.display.get('size[1]')
13
        ];
14
        m.device.data.zoom = 10;
15
        m.device.data.orientation = {
16
            text: 'NORTH UP',
17
            map: 0,
18
            airplane: data.hdg,
display orientation type on ...
Sébastien MARQUE authored on 2017-05-21
19
            fontsize: m.device.role == 'MFD' ? 16 : 12,
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
20
        };
21
        m.changeZoom();
separates maps code
Sébastien MARQUE authored on 2017-05-11
22

            
23
        m.visibility = m.device.role == 'MFD';
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
24
        
25
        m.group = m.device.display.display.createGroup()
26
            .set('clip',
27
                    'rect('
28
                        ~ m.device.data.mapclip.top ~','
29
                        ~ m.device.data.mapclip.right ~','
30
                        ~ m.device.data.mapclip.bottom ~','
31
                        ~ m.device.data.mapclip.left ~')')
32
            .setCenter(
33
                (m.device.data.mapclip.right + m.device.data.mapclip.left) / 2,
34
                (m.device.data.mapclip.bottom + m.device.data.mapclip.top) / 2);
35

            
separates maps code
Sébastien MARQUE authored on 2017-05-11
36
        m.layers = {};
37
        m.layers.tiles = MapTiles.new(m.device, m.group);
topo display is now availabl...
Sébastien MARQUE authored on 2020-06-14
38
        if (m.device.role == 'MFD')
39
            m.layers.topo = MapTopo.new(m.device, m.group);
adds route display on map
Sébastien MARQUE authored on 2017-05-11
40
        m.layers.route = MapRoute.new(m.device, m.group);
separates maps code
Sébastien MARQUE authored on 2017-05-11
41
        m.layers.navaids = MapNavaids.new(m.device, m.group);
removes traffic from PFD ins...
Sébastien MARQUE authored on 2020-06-14
42
        if (m.device.role == 'MFD')
43
            m.layers.tcas = MapTcas.new(m.device, m.group);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
44

            
display orientation type on ...
Sébastien MARQUE authored on 2017-05-21
45
        m.mapOrientation = m.device.display.display.createGroup('MapOrientation')
46
            .setVisible(m.visibility);
47
        m.mapOrientation.createChild('path', 'MapOrientation-bg')
48
            .rect(
49
                m.device.data.mapclip.right - size(m.device.data.orientation) * (m.device.data.orientation.fontsize + 2),
50
                m.device.data.mapclip.top + 2,
51
                size(m.device.data.orientation) * (m.device.data.orientation.fontsize + 2),
52
                m.device.data.orientation.fontsize + 2)
53
            .setColor(1,1,1)
54
            .setColorFill(0,0,0);
55
        m.mapOrientation_text = m.mapOrientation.createChild('text', 'MapOrientation-text')
56
            .setFontSize(m.device.data.orientation.fontsize)
57
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
58
            .setTranslation(
59
                m.device.data.mapclip.right - size(m.device.data.orientation) * (m.device.data.orientation.fontsize + 2),
60
                m.device.data.mapclip.top + m.device.data.orientation.fontsize + 2)
61
            .setColor(1,1,1)
62
            .setColorFill(1,1,1)
63
            .setText(m.device.data.orientation.text);
64

            
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
65
#        m.device.display.display.createGroup().createChild('path')
66
#            .setColor(1,0,0)
67
#            .setColorFill(1,0,0)
68
#            .setStrokeLineWidth(2)
69
#            .moveTo(
70
#                m.device.data.mapclip.left + (m.device.data.mapclip.right-m.device.data.mapclip.left)/2,
71
#                m.device.data.mapclip.top +50)
72
#            .vertTo(
73
#                m.device.data.mapclip.bottom -50)
74
#            .close()
75
#            .moveTo(
76
#                m.device.data.mapclip.left +50,
77
#                m.device.data.mapclip.top + (m.device.data.mapclip.bottom-m.device.data.mapclip.top)/2)
78
#            .horizTo(
79
#                m.device.data.mapclip.right-50)
80
#            .close();
81

            
82
        return m;
83
    },
poweroff improved
Sébastien MARQUE authored on 2020-05-16
84
    off: func {
85
        me.mapOrientation.setVisible(0);
86
        foreach (var layer; keys(me.layers)) {
87
            me.layers[layer].off();
88
            delete(me.layers, layer);
89
        }
90
    },
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
91
    changeZoom : func (d = 0) {
92
        me.device.data.zoom = math.max(2, math.min(19, me.device.data.zoom + d));
93
        me.device.data['range-nm'] = me.device.display.display.get('view[1]') / 2 * 84.53 * math.cos(data.lat) / math.pow(2, me.device.data.zoom);
adjust scale factor for comp...
Sébastien MARQUE authored on 2017-05-14
94
        me.device.data['range-factor'] = math.pow(2,13 - me.device.data.zoom) * 1.45;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
95
    },
96
    update : func {
97
        if (me.device.data.orientation.text == 'NORTH UP') {
98
            me.device.data.orientation.map = 0;
99
            me.device.data.orientation.airplane = data.hdg;
100
        }
101
        elsif (me.device.data.orientation.text == 'TRK UP') {
102
            if (data.wow) {
103
                me.device.data.orientation.map = -data.hdg;
104
                me.device.data.orientation.airplane = data.hdg;
105
            }
106
            else {
107
                var track = getprop('/orientation/track-deg');
108
                me.device.data.orientation.map = -track;
109
                me.device.data.orientation.airplane = data.hdg;
110
            }
111
        }
112
        elsif (me.device.data.orientation.text == 'DTK UP') {
fix desired track map rotati...
Sébastien MARQUE authored on 2017-05-11
113
            var desired = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
114
            me.device.data.orientation.map = -desired;
115
            me.device.data.orientation.airplane = data.hdg;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
116
        }
117
        elsif (me.device.data.orientation.text == 'HDG UP') {
118
            me.device.data.orientation.map = -data.hdg;
119
            me.device.data.orientation.airplane = data.hdg;
120
        }
121

            
122
        me.group.setRotation(me.device.data.orientation.map * D2R);
123

            
display orientation type on ...
Sébastien MARQUE authored on 2017-05-21
124
        me.mapOrientation_text
125
            .setText(me.device.data.orientation.text);
126

            
separates maps code
Sébastien MARQUE authored on 2017-05-11
127
        foreach (var l; keys(me.layers))
128
            me.layers[l].update();
implements the ND from Extra...
Sébastien MARQUE authored on 2017-04-17
129
    },
130
    setVisible : func (v) {
separates maps code
Sébastien MARQUE authored on 2017-05-11
131
        me.visibility = v;
132
        foreach (var l; keys(me.layers))
133
            me.layers[l].setVisible(v);
display orientation type on ...
Sébastien MARQUE authored on 2017-05-21
134
        me.mapOrientation.setVisible(v);
navaids displayed with corre...
Sébastien MARQUE authored on 2017-04-18
135
    },
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
136
};