You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FineArrowGraphics.js 2.0KB

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