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.1KB

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