Debian Codegraph @

Nasal/canvas/map/RWY.symbol

raw
1 # See: http://wiki.flightgear.org/MapStructure
2 # Class things:
3 var name = 'RWY';
4 var parents = [DotSym];
5 var __self__ = caller(0)[0];
6 DotSym.makeinstance( name, __self__ );
7
8 SymbolLayer.get(name).df_style = {
9 surface_color: canvas.SURFACECOLORS,
10 text_alignment: "center-center",
11 text_bgcolor: [0,0,0,0],
12 text_color: [0,0.6,0.85],
13 text_mode: canvas.Text.TEXT,
14 text_padding: 0,
15 text_size: 14,
16 text_font: "LiberationFonts/LiberationSans-Regular.ttf",
17 show_labels: 0,
18 };
19
20 var element_type = "group"; # we want a group, becomes "me.element"
21 var rwys = nil;
22
23 var SURFACECOLORS = {
24 0 : { type: "fallback", r:0.0, g:0.0, b:0.0 },
25 1 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
26 2 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
27 3 : { type: "turf", r:0.2, g:0.5, b:0.2 },
28 4 : { type: "dirt", r:0.4, g:0.3, b:0.3 },
29 5 : { type: "gravel", r:0.35, g:0.3, b:0.3 },
30 12 : { type: "lakebed", r:0.4, g:0.4, b:0.3 },
31 13 : { type: "water", r:0.3, g:0.4, b:0.6 },
32 14 : { type: "snow", r:0.8, g:0.8, b:0.9 },
33 15 : { type: "transparent", r:0.0, g:0.0, b:0.0 },
34 20 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
35 21 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
36 22 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
37 23 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
38 24 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
39 25 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
40 26 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
41 27 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
42 28 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
43 29 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
44 30 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
45 31 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
46 32 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
47 33 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
48 34 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
49 35 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
50 36 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
51 37 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
52 38 : { type: "asphalt", r:0.2, g:0.2, b:0.2 },
53 50 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
54 51 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
55 52 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
56 53 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
57 54 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
58 55 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
59 56 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
60 57 : { type: "concrete", r:0.3, g:0.3, b:0.3 },
61 };
62
63
64 var init = func {
65 var apt=airportinfo(me.model.id);
66 var rwys = apt.runwaysWithoutReciprocals();
67
68 foreach (var rw1; rwys)
69 {
70 var clr = me.style.surface_color[rw1.surface];
71 if (clr == nil) { clr = SURFACECOLORS[rw1.surface]};
72 if (clr == nil) { clr = SURFACECOLORS[0]};
73
74 var icon_rw =
75 me.element.createChild("path", "runway-" ~ rw1.id)
76 .setStrokeLineWidth(0.5)
77 .setColor(1.0,1.0,1.0)
78 .setColorFill(clr.r, clr.g, clr.b);
79
80 var rwy1 = Runway.new(rw1);
81 var beg_thr = rwy1.pointOffCenterline(rw1.threshold);
82 var beg_thr1 = rwy1.pointOffCenterline(rw1.threshold, 0.5 * rw1.width);
83 var beg_thr2 = rwy1.pointOffCenterline(rw1.threshold, -0.5 * rw1.width);
84 var beg1 = rwy1.pointOffCenterline(0, 0.5 * rw1.width);
85 var beg2 = rwy1.pointOffCenterline(0, -0.5 * rw1.width);
86
87 var rw2 = rw1.reciprocal;
88 var rwy2 = Runway.new(rw2);
89 var end_thr = rwy2.pointOffCenterline(rw2.threshold);
90 var end_thr1 = rwy2.pointOffCenterline(rw2.threshold, 0.5 * rw2.width);
91 var end_thr2 = rwy2.pointOffCenterline(rw2.threshold, -0.5 * rw2.width);
92 var end1 = rwy2.pointOffCenterline(0, 0.5 * rw2.width);
93 var end2 = rwy2.pointOffCenterline(0, -0.5 * rw2.width);
94
95 icon_rw.setDataGeo
96 (
97 [ canvas.Path.VG_MOVE_TO,
98 canvas.Path.VG_LINE_TO,
99 canvas.Path.VG_LINE_TO,
100 canvas.Path.VG_LINE_TO,
101 canvas.Path.VG_CLOSE_PATH ],
102 [ beg1[0], beg1[1],
103 beg2[0], beg2[1],
104 end1[0], end1[1],
105 end2[0], end2[1] ]
106 );
107
108 var icon_cl =
109 me.element.createChild("path", "centerline")
110 .setStrokeLineWidth(0.5)
111 .setColor(1,1,1)
112 .setStrokeDashArray([15, 10]);
113
114 icon_cl.setDataGeo
115 (
116 [ canvas.Path.VG_MOVE_TO,
117 canvas.Path.VG_LINE_TO ],
118 [ beg_thr[0], beg_thr[1],
119 end_thr[0], end_thr[1] ]
120 );
121
122 var icon_thr =
123 me.element.createChild("path", "threshold")
124 .setStrokeLineWidth(1.5)
125 .setColor(1,1,1);
126
127 icon_thr.setDataGeo
128 (
129 [ canvas.Path.VG_MOVE_TO,
130 canvas.Path.VG_LINE_TO,
131 canvas.Path.VG_MOVE_TO,
132 canvas.Path.VG_LINE_TO ],
133 [ beg_thr1[0], beg_thr1[1],
134 beg_thr2[0], beg_thr2[1],
135 end_thr1[0], end_thr1[1],
136 end_thr2[0], end_thr2[1] ]
137 );
138
139 if (me.style.show_labels == 1) {
140 var coord1 = geo.Coord.new();
141 coord1.set_latlon(rw1.lat, rw1.lon);
142 coord1.apply_course_distance(rw1.heading, - 50.0);
143
144 var coord2 = geo.Coord.new();
145 coord2.set_latlon(rw2.lat, rw2.lon);
146 coord2.apply_course_distance(rw2.heading, - 50.0);
147
148 var txt1 = me.element.createChild("text", "rwy1label")
149 .setText(rw1.id)
150 .setGeoPosition(coord1.lat(), coord1.lon())
151 .setFont(me.style.text_font)
152 .setFontSize(me.style.text_size)
153 .setAlignment(me.style.text_alignment)
154 .setPadding(me.style.text_padding)
155 .setDrawMode(me.style.text_mode)
156 .setColor(me.style.text_color)
157 .setColorFill(me.style.text_bgcolor);
158
159 var txt1 = me.element.createChild("text", "rwy2label")
160 .setText(rw2.id)
161 .setGeoPosition(coord2.lat(), coord2.lon())
162 .setFont(me.style.text_font)
163 .setFontSize(me.style.text_size)
164 .setAlignment(me.style.text_alignment)
165 .setPadding(me.style.text_padding)
166 .setDrawMode(me.style.text_mode)
167 .setColor(me.style.text_color)
168 .setColorFill(me.style.text_bgcolor);
169 }
170 }
171
172 #draw helipads
173 foreach(var hp; keys(apt.helipads))
174 {
175 var hp = apt.runway(hp);
176 var clr = me.style.surface_color[hp.surface];
177 if (clr == nil) { clr = SURFACECOLORS[hp.surface]};
178 if (clr == nil) { clr = SURFACECOLORS[0]};
179
180 var icon_hp =
181 me.element.createChild("path", "helipad-" ~ hp.id)
182 .setStrokeLineWidth(0.5)
183 .setColor(1.0,1.0,1.0)
184 .setColorFill(clr.r, clr.g, clr.b);
185
186 var heli = Runway.new(hp);
187 var p1 = heli.pointOffCenterline(0.5 * hp.length, 0.5 * hp.width);
188 var p2 = heli.pointOffCenterline(0.5 * hp.length, -0.5 * hp.width);
189 var p3 = heli.pointOffCenterline(-0.5 * hp.length, -0.5 * hp.width);
190 var p4 = heli.pointOffCenterline(-0.5 * hp.length, 0.5 * hp.width);
191
192 icon_hp.setDataGeo
193 (
194 [ canvas.Path.VG_MOVE_TO,
195 canvas.Path.VG_LINE_TO,
196 canvas.Path.VG_LINE_TO,
197 canvas.Path.VG_LINE_TO,
198 canvas.Path.VG_CLOSE_PATH ],
199 [ p1[0], p1[1],
200 p2[0], p2[1],
201 p3[0], p3[1],
202 p4[0], p4[1] ]
203 );
204
205 if (me.style.show_labels == 1) {
206 var coord1 = geo.Coord.new();
207 coord1.set_latlon(rw1.lat, rw1.lon);
208 coord1.apply_course_distance(rw1.heading, - 50.0);
209
210 var txt1 = me.element.createChild("text", "hplabel")
211 .setText(hp.id)
212 .setGeoPosition(coord1.lat(), coord1.lon())
213 .setFont(me.style.text_font)
214 .setFontSize(me.style.text_size)
215 .setAlignment(me.style.text_alignment)
216 .setPadding(me.style.text_padding)
217 .setDrawMode(me.style.text_mode)
218 .setColor(me.style.text_color)
219 .setColorFill(me.style.text_bgcolor);
220 }
221 }
222 };
223 var draw = func;