var assert_m = canvas.assert_m; # -------------------------------- # From FGDATA/Nasal/canvas/api.nas # -------------------------------- # Recursively get all children of class specified by first param canvas.Group.getChildrenOfType = func(type, array = nil){ var children = array; if(children == nil) children = []; var my_children = me.getChildren(); if(typeof(type) != 'vector') type = [type]; foreach(var c; my_children){ foreach(var t; type){ if(isa(c, t)){ append(children, c); } } if(isa(c, canvas.Group)){ c.getChildrenOfType(type, children); } } return children; }; # Set color to children of type Path and Text. It is possible to optionally # specify which types of children should be affected by passing a vector as # the last agrument, ie. my_group.setColor(1,1,1,[Path]); canvas.Group.setColor = func(){ var color = arg; var types = [Path, Text]; var arg_c = size(color); if(arg_c > 1 and typeof(color[-1]) == 'vector'){ types = color[-1]; color = subvec(color, 0, arg_c - 1); } var children = me.getChildrenOfType(types); if(typeof(color) == 'vector'){ var first = color[0]; if(typeof(first) == 'vector') color = first; } foreach(var c; children) c.setColor(color); }; canvas.Map.addLayer = func(factory, type_arg=nil, priority=nil, style=nil, opts=nil, visible=1) { if(contains(me.layers, type_arg)) printlog("warn", "addLayer() warning: overwriting existing layer:", type_arg); var options = opts; # Argument handling if (type_arg != nil) { var layer = factory.new(type:type_arg, group:me, map:me, style:style, options:options, visible:visible); var type = factory.get(type_arg); var key = type_arg; } else { var layer = factory.new(group:me, map:me, style:style, options:options, visible:visible); var type = factory; var key = factory.type; } me.layers[type_arg] = layer; if (priority == nil) priority = type.df_priority; if (priority != nil) layer.group.setInt("z-index", priority); return layer; # return new layer to caller() so that we can directly work with it, i.e. to register event handlers (panning/zooming) }; # ----------------------------------------- # From FGDATA/Nasal/canvas/MapStructure.nas # ----------------------------------------- var opt_member = func(h,k) { if (contains(h, k)) return h[k]; if (contains(h, "parents")) { var _=h.parents; for (var i=0;i= 2){ var (lat,lon) = me.controller.getpos(m); append(coords,"N"~lat); append(coords,"E"~lon); append(cmds,cmd); cmd = canvas.Path.VG_LINE_TO; } else { cmd = canvas.Path.VG_MOVE_TO; } } me.element.setDataGeo(cmds, coords); me.element.update(); # this doesn't help with flickering, it seems me.callback('draw_after'); };