zkv1000 / Nasal / maps / topo.nas /
Newer Older
95 lines | 3.446kb
topo display is now availabl...
Sébastien MARQUE authored on 2020-06-14
1
var MapTopo = {
2
    new : func(device, group) {
3
        var m = { parents: [ MapTopo ] };
4
        m.device = device;
5
        m.visibility = 0;
6
        m.group = group.createChild('map', 'topo')
7
            .setTranslation((m.device.data.mapview[0] + m.device.data.mapclip.left)/2, 400)
8
            .setRotation(m.device.data.orientation.airplane * D2R)
9
            .setVisible(m.visibility);
10
        m.radar = [];
11
        for (var dist = 0; dist < 10; dist += 1) {
12
            append(m.radar, []);
13
            for (var radial = 0; radial < 11; radial += 1) {
14
                append(m.radar[dist], m.arc((radial * 10) - 50, (dist * 35) + 10));
15
            }
16
        }
17
        data.timers.topo_radar = maketimer(0, func {
18
            var (radial, dist) = [m.radial, m.dist];
19
            var geo = greatCircleMove(data.hdg + ((radial * 10) - 50),
20
                                      m.delta_radar_dist_nm * dist + m.delta_radar_dist_nm/2);
21
            var _geodinfo = geodinfo(geo.lat, geo.lon, 10000);
22
            if (_geodinfo != nil) {
23
                var diff = _geodinfo[0] * units.altitude.from_m - data.alt;
24

            
25
                var color = [1, 0.5, 0.16, 1];
26
                if (diff > 1000 * units.altitude.from_ft)
27
                    color = [1, 0, 0, 1];
28

            
29
                m.radar[dist][radial]
30
                    .setColorFill(color)
31
                    .setVisible(diff > 0);
32
            }
33
            if    (m.radial < 10) # size(m.radar[m.dist]) - 1
34
                m.radial += 1;
35
            elsif (m.dist   <  9) { # size(m.radar) -1
36
                m.dist   += 1;
37
                m.radial = 0;
38
            }
39
            else {
40
                m.dist = 0;
41
                m.radial = 0;
42
            }
43
        });
44
        m.device.data.orientation.radar = 0;
45
        m.dist = 0;
46
        m.radial = 0;
47
        m.delta_radar_dist_nm = m.device.data['range-nm'] / size(m.radar);
48
        return m;
49
    },
50

            
51
    arc: func(radial, dist) {
52
        var from_deg = (radial - 5) * D2R;
53
        var to_deg = (radial + 5) * D2R;
54
        var (fs1, fc1) = [math.sin(from_deg), math.cos(from_deg)];
55
        var dx1 = (math.sin(to_deg) - fs1) * dist;
56
        var dy1 = (math.cos(to_deg) - fc1) * dist;
57
        var (fs2, fc2) = [math.sin(to_deg), math.cos(to_deg)];
58
        var dx2 = (math.sin(from_deg) - fs2) * (dist + 35);
59
        var dy2 = (math.cos(from_deg) - fc2) * (dist + 35);
60

            
61
        return me.group.createChild('path', sprintf('arc %-02i@%02i', radial, dist))
62
            .moveTo(dist*fs1, -dist*fc1)
63
            .arcSmallCW(dist, dist, 0, dx1, -dy1)
64
            .lineTo((dist + 35)*fs2, -(dist + 35)*fc2)
65
            .arcSmallCW(dist + 35, dist + 35, 0, dx2, -dy2)
66
            .close()
67
            .setColorFill(1,0,0,0.75)
68
            .setVisible(0);
69
    },
70

            
71
    setVisible : func (v) {
72
        if (me.visibility != v) {
73
            me.visibility = v;
74
            me.group
75
                .setRotation(me.device.data.orientation.airplane * D2R)
76
                .setVisible(v);
77
        }
78
        if (me.visibility)
79
            data.timers.topo_radar.start();
80
        else
81
            data.timers.topo_radar.stop();
82
    },
83

            
84
    off : func {
85
        me.setVisible(0);
86
        me.group.removeAllChildren();
87
    },
88

            
89
    update : func {
90
        if (me.visibility) {
91
            me.group.setRotation(me.device.data.orientation.airplane * D2R);
92
            me.delta_radar_dist_nm = me.device.data['range-nm'] / size(me.radar);
93
        }
94
    },
95
};