Use new props.addChildren method to speed up 'Select Aiport' dialog
This commit is contained in:
parent
87426ba5c1
commit
7f1117a537
3 changed files with 54 additions and 34 deletions
|
@ -319,16 +319,25 @@ var Group = {
|
||||||
# type can be group, text
|
# type can be group, text
|
||||||
createChild: func(type, id = nil)
|
createChild: func(type, id = nil)
|
||||||
{
|
{
|
||||||
var factory = me._element_factories[type];
|
var factory = me._getFactory(type);
|
||||||
|
|
||||||
if( factory == nil )
|
if( factory == nil )
|
||||||
{
|
|
||||||
debug.dump("canvas.Group.createChild(): unknown type (" ~ type ~ ")");
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
|
||||||
|
|
||||||
return factory([me._node, type], id);
|
return factory([me._node, type], id);
|
||||||
},
|
},
|
||||||
|
# Create multiple children of given type
|
||||||
|
createChildren: func(type, count)
|
||||||
|
{
|
||||||
|
var factory = me._getFactory(type);
|
||||||
|
if( factory == nil )
|
||||||
|
return [];
|
||||||
|
|
||||||
|
var nodes = me._node.addChildren(type, count, 0, 0);
|
||||||
|
for(var i = 0; i < count; i += 1)
|
||||||
|
nodes[i] = factory(nodes[i], nil); # TODO id. Maybe <base id>-<index>?
|
||||||
|
|
||||||
|
return nodes;
|
||||||
|
},
|
||||||
# Get a vector of all child elements
|
# Get a vector of all child elements
|
||||||
getChildren: func()
|
getChildren: func()
|
||||||
{
|
{
|
||||||
|
@ -386,6 +395,15 @@ var Group = {
|
||||||
{
|
{
|
||||||
# Create element from existing node
|
# Create element from existing node
|
||||||
return me._element_factories[ node.getName() ](node, nil);
|
return me._element_factories[ node.getName() ](node, nil);
|
||||||
|
},
|
||||||
|
_getFactory: func(type)
|
||||||
|
{
|
||||||
|
var factory = me._element_factories[type];
|
||||||
|
|
||||||
|
if( factory == nil )
|
||||||
|
debug.dump("canvas.Group.createChild(): unknown type (" ~ type ~ ")");
|
||||||
|
|
||||||
|
return factory;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
var draw_taxiways = func(group, apt, lod) { # TODO: the LOD arg isn't stricly needed here,
|
var draw_taxiways = func(group, apt, lod) { # TODO: the LOD arg isn't stricly needed here,
|
||||||
# the layer is a conventional canvas group, so it can access its map
|
# the layer is a conventional canvas group, so it can access its map
|
||||||
# parent and just read the "range" property to do LOD handling
|
# parent and just read the "range" property to do LOD handling
|
||||||
group.set("z-index",-100); # HACK: we need to encapsulate this
|
group.set("z-index",-100) # HACK: we need to encapsulate this
|
||||||
|
.set("stroke", "none");
|
||||||
# var group = group.createChild("group", "apt-"~apt.id); #FIXME: we don't need to use two nested groups for each taxiway - performance?
|
# var group = group.createChild("group", "apt-"~apt.id); #FIXME: we don't need to use two nested groups for each taxiway - performance?
|
||||||
# group = group.createChild("group", "taxiways");
|
# group = group.createChild("group", "taxiways");
|
||||||
# print("drawing taxiways for:", apt.id);
|
# print("drawing taxiways for:", apt.id);
|
||||||
# Taxiways drawn first so the runways and parking positions end up on top.
|
# Taxiways drawn first so the runways and parking positions end up on top.
|
||||||
|
|
||||||
|
# Preallocate all paths at once to gain some speed
|
||||||
|
var taxi_paths = group.createChildren("path", size(apt.taxiways));
|
||||||
|
var i = 0;
|
||||||
foreach(var taxi; apt.taxiways)
|
foreach(var taxi; apt.taxiways)
|
||||||
{
|
{
|
||||||
var clr = SURFACECOLORS[taxi.surface];
|
var clr = SURFACECOLORS[taxi.surface];
|
||||||
if (clr == nil) { clr = SURFACECOLORS[0]};
|
if (clr == nil) { clr = SURFACECOLORS[0]};
|
||||||
|
|
||||||
var icon_taxi =
|
|
||||||
group.createChild("path", "taxi")
|
|
||||||
.setStrokeLineWidth(0)
|
|
||||||
.setColor(clr.r, clr.g, clr.b)
|
|
||||||
.setColorFill(clr.r, clr.g, clr.b);
|
|
||||||
|
|
||||||
var txi = Runway.new(taxi);
|
var txi = Runway.new(taxi);
|
||||||
var beg1 = txi.pointOffCenterline(0, 0.5 * taxi.width);
|
var beg1 = txi.pointOffCenterline(0, 0.5 * taxi.width);
|
||||||
var beg2 = txi.pointOffCenterline(0, -0.5 * taxi.width);
|
var beg2 = txi.pointOffCenterline(0, -0.5 * taxi.width);
|
||||||
var end1 = txi.pointOffCenterline(taxi.length, 0.5 * taxi.width);
|
var end1 = txi.pointOffCenterline(taxi.length, 0.5 * taxi.width);
|
||||||
var end2 = txi.pointOffCenterline(taxi.length, -0.5 * taxi.width);
|
var end2 = txi.pointOffCenterline(taxi.length, -0.5 * taxi.width);
|
||||||
|
|
||||||
icon_taxi.setDataGeo
|
taxi_paths[i].setColorFill(clr.r, clr.g, clr.b)
|
||||||
|
.setDataGeo
|
||||||
(
|
(
|
||||||
[ canvas.Path.VG_MOVE_TO,
|
[ canvas.Path.VG_MOVE_TO,
|
||||||
canvas.Path.VG_LINE_TO,
|
canvas.Path.VG_LINE_TO,
|
||||||
|
@ -35,6 +35,7 @@ var draw_taxiways = func(group, apt, lod) { # TODO: the LOD arg isn't stricl
|
||||||
end2[0], end2[1],
|
end2[0], end2[1],
|
||||||
end1[0], end1[1] ]
|
end1[0], end1[1] ]
|
||||||
);
|
);
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ var Node = {
|
||||||
getChild : func wrap(_getChild(me._g, arg)),
|
getChild : func wrap(_getChild(me._g, arg)),
|
||||||
getChildren : func wrap(_getChildren(me._g, arg)),
|
getChildren : func wrap(_getChildren(me._g, arg)),
|
||||||
addChild : func wrap(_addChild(me._g, arg)),
|
addChild : func wrap(_addChild(me._g, arg)),
|
||||||
|
addChildren : func wrap(_addChildren(me._g, arg)),
|
||||||
removeChild : func wrap(_removeChild(me._g, arg)),
|
removeChild : func wrap(_removeChild(me._g, arg)),
|
||||||
removeChildren : func wrap(_removeChildren(me._g, arg)),
|
removeChildren : func wrap(_removeChildren(me._g, arg)),
|
||||||
getAliasTarget : func wrap(_getAliasTarget(me._g, arg)),
|
getAliasTarget : func wrap(_getAliasTarget(me._g, arg)),
|
||||||
|
|
Loading…
Reference in a new issue