Debian Codegraph @

gui/dialogs/map-canvas.xml

raw symbols SCIP
1 <?xml version="1.0"?>
2
3 <PropertyList>
4 <name>map-canvas</name>
5 <layout>vbox</layout>
6 <resizable>true</resizable>
7 <default-padding>3</default-padding>
8
9 <color>
10 <alpha type="float">1.0</alpha>
11 </color>
12
13 <nasal>
14 <open><![CDATA[
15 var self = cmdarg();
16 var listeners = [];
17 var setTransparency = func(updateDialog){
18 var alpha = (getprop("/sim/gui/dialogs/map-canvas/transparent") or 0);
19 self.getNode("color/alpha").setValue(1-alpha*0.3);
20 var n = props.Node.new({ "dialog-name": "map-canvas" });
21 if (updateDialog)
22 {
23 fgcommand("dialog-close", n);
24 fgcommand("dialog-show", n);
25 }
26 }
27 setTransparency(0);
28
29 ]]></open>
30
31 <close><![CDATA[
32 TestMap.del();
33 foreach (var l; listeners)
34 removelistener(l);
35 setsize(listeners, 0);
36 ]]></close>
37 </nasal>
38
39 <group>
40 <layout>hbox</layout>
41 <default-padding>1</default-padding>
42
43 <text>
44 <label>Map (Canvas)</label>
45 </text>
46
47 <empty><stretch>1</stretch></empty>
48
49 <button>
50 <legend>X</legend>
51 <key>Esc</key>
52 <pref-width>20</pref-width>
53 <pref-height>20</pref-height>
54 <binding>
55 <command>dialog-close</command>
56 </binding>
57 </button>
58 </group>
59
60 <hrule/>
61
62 <group>
63 <layout>hbox</layout>
64 <stretch>true</stretch>
65 <halign>fill</halign>
66
67 <!-- sidebar -->
68 <group>
69 <layout>vbox</layout>
70 <halign>left</halign>
71
72 <text>
73 <label>Display:</label>
74 </text>
75
76 <checkbox>
77 <label>Airports</label>
78 <halign>left</halign>
79 <property>/sim/gui/dialogs/map-canvas/draw-APT</property>
80 <live>true</live>
81 <binding>
82 <command>dialog-apply</command>
83 </binding>
84 <binding>
85 <command>property-toggle</command>
86 </binding>
87 </checkbox>
88
89 <checkbox>
90 <label>Fixes</label>
91 <halign>left</halign>
92 <property>/sim/gui/dialogs/map-canvas/draw-FIX</property>
93 <live>true</live>
94 <binding>
95 <command>dialog-apply</command>
96 </binding>
97 <binding>
98 <command>property-toggle</command>
99 </binding>
100 </checkbox>
101
102 <checkbox>
103 <label>VORs</label>
104 <halign>left</halign>
105 <property>/sim/gui/dialogs/map-canvas/draw-VOR</property>
106 <live>true</live>
107 <binding>
108 <command>dialog-apply</command>
109 </binding>
110 <binding>
111 <command>property-toggle</command>
112 </binding>
113 </checkbox>
114
115 <checkbox>
116 <label>DMEs</label>
117 <halign>left</halign>
118 <property>/sim/gui/dialogs/map-canvas/draw-DME</property>
119 <live>true</live>
120 <binding>
121 <command>dialog-apply</command>
122 </binding>
123 <binding>
124 <command>property-toggle</command>
125 </binding>
126 </checkbox>
127
128 <checkbox>
129 <label>NDBs</label>
130 <halign>left</halign>
131 <property>/sim/gui/dialogs/map-canvas/draw-NDB</property>
132 <live>true</live>
133 <binding>
134 <command>dialog-apply</command>
135 </binding>
136 <binding>
137 <command>property-toggle</command>
138 </binding>
139 </checkbox>
140
141 <checkbox>
142 <label>Route</label>
143 <halign>left</halign>
144 <property>/sim/gui/dialogs/map-canvas/draw-RTE</property>
145 <live>true</live>
146 <binding>
147 <command>dialog-apply</command>
148 </binding>
149 <binding>
150 <command>property-toggle</command>
151 </binding>
152 </checkbox>
153
154 <checkbox>
155 <label>Waypoints</label>
156 <halign>left</halign>
157 <property>/sim/gui/dialogs/map-canvas/draw-WPT</property>
158 <live>true</live>
159 <binding>
160 <command>dialog-apply</command>
161 </binding>
162 <binding>
163 <command>property-toggle</command>
164 </binding>
165 </checkbox>
166
167 <checkbox>
168 <label>APS</label>
169 <halign>left</halign>
170 <property>/sim/gui/dialogs/map-canvas/draw-APS</property>
171 <live>true</live>
172 <binding>
173 <command>dialog-apply</command>
174 </binding>
175 <binding>
176 <command>property-toggle</command>
177 </binding>
178 </checkbox>
179
180
181 <!--
182 <button>
183 <legend>Airways</legend>
184 <pref-width>100</pref-width>
185 </button>
186 -->
187
188 <checkbox>
189 <label>Traffic</label>
190 <halign>left</halign>
191 <property>/sim/gui/dialogs/map-canvas/draw-TFC</property>
192 <live>true</live>
193 <binding>
194 <command>dialog-apply</command>
195 </binding>
196 <binding>
197 <command>property-toggle</command>
198 </binding>
199 </checkbox>
200
201 <!--
202 <button>
203 <legend>Obstacles</legend>
204 <pref-width>100</pref-width>
205 </button>
206 -->
207
208 <checkbox>
209 <label>Data</label>
210 <halign>left</halign>
211 <property>/sim/gui/dialogs/map-canvas/draw-data</property>
212 <live>true</live>
213 <binding>
214 <command>dialog-apply</command>
215 </binding>
216 <binding>
217 <command>property-toggle</command>
218 </binding>
219 </checkbox>
220
221 <checkbox>
222 <label>Flight History</label>
223 <halign>left</halign>
224 <property>/sim/gui/dialogs/map-canvas/draw-FLT</property>
225 <live>true</live>
226 <binding>
227 <command>dialog-apply</command>
228 </binding>
229 <binding>
230 <command>property-toggle</command>
231 </binding>
232 </checkbox>
233
234 <checkbox>
235 <label>Weather</label>
236 <halign>left</halign>
237
238 <!-- layer only supported if LW/AW is active -->
239 <enable>
240 <property>/sim/gui/dialogs/metar/mode/local-weather</property>
241 <value>1</value>
242 </enable>
243
244 <property>/sim/gui/dialogs/map-canvas/draw-WXR</property>
245 <live>true</live>
246 <binding>
247 <command>dialog-apply</command>
248 </binding>
249 <binding>
250 <command>property-toggle</command>
251 </binding>
252 </checkbox>
253
254 <checkbox>
255 <label>OSM</label>
256 <halign>left</halign>
257
258 <property>/sim/gui/dialogs/map-canvas/draw-OSM</property>
259 <live>true</live>
260 <binding>
261 <command>dialog-apply</command>
262 </binding>
263 <binding>
264 <command>property-toggle</command>
265 </binding>
266 </checkbox>
267
268 <checkbox>
269 <label>VFRChart</label>
270 <halign>left</halign>
271
272 <property>/sim/gui/dialogs/map-canvas/draw-VFRChart</property>
273 <live>true</live>
274 <binding>
275 <command>dialog-apply</command>
276 </binding>
277 <binding>
278 <command>property-toggle</command>
279 </binding>
280 </checkbox>
281
282 <!-- layer only supported if tutorial system is active and targets specified-->
283 <!--
284 <checkbox>
285 <enable>
286 <property>/sim/gui/dialogs/metar/mode/local-weather</property>
287 <value>1</value>
288 </enable>
289 <label>Tutorial Goals</label>
290 <label>Weather</label>
291 <halign>left</halign>
292 <pref-width>100</pref-width>
293 <property>/sim/gui/dialogs/map-canvas/draw-TUT</property>
294 <live>true</live>
295 <binding>
296 <command>dialog-apply</command>
297 </binding>
298 <binding>
299 <command>property-toggle</command>
300 </binding>
301 </checkbox>
302 -->
303
304 <empty><stretch>true</stretch></empty>
305
306 <checkbox>
307 <label>Magnetic Hdgs</label>
308 <halign>left</halign>
309 <property>/sim/gui/dialogs/map-canvas/magnetic-headings</property>
310 <live>true</live>
311 <binding>
312 <command>dialog-apply</command>
313 </binding>
314 <binding>
315 <command>property-toggle</command>
316 </binding>
317 </checkbox>
318
319 <checkbox>
320 <label>Center on Acft</label>
321 <halign>left</halign>
322 <property>/sim/gui/dialogs/map-canvas/centre-on-aircraft</property>
323 <live>true</live>
324 <binding>
325 <command>dialog-apply</command>
326 </binding>
327 <binding>
328 <command>property-toggle</command>
329 </binding>
330 </checkbox>
331
332 <checkbox>
333 <label>Aircraft Hdg Up</label>
334 <halign>left</halign>
335 <property>/sim/gui/dialogs/map-canvas/aircraft-heading-up</property>
336 <live>true</live>
337 <binding>
338 <command>dialog-apply</command>
339 </binding>
340 <binding>
341 <command>property-toggle</command>
342 </binding>
343 </checkbox>
344
345 <checkbox>
346 <label>Transparent</label>
347 <halign>left</halign>
348 <property>/sim/gui/dialogs/map-canvas/transparent</property>
349 <live>true</live>
350 <binding>
351 <command>dialog-apply</command>
352 </binding>
353 <binding>
354 <command>property-toggle</command>
355 </binding>
356 <binding>
357 <command>nasal</command>
358 <script>setTransparency(1);</script>
359 </binding>
360 </checkbox>
361
362 <empty><stretch>true</stretch></empty>
363
364 <button>
365 <name>close</name>
366 <legend>Close</legend>
367 <default>true</default>
368 <binding>
369 <command>dialog-close</command>
370 </binding>
371 </button>
372
373 </group>
374
375 <vrule/>
376
377 <group>
378 <layout>vbox</layout>
379 <stretch>true</stretch>
380
381 <group>
382 <canvas>
383 <name>canvas-map</name>
384 <valign>fill</valign>
385 <halign>fill</halign>
386 <stretch>true</stretch>
387 <pref-width>600</pref-width>
388 <pref-height>400</pref-height>
389 <nasal><load><![CDATA[
390
391
392
393
394 var myCanvas = canvas.get( cmdarg() );
395 myCanvas.setColorBackground(0,0,0,0.5); # transparent
396 var TestMap = myCanvas.createGroup().createChild("map");
397
398 # Initialize the controller:
399 var ctrl_ns = canvas.Map.Controller.get("Aircraft position");
400 var source = ctrl_ns.SOURCES["map-dialog"];
401 if (source == nil) {
402 # TODO: amend
403 var source = ctrl_ns.SOURCES["map-dialog"] = {
404 getPosition: func subvec(geo.aircraft_position().latlon(), 0, 2),
405 getAltitude: func getprop('/position/altitude-ft'),
406 getHeading: func {
407 if (me.aircraft_heading)
408 getprop('/orientation/heading-deg')
409 else 0
410 },
411 aircraft_heading: 1,
412 };
413 }
414 setlistener("/sim/gui/dialogs/map-canvas/aircraft-heading-up", func(n) {
415 source.aircraft_heading = n.getBoolValue();
416 }, 1);
417 # Make it move with our aircraft:
418 TestMap.setController("Aircraft position", "map-dialog"); # from aircraftpos.controller
419
420 # Initialize a range:
421 TestMap.setRange(60);
422 TestMap.setScreenRange(200);
423
424 var range_step = math.log10(TestMap.getRange());
425 # TODO: check if this is valid, IIRC DOM manipulation was fragile when done inside canvas/Nasal region (?)
426 gui.findElementByName(self, "zoomdisplay").setValue("property", TestMap._node.getNode("range").getPath());
427
428 # Center the map's origin: FIXME: move to api.nas, i.e. allow maps to have a size/view that differs from the actual canvas ??
429 TestMap.setTranslation(
430 myCanvas.get("view[0]")/2,
431 myCanvas.get("view[1]")/2
432 );
433
434 ##
435 # Styling: This is a bit crude at the moment, i.e. no dedicated APIs yet - but it's
436 # just there to prototype things for now
437 var Styles = {};
438 Styles.get = func(type) return Styles[type];
439 var Options = {};
440 Options.get = func(type) return Options[type];
441
442 ## set up a few keys supported by the DME.symbol file to customize appearance:
443 Styles.DME = {};
444 Styles.DME.debug = 1; # HACK for benchmarking/debugging purposes
445 Styles.DME.animation_test = 0; # for prototyping animated symbols
446
447 Styles.DME.scale_factor = 0.4; # 40% (applied to whole group)
448 Styles.DME.line_width = 3.0;
449 Styles.DME.color_tuned = [0,1,0]; #rgb
450 Styles.DME.color_default = [1,1,0]; #rgb
451
452 Styles.APT = {};
453 Styles.APT.scale_factor = 0.4; # 40% (applied to whole group)
454 Styles.APT.line_width = 3.0;
455 Styles.APT.color_default = [0,0.6,0.85]; #rgb
456 Styles.APT.label_font_color = Styles.APT.color_default;
457 Styles.APT.label_font_size=28;
458
459 Styles.TFC = {};
460 Styles.TFC.scale_factor = 0.4; # 40% (applied to whole group)
461
462 Styles.WPT = {};
463 Styles.WPT.scale_factor = 0.5; # 50% (applied to whole group)
464
465 Styles.RTE = {};
466 Styles.RTE.line_width = 2;
467
468 Styles.FLT = {};
469 Styles.FLT.line_width = 3;
470
471 Styles.FIX = {};
472 Styles.FIX.color = [1,0,0];
473 Styles.FIX.scale_factor = 0.4; # 40%
474
475 Styles.VOR = {};
476 Styles.VOR.range_line_width = 2;
477 Styles.VOR.radial_line_width = 1;
478 Styles.VOR.scale_factor = 0.6; # 60%
479
480 Options.FLT = {};
481 var make_update_wrapper = func(name) {
482 if (!contains(Options, name)) Options[name] = {};
483 Options[name].update_wrapper = func(layer, fn) {
484 var t = systime();
485 fn();
486 t = systime() - t;
487 printlog(canvas._MP_dbg_lvl, name~" took "~(t*1000)~"ms")
488 }
489 }
490
491 var ToggleLayerVisible = func(name) {
492 (var l = TestMap.getLayer(name)).setVisible(l.getVisible());
493 };
494 var SetLayerVisible = func(name,n=1) {
495 TestMap.getLayer(name).setVisible(n);
496 };
497
498 var SetProjection = func(projection) {
499 TestMap._node.setValue("projection", projection);
500 };
501
502 setlistener("/sim/gui/dialogs/map-canvas/projection",
503 func(n) SetProjection(n.getValue());
504 );
505
506
507 Styles.APS = {};
508 Styles.APS.scale_factor = 0.25;
509
510 # TODO: introduce some meta NAV layer that handles both VORs and NDBs, can we instantiate those layers directly ?
511 var r = func(name,vis=1,zindex=nil) return caller(0)[0];
512 # TODO: we'll need some z-indexing here, right now it's just random
513 foreach(var type; [r('TFC',0),r('APT'),r('DME'),r('VOR'),r('NDB'),r('FIX',0),r('RTE'),r('WPT'),r('FLT'),r('WXR',0),r('APS')] ) {
514 if (1 and type.name != 'APS' and type.name != 'FLT') make_update_wrapper(type.name);
515 TestMap.addLayer(factory: canvas.SymbolLayer, type_arg: type.name,
516 visible: type.vis, priority: 4,
517 style: Styles.get(type.name),
518 options: Options.get(type.name) );
519 (func {
520 # Notify MapStructure about layer visibility changes:
521 var name = type.name;
522 props.globals.initNode("/sim/gui/dialogs/map-canvas/draw-"~name, type.vis, "BOOL");
523 append(listeners,
524 setlistener("/sim/gui/dialogs/map-canvas/draw-"~name,
525 func(n) SetLayerVisible(name,n.getValue()))
526 );
527
528
529 })();
530 }
531
532 foreach(var type; [ r('OSM'), r('VFRChart') ]) {
533 TestMap.addLayer(factory: canvas.OverlayLayer, type_arg: type.name,
534 visible: 0, priority: 1,
535 style: Styles.get(type.name),
536 options: Options.get(type.name) );
537 (func {
538 # Notify MapStructure about layer visibility changes:
539 var name = type.name;
540 props.globals.initNode("/sim/gui/dialogs/map-canvas/draw-"~name, 0, "BOOL");
541 append(listeners,
542 setlistener("/sim/gui/dialogs/map-canvas/draw-"~name,
543 func(n) SetLayerVisible(name,n.getValue()))
544 );
545 })();
546 }
547
548
549 ]]></load></nasal>
550 </canvas>
551 <layout>hbox</layout>
552 <stretch>true</stretch>
553 <halign>fill</halign>
554 <valign>fill</valign>
555 </group>
556
557 <hrule/>
558
559 <group>
560 <layout>hbox</layout>
561
562 <button>
563 <name>zoomout</name>
564 <legend>-</legend>
565 <pref-width>52</pref-width>
566 <pref-height>22</pref-height>
567
568 <binding>
569 <command>nasal</command>
570 <script>
571 var range = TestMap.getRange();
572 if (range &lt; 40)
573 TestMap.setRange(range*range_step);
574 </script>
575 </binding>
576 </button>
577
578 <text>
579 <name>zoomdisplay</name>
580 <label>MMM</label>
581 <format>Zoom %0.1f NM</format>
582 <property>/gui/radar-mapstructure/zoom</property>
583 <live>true</live>
584 </text>
585
586 <button>
587 <name>zoomin</name>
588 <legend>+</legend>
589 <pref-width>52</pref-width>
590 <pref-height>22</pref-height>
591
592 <binding>
593 <command>nasal</command>
594 <script>
595 var range = TestMap.getRange();
596 if (range &gt; 1)
597 TestMap.setRange(range/range_step);
598 </script>
599 </binding>
600 </button>
601 </group>
602
603 </group>
604 </group>
605 </PropertyList>