prepare for adopting MapStructure
[fg:hoorays-fgdata.git] / Nasal / canvas / map / VOR.symbol
1 # Class things:
2 var name = 'VOR';
3 var parents = [DotSym];
4 var __self__ = caller(0)[0];
5 DotSym.makeinstance( name, __self__ );
6
7 var element_type = "group"; # we want a group, becomes "me.element"
8 var inited = 0; # this allows us to track whether draw() is an init() or an update()
9 var range_vor = nil; # two elements that get drawn when needed
10 var radial_vor = nil; # if one is nil, the other has to be nil
11
12 var draw = func {
13         if (me.inited) {
14                 # Update
15                 if (me.controller.isActive(me.model)) {
16                         if (me.range_vor == nil) {
17                                 var rangeNm = me.controller.query_range();
18                                 # print("VOR is tuned:", me.model.id);
19                                 var radius = (me.model.range_nm/rangeNm)*345;
20                                 me.range_vor = me.element.createChild("path")
21                                         .moveTo(-radius,0)
22                                         .arcSmallCW(radius,radius,0,2*radius,0)
23                                         .arcSmallCW(radius,radius,0,-2*radius,0)
24                                         .setStrokeLineWidth(3)
25                                         .setStrokeDashArray([5, 15, 5, 15, 5])
26                                         .setColor(0,1,0);
27
28                                 var course = controller.get_tuned_course(me.model.frequency/100);
29                                 vor_grp.createChild("path")
30                                         .moveTo(0,-radius)
31                                         .vert(2*radius)
32                                         .setStrokeLineWidth(3)
33                                         .setStrokeDashArray([15, 5, 15, 5, 15])
34                                         .setColor(0,1,0)
35                                         .setRotation(course*D2R);
36                                 icon_vor.setColor(0,1,0);
37                         }
38                         me.range_vor.show();
39                         me.radial_vor.show();
40                 } else {
41                         me.range_vor.hide();
42                         me.radial_vor.hide();
43                 }
44         } else # Init
45         me.element.createChild("path")
46                 .moveTo(-15,0)
47                 .lineTo(-7.5,12.5)
48                 .lineTo(7.5,12.5)
49                 .lineTo(15,0)
50                 .lineTo(7.5,-12.5)
51                 .lineTo(-7.5,-12.5)
52                 .close()
53                 .setStrokeLineWidth(3)
54                 .setColor(0,0.6,0.85);
55 };
56