基地source codes of WorldWindJava on github,类MilStd2525TacticalSymbol覆盖方法名为layoutDynamicModifiers。在这个方法中,你可以看到对于DIRECTION_OF_MOVEMENT,最终只调用addLine(...)(这个方法是在超级抽象AbstractTacticalSymbol中实现的,它只向名为currentLines的列表中添加一行),并且只能设置SPEED_LEADER_SCALE和其他属性运动方向不能在外部改变。
@Override
protected void layoutDynamicModifiers(DrawContext dc, AVList modifiers, OrderedSymbol osym)
{
this.currentLines.clear();
if (!this.isShowGraphicModifiers())
return;
// Direction of Movement indicator. Placed either at the center of the icon or at the bottom of the symbol
// layout.
Object o = this.getModifier(SymbologyConstants.DIRECTION_OF_MOVEMENT);
if (o != null && o instanceof Angle)
{
// The length of the direction of movement line is equal to the height of the symbol frame. See
// MIL-STD-2525C section 5.3.4.1.c, page 33.
double length = this.iconRect.getHeight();
Object d = this.getModifier(SymbologyConstants.SPEED_LEADER_SCALE);
if (d != null && d instanceof Number)
length *= ((Number) d).doubleValue();
if (this.useGroundHeadingIndicator)
{
List<? extends Point2D> points = MilStd2525Util.computeGroundHeadingIndicatorPoints(dc, osym.placePoint,
(Angle) o, length, this.iconRect.getHeight());
this.addLine(dc, Offset.BOTTOM_CENTER, points, LAYOUT_RELATIVE, points.size() - 1, osym);
}
else
{
List<? extends Point2D> points = MilStd2525Util.computeCenterHeadingIndicatorPoints(dc,
osym.placePoint, (Angle) o, length);
this.addLine(dc, Offset.CENTER, points, null, 0, osym);
}
}
}
在超类AbstractTacticalSymbol,字段currentLines(其包含用于移动的方向线)在其中提请加入行提到列表(类的线2366)的方法命名drawLines(...)被使用。在第2364行中,您可以看到该颜色设置为黑色。
gl.glColor4f(0f, 0f, 0f, opacity.floatValue());
现在我建议你延长MilStd2525TacticalSymbol和做以下:
- 扩展类AbstractTacticalSymbol.Line和定义一些字段来存储颜色。
- 覆盖方法layoutDynamicModifiers并获取您自己的键(例如DIRECTION_OF_MOVEMENT_COLOR)从修饰符中获取颜色,并使用此给定颜色创建自己的线并将其添加到currentLines列表(您可以重写此方法的addLine方法)。
- 最后重写drawLines以在自己的Line类中使用商店颜色,并在绘制线之前更改gl的颜色(可以在绘制移动方向后将颜色更改为黑色)。
您使用的是哪个版本的WorldWind?即1.X,2.0,2.0-986,2.1 – Igor
2.1.0。我基本上已经跟上了主git分支。 – stix