zkv1000 / Nasal / map.nas /
Newer Older
100 lines | 3.9kb
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,
19
        };
20
        m.changeZoom();
separates maps code
Sébastien MARQUE authored on 2017-05-11
21

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

            
separates maps code
Sébastien MARQUE authored on 2017-05-11
35
        m.layers = {};
36
        m.layers.tiles = MapTiles.new(m.device, m.group);
adds route display on map
Sébastien MARQUE authored on 2017-05-11
37
        m.layers.route = MapRoute.new(m.device, m.group);
separates maps code
Sébastien MARQUE authored on 2017-05-11
38
        m.layers.navaids = MapNavaids.new(m.device, m.group);
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
39

            
40
#        m.device.display.display.createGroup().createChild('path')
41
#            .setColor(1,0,0)
42
#            .setColorFill(1,0,0)
43
#            .setStrokeLineWidth(2)
44
#            .moveTo(
45
#                m.device.data.mapclip.left + (m.device.data.mapclip.right-m.device.data.mapclip.left)/2,
46
#                m.device.data.mapclip.top +50)
47
#            .vertTo(
48
#                m.device.data.mapclip.bottom -50)
49
#            .close()
50
#            .moveTo(
51
#                m.device.data.mapclip.left +50,
52
#                m.device.data.mapclip.top + (m.device.data.mapclip.bottom-m.device.data.mapclip.top)/2)
53
#            .horizTo(
54
#                m.device.data.mapclip.right-50)
55
#            .close();
56

            
57
        return m;
58
    },
59
    changeZoom : func (d = 0) {
60
        me.device.data.zoom = math.max(2, math.min(19, me.device.data.zoom + d));
61
        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);
62
        me.device.data['range-factor'] = math.pow(2,13 - me.device.data.zoom) * 1.6875;
63
    },
64
    update : func {
65
        if (me.device.data.orientation.text == 'NORTH UP') {
66
            me.device.data.orientation.map = 0;
67
            me.device.data.orientation.airplane = data.hdg;
68
        }
69
        elsif (me.device.data.orientation.text == 'TRK UP') {
70
            if (data.wow) {
71
                me.device.data.orientation.map = -data.hdg;
72
                me.device.data.orientation.airplane = data.hdg;
73
            }
74
            else {
75
                var track = getprop('/orientation/track-deg');
76
                me.device.data.orientation.map = -track;
77
                me.device.data.orientation.airplane = data.hdg;
78
            }
79
        }
80
        elsif (me.device.data.orientation.text == 'DTK UP') {
fix desired track map rotati...
Sébastien MARQUE authored on 2017-05-11
81
            var desired = getprop('/instrumentation/gps/wp/wp[1]/desired-course-deg');
82
            me.device.data.orientation.map = -desired;
83
            me.device.data.orientation.airplane = data.hdg;
massive code reorganisation ...
Sébastien MARQUE authored on 2017-05-01
84
        }
85
        elsif (me.device.data.orientation.text == 'HDG UP') {
86
            me.device.data.orientation.map = -data.hdg;
87
            me.device.data.orientation.airplane = data.hdg;
88
        }
89

            
90
        me.group.setRotation(me.device.data.orientation.map * D2R);
91

            
separates maps code
Sébastien MARQUE authored on 2017-05-11
92
        foreach (var l; keys(me.layers))
93
            me.layers[l].update();
implements the ND from Extra...
Sébastien MARQUE authored on 2017-04-17
94
    },
95
    setVisible : func (v) {
separates maps code
Sébastien MARQUE authored on 2017-05-11
96
        me.visibility = v;
97
        foreach (var l; keys(me.layers))
98
            me.layers[l].setVisible(v);
navaids displayed with corre...
Sébastien MARQUE authored on 2017-04-18
99
    },
adds Map on MFD
Sébastien MARQUE authored on 2017-03-20
100
};