zkv1000 / Nasal / map.nas /
Newer Older
133 lines | 5.491kb
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);
adds route display on map
Sébastien MARQUE authored on 2017-05-11
38
        m.layers.route = MapRoute.new(m.device, m.group);
separates maps code
Sébastien MARQUE authored on 2017-05-11
39
        m.layers.navaids = MapNavaids.new(m.device, m.group);
add TCAS
Sébastien MARQUE authored on 2017-12-21
40
        m.layers.tcas = MapTcas.new(m.device, m.group);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
41

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

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

            
79
        return m;
80
    },
poweroff improved
Sébastien MARQUE authored on 2020-05-16
81
    off: func {
82
        me.mapOrientation.setVisible(0);
83
        foreach (var layer; keys(me.layers)) {
84
            me.layers[layer].off();
85
            delete(me.layers, layer);
86
        }
87
    },
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
88
    changeZoom : func (d = 0) {
89
        me.device.data.zoom = math.max(2, math.min(19, me.device.data.zoom + d));
90
        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
91
        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
92
    },
93
    update : func {
94
        if (me.device.data.orientation.text == 'NORTH UP') {
95
            me.device.data.orientation.map = 0;
96
            me.device.data.orientation.airplane = data.hdg;
97
        }
98
        elsif (me.device.data.orientation.text == 'TRK UP') {
99
            if (data.wow) {
100
                me.device.data.orientation.map = -data.hdg;
101
                me.device.data.orientation.airplane = data.hdg;
102
            }
103
            else {
104
                var track = getprop('/orientation/track-deg');
105
                me.device.data.orientation.map = -track;
106
                me.device.data.orientation.airplane = data.hdg;
107
            }
108
        }
109
        elsif (me.device.data.orientation.text == 'DTK UP') {
fix desired track map rotati...
Sébastien MARQUE authored on 2017-05-11
110
            var desired = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
111
            me.device.data.orientation.map = -desired;
112
            me.device.data.orientation.airplane = data.hdg;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
113
        }
114
        elsif (me.device.data.orientation.text == 'HDG UP') {
115
            me.device.data.orientation.map = -data.hdg;
116
            me.device.data.orientation.airplane = data.hdg;
117
        }
118

            
119
        me.group.setRotation(me.device.data.orientation.map * D2R);
120

            
display orientation type on ...
Sébastien MARQUE authored on 2017-05-21
121
        me.mapOrientation_text
122
            .setText(me.device.data.orientation.text);
123

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