zkv1000 / Nasal / map.nas /
Newer Older
139 lines | 5.604kb
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

            
cosmetic
Sébastien MARQUE authored on 2021-06-14
36
        m.layers = {
37
            tiles   : MapTiles.new(m.device, m.group),
38
            route   : MapRoute.new(m.device, m.group),
39
            navaids : MapNavaids.new(m.device, m.group),
40
        };
just a little re-order
Sébastien MARQUE authored on 2021-03-30
41
        if (m.device.role == 'MFD') {
cosmetic
Sébastien MARQUE authored on 2021-06-14
42
            m.layers.tcas  = MapTcas.new(m.device, m.group);
43
            m.layers.topo  = MapTopo.new(m.device, m.group);
add track display
Sébastien MARQUE authored on 2021-05-13
44
            m.layers.track = MapTrack.new(m.device, m.group);
just a little re-order
Sébastien MARQUE authored on 2021-03-30
45
        }
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
46

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

            
close issue with misplacing ...
Sébastien MARQUE authored on 2020-06-22
67
        data.lat = getprop('/position/latitude-deg');
68
        m.changeZoom();
69

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

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

            
125
        me.group.setRotation(me.device.data.orientation.map * D2R);
126

            
display orientation type on ...
Sébastien MARQUE authored on 2017-05-21
127
        me.mapOrientation_text
128
            .setText(me.device.data.orientation.text);
129

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