topo display is now availabl...
|
1 |
var MapTopo = { |
2 |
new : func(device, group) { |
|
3 |
var m = { parents: [ MapTopo ] }; |
|
4 |
m.device = device; |
|
5 |
m.visibility = 0; |
|
faster topo rendering
|
6 |
m.dist_scale = 10; |
7 |
m.radial_scale = 11; |
|
8 |
m.group = group.createChild('group', 'topo') |
|
topo display is now availabl...
|
9 |
.setTranslation((m.device.data.mapview[0] + m.device.data.mapclip.left)/2, 400) |
10 |
.setRotation(m.device.data.orientation.airplane * D2R) |
|
11 |
.setVisible(m.visibility); |
|
faster topo rendering
|
12 |
for (var dist = 0; dist < m.dist_scale; dist += 1) { |
topo display is now availabl...
|
13 |
for (var radial = 0; radial < 11; radial += 1) { |
faster topo rendering
|
14 |
if (radial + dist) |
15 |
m.arc((radial * 10) - 50, (dist * 35) + 10); |
|
16 |
else |
|
17 |
m.path = m.arc((radial * 10) - 50, (dist * 35) + 10).parents[1]._node.getPath(); |
|
topo display is now availabl...
|
18 |
} |
19 |
} |
|
20 |
data.timers.topo_radar = maketimer(0, func { |
|
21 |
var (radial, dist) = [m.radial, m.dist]; |
|
22 |
var geo = greatCircleMove(data.hdg + ((radial * 10) - 50), |
|
23 |
m.delta_radar_dist_nm * dist + m.delta_radar_dist_nm/2); |
|
24 |
var _geodinfo = geodinfo(geo.lat, geo.lon, 10000); |
|
25 |
if (_geodinfo != nil) { |
|
26 |
var diff = _geodinfo[0] * units.altitude.from_m - data.alt; |
|
27 | ||
faster topo rendering
|
28 |
var color = 'rgba(255, 127, 40, 1)'; |
topo display is now availabl...
|
29 |
if (diff > 1000 * units.altitude.from_ft) |
faster topo rendering
|
30 |
color = 'rgba(255, 0, 0, 1)'; |
adds topo alert on map also ...
|
31 |
elsif (diff < 0 and diff > -300 * units.altitude.from_ft) |
32 |
color = sprintf('rgba(255, 127, 40, %f)', 1 + 0.5 * (diff / (300 * units.altitude.from_ft)) ); |
|
topo display is now availabl...
|
33 | |
faster topo rendering
|
34 |
setprop(m.path, radial + m.radial_scale * dist, 'fill', color); |
adds topo alert on map also ...
|
35 |
setprop(m.path, radial + m.radial_scale * dist, 'visible', diff > -300 * units.altitude.from_ft); |
topo display is now availabl...
|
36 |
} |
faster topo rendering
|
37 |
if (m.radial < m.radial_scale - 1) |
topo display is now availabl...
|
38 |
m.radial += 1; |
faster topo rendering
|
39 |
elsif (m.dist < m.dist_scale - 1) { |
topo display is now availabl...
|
40 |
m.dist += 1; |
41 |
m.radial = 0; |
|
42 |
} |
|
43 |
else { |
|
44 |
m.dist = 0; |
|
45 |
m.radial = 0; |
|
46 |
} |
|
47 |
}); |
|
48 |
m.device.data.orientation.radar = 0; |
|
49 |
m.dist = 0; |
|
50 |
m.radial = 0; |
|
faster topo rendering
|
51 |
m.delta_radar_dist_nm = m.device.data['range-nm'] / m.dist_scale; |
topo display is now availabl...
|
52 |
return m; |
53 |
}, |
|
54 | ||
55 |
arc: func(radial, dist) { |
|
56 |
var from_deg = (radial - 5) * D2R; |
|
57 |
var to_deg = (radial + 5) * D2R; |
|
58 |
var (fs1, fc1) = [math.sin(from_deg), math.cos(from_deg)]; |
|
59 |
var dx1 = (math.sin(to_deg) - fs1) * dist; |
|
60 |
var dy1 = (math.cos(to_deg) - fc1) * dist; |
|
61 |
var (fs2, fc2) = [math.sin(to_deg), math.cos(to_deg)]; |
|
62 |
var dx2 = (math.sin(from_deg) - fs2) * (dist + 35); |
|
63 |
var dy2 = (math.cos(from_deg) - fc2) * (dist + 35); |
|
64 | ||
65 |
return me.group.createChild('path', sprintf('arc %-02i@%02i', radial, dist)) |
|
66 |
.moveTo(dist*fs1, -dist*fc1) |
|
67 |
.arcSmallCW(dist, dist, 0, dx1, -dy1) |
|
68 |
.lineTo((dist + 35)*fs2, -(dist + 35)*fc2) |
|
69 |
.arcSmallCW(dist + 35, dist + 35, 0, dx2, -dy2) |
|
70 |
.close() |
|
71 |
.setColorFill(1,0,0,0.75) |
|
72 |
.setVisible(0); |
|
73 |
}, |
|
74 | ||
75 |
setVisible : func (v) { |
|
76 |
if (me.visibility != v) { |
|
77 |
me.visibility = v; |
|
78 |
me.group |
|
79 |
.setRotation(me.device.data.orientation.airplane * D2R) |
|
80 |
.setVisible(v); |
|
81 |
} |
|
82 |
if (me.visibility) |
|
83 |
data.timers.topo_radar.start(); |
|
84 |
}, |
|
85 | ||
86 |
off : func { |
|
87 |
me.setVisible(0); |
|
88 |
me.group.removeAllChildren(); |
|
89 |
}, |
|
90 | ||
91 |
update : func { |
|
92 |
if (me.visibility) { |
|
93 |
me.group.setRotation(me.device.data.orientation.airplane * D2R); |
|
faster topo rendering
|
94 |
me.delta_radar_dist_nm = me.device.data['range-nm'] / me.dist_scale; |
topo display is now availabl...
|
95 |
} |
96 |
}, |
|
97 |
}; |