2017-04-17 63 views
10

在美國國家航空航天局WorldWind中,可以爲Milstd-2525符號分配一個「旅行方向」速度領先者。但是,這個速度領先者是黑色的,因此很難看到深藍色的海洋背景。我曾嘗試更改TacticalSymbolAttributes中的內部顏色材質,但這似乎沒有任何效果(在任何情況下)。不幸的是,文檔沒有提供關於如何改變線條顏色的線索。美國國家航空航天局Worldwind:如何改變戰術符號的速度領導者的顏色?

是否有可能在Worldwind中更改Milstd-2525 Tactical Symbol的速度引導線的顏色,如果是這樣,怎麼辦?

+0

您使用的是哪個版本的WorldWind?即1.X,2.0,2.0-986,2.1 – Igor

+0

2.1.0。我基本上已經跟上了主git分支。 – stix

回答

5

基地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和做以下:

  1. 擴展類AbstractTacticalSymbol.Line和定義一些字段來存儲顏色。
  2. 覆蓋方法layoutDynamicModifiers並獲取您自己的鍵(例如DIRECTION_OF_MOVEMENT_COLOR)從修飾符中獲取顏色,並使用此給定顏色創建自己的線並將其添加到currentLines列表(您可以重寫此方法的addLine方法)。
  3. 最後重寫drawLines以在自己的Line類中使用商店顏色,並在繪製線之前更改gl的顏色(可以在繪製移動方向後將顏色更改爲黑色)。
1

我正在跑掉之前的Worldwind,但試試看看AbstractTacticalSymbol.java - > drawLines()方法。

在繪製線條之前,它默認glColor爲黑色。

相關問題