您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FineArrow.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 22:38:10
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import State from '@dc-modules/state/State'
  7. import Parse from '@dc-modules/parse/Parse'
  8. import { Util, PlotUtil } from '@dc-modules/utils'
  9. import { Transform } from '@dc-modules/transform'
  10. import Overlay from '../Overlay'
  11. const HALF_PI = Math.PI / 2
  12. class FineArrow extends Overlay {
  13. constructor(positions) {
  14. super()
  15. this._positions = Parse.parsePositions(positions)
  16. this._delegate = new Cesium.Entity({ polygon: {} })
  17. this.tailWidthFactor = 0.15
  18. this.neckWidthFactor = 0.2
  19. this.headWidthFactor = 0.25
  20. this.headAngle = Math.PI / 8.5
  21. this.neckAngle = Math.PI / 13
  22. this._state = State.INITIALIZED
  23. }
  24. get type() {
  25. return Overlay.getOverlayType('fine_arrow')
  26. }
  27. set positions(positions) {
  28. this._positions = Parse.parsePositions(positions)
  29. this._delegate.polygon.hierarchy = this._getHierarchy()
  30. return this
  31. }
  32. get positions() {
  33. return this._positions
  34. }
  35. _getHierarchy() {
  36. let pnts = Parse.parsePolygonCoordToArray(this._positions)[0]
  37. let pnt1 = pnts[0]
  38. let pnt2 = pnts[1]
  39. let len = PlotUtil.getBaseLength(pnts)
  40. let tailWidth = len * this.tailWidthFactor
  41. let neckWidth = len * this.neckWidthFactor
  42. let headWidth = len * this.headWidthFactor
  43. let tailLeft = PlotUtil.getThirdPoint(pnt2, pnt1, HALF_PI, tailWidth, true)
  44. let tailRight = PlotUtil.getThirdPoint(
  45. pnt2,
  46. pnt1,
  47. HALF_PI,
  48. tailWidth,
  49. false
  50. )
  51. let headLeft = PlotUtil.getThirdPoint(
  52. pnt1,
  53. pnt2,
  54. this.headAngle,
  55. headWidth,
  56. false
  57. )
  58. let headRight = PlotUtil.getThirdPoint(
  59. pnt1,
  60. pnt2,
  61. this.headAngle,
  62. headWidth,
  63. true
  64. )
  65. let neckLeft = PlotUtil.getThirdPoint(
  66. pnt1,
  67. pnt2,
  68. this.neckAngle,
  69. neckWidth,
  70. false
  71. )
  72. let neckRight = PlotUtil.getThirdPoint(
  73. pnt1,
  74. pnt2,
  75. this.neckAngle,
  76. neckWidth,
  77. true
  78. )
  79. return new Cesium.PolygonHierarchy(
  80. Transform.transformWGS84ArrayToCartesianArray(
  81. Parse.parsePositions([
  82. tailLeft,
  83. neckLeft,
  84. headLeft,
  85. pnt2,
  86. headRight,
  87. neckRight,
  88. tailRight
  89. ])
  90. )
  91. )
  92. }
  93. _mountedHook() {
  94. /**
  95. * set the location
  96. */
  97. this.positions = this._positions
  98. }
  99. /**
  100. *
  101. * @param text
  102. * @param textStyle
  103. * @returns {FineArrow}
  104. */
  105. setLabel(text, textStyle) {
  106. return this
  107. }
  108. /**
  109. * Sets Style
  110. * @param style
  111. * @returns {FineArrow}
  112. */
  113. setStyle(style) {
  114. if (Object.keys(style).length === 0) {
  115. return this
  116. }
  117. delete style['positions']
  118. this._style = style
  119. Util.merge(this._delegate.polygon, this._style)
  120. return this
  121. }
  122. }
  123. Overlay.registerType('fine_arrow')
  124. export default FineArrow