Attribute Variables in Code
The following example shows how an attribute variable that returns a double can be created or modified through code.
// Set the width of a LineVisualizer that visualizes roads to a constant value.
roadVisualizer.Width = 5.0;
// Set the width of a LineVisualizer to the value of the attribute ROAD_CLASS,
// if the attribute is missing we set the width to 5.
roadVisualizer.Width = new IndirectAttributeVariable<double>("ROAD_CLASS", 5.0);
// Same as the indirect example above but use an ExpressionAttributeVariable.
// Note that we use the shorthand version of an if-then-else expression.
roadVisualizer.Width = new ExpressionAttributeVariable<double>(
"ROAD_CLASS, 5.0");
// Use a KeyedAttributeVariable and the value of the ROAD_CLASS attribute to
// look up the value in a table so that:
//
// ROAD_CLASS 1 => 1
// ROAD_CLASS 2 => 5
// ROAD_CLASS 3 => 10
//
// If the ROAD_CLASS attribute is missing we set the width to 5.
KeyedAttributeVariable<double> roadWidth =
new KeyedAttributeVariable<double>("ROAD_CLASS");
roadWidth.DefaultValue = 5.0;
roadWidth.Table[1] = 1.0;
roadWidth.Table[2] = 5.0;
roadWidth.Table[3] = 10.0;
roadVisualizer.Width = roadWidth;