基地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