jxdnsong
2023-04-05 be147d2a99d60a30b20fade742e85b45f06172ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
 * @Author: Caven
 * @Date: 2020-08-30 17:10:33
 */
 
import { Cesium } from '@dc-modules/namespace'
import Parse from '@dc-modules/parse/Parse'
import { Transform } from '@dc-modules/transform'
import { PlotUtil } from '@dc-modules/utils'
 
const HALF_PI = Math.PI / 2
 
class FineArrowGraphics {
  constructor(options) {
    this._positions = options?.positions || []
    this.tailWidthFactor = 0.15
    this.neckWidthFactor = 0.2
    this.headWidthFactor = 0.25
    this.headAngle = Math.PI / 8.5
    this.neckAngle = Math.PI / 13
  }
 
  set positions(positions) {
    this._positions = positions
  }
 
  get positions() {
    return this._positions
  }
 
  get hierarchy() {
    return this._createHierarchy()
  }
 
  _createHierarchy() {
    let pnts = Parse.parsePolygonCoordToArray(
      Transform.transformCartesianArrayToWGS84Array(this._positions)
    )[0]
    let pnt1 = pnts[0]
    let pnt2 = pnts[1]
    let len = PlotUtil.getBaseLength(pnts)
    let tailWidth = len * this.tailWidthFactor
    let neckWidth = len * this.neckWidthFactor
    let headWidth = len * this.headWidthFactor
    let tailLeft = PlotUtil.getThirdPoint(pnt2, pnt1, HALF_PI, tailWidth, true)
    let tailRight = PlotUtil.getThirdPoint(
      pnt2,
      pnt1,
      HALF_PI,
      tailWidth,
      false
    )
    let headLeft = PlotUtil.getThirdPoint(
      pnt1,
      pnt2,
      this.headAngle,
      headWidth,
      false
    )
    let headRight = PlotUtil.getThirdPoint(
      pnt1,
      pnt2,
      this.headAngle,
      headWidth,
      true
    )
    let neckLeft = PlotUtil.getThirdPoint(
      pnt1,
      pnt2,
      this.neckAngle,
      neckWidth,
      false
    )
    let neckRight = PlotUtil.getThirdPoint(
      pnt1,
      pnt2,
      this.neckAngle,
      neckWidth,
      true
    )
    return new Cesium.PolygonHierarchy(
      Transform.transformWGS84ArrayToCartesianArray(
        Parse.parsePositions([
          tailLeft,
          neckLeft,
          headLeft,
          pnt2,
          headRight,
          neckRight,
          tailRight
        ])
      )
    )
  }
}
 
export default FineArrowGraphics