zkv1000 / Nasal / map.nas /
Newer Older
125 lines | 5.24kb
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);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
40

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

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

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

            
111
        me.group.setRotation(me.device.data.orientation.map * D2R);
112

            
display orientation type on ...
Sébastien MARQUE authored on 2017-05-21
113
        me.mapOrientation_text
114
            .setText(me.device.data.orientation.text);
115

            
separates maps code
Sébastien MARQUE authored on 2017-05-11
116
        foreach (var l; keys(me.layers))
117
            me.layers[l].update();
implements the ND from Extra...
Sébastien MARQUE authored on 2017-04-17
118
    },
119
    setVisible : func (v) {
separates maps code
Sébastien MARQUE authored on 2017-05-11
120
        me.visibility = v;
121
        foreach (var l; keys(me.layers))
122
            me.layers[l].setVisible(v);
display orientation type on ...
Sébastien MARQUE authored on 2017-05-21
123
        me.mapOrientation.setVisible(v);
navaids displayed with corre...
Sébastien MARQUE authored on 2017-04-18
124
    },
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
125
};