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.

TailedAttackArrow.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 22:51:36
  4. */
  5. import State from '@dc-modules/state/State'
  6. import Parse from '@dc-modules/parse/Parse'
  7. import { PlotUtil } from '@dc-modules/utils'
  8. import { Transform } from '@dc-modules/transform'
  9. import Overlay from '../Overlay'
  10. import AttackArrow from './AttackArrow'
  11. const { Cesium } = DC.Namespace
  12. class TailedAttackArrow extends AttackArrow {
  13. constructor(positions) {
  14. super(positions)
  15. this._delegate = new Cesium.Entity({ polygon: {} })
  16. this.headHeightFactor = 0.18
  17. this.headWidthFactor = 0.3
  18. this.neckHeightFactor = 0.85
  19. this.neckWidthFactor = 0.15
  20. this.tailWidthFactor = 0.1
  21. this.headTailFactor = 0.8
  22. this.swallowTailFactor = 1
  23. this.type = Overlay.getOverlayType('tailed_attack_arrow')
  24. this._state = State.INITIALIZED
  25. }
  26. set positions(positions) {
  27. this._positions = Parse.parsePositions(positions)
  28. this._delegate.polygon.hierarchy = this._getHierarchy()
  29. return this
  30. }
  31. get positions() {
  32. return this._positions
  33. }
  34. _getHierarchy() {
  35. let pnts = Parse.parsePolygonCoordToArray(this._positions)[0]
  36. let tailLeft = pnts[0]
  37. let tailRight = pnts[1]
  38. if (PlotUtil.isClockWise(pnts[0], pnts[1], pnts[2])) {
  39. tailLeft = pnts[1]
  40. tailRight = pnts[0]
  41. }
  42. let midTail = PlotUtil.mid(tailLeft, tailRight)
  43. let bonePnts = [midTail].concat(pnts.slice(2))
  44. let headPnts = this._getArrowHeadPoints(bonePnts, tailLeft, tailRight)
  45. let neckLeft = headPnts[0]
  46. let neckRight = headPnts[4]
  47. let tailWidth = PlotUtil.distance(tailLeft, tailRight)
  48. let allLen = PlotUtil.getBaseLength(bonePnts)
  49. let len = allLen * this.tailWidthFactor * this.swallowTailFactor
  50. let swallowTailPnt = PlotUtil.getThirdPoint(
  51. bonePnts[1],
  52. bonePnts[0],
  53. 0,
  54. len,
  55. true
  56. )
  57. let factor = tailWidth / allLen
  58. let bodyPnts = this._getArrowBodyPoints(
  59. bonePnts,
  60. neckLeft,
  61. neckRight,
  62. factor
  63. )
  64. let count = bodyPnts.length
  65. let leftPnts = [tailLeft].concat(bodyPnts.slice(0, count / 2))
  66. leftPnts.push(neckLeft)
  67. let rightPnts = [tailRight].concat(bodyPnts.slice(count / 2, count))
  68. rightPnts.push(neckRight)
  69. leftPnts = PlotUtil.getQBSplinePoints(leftPnts)
  70. rightPnts = PlotUtil.getQBSplinePoints(rightPnts)
  71. return new Cesium.PolygonHierarchy(
  72. Transform.transformWGS84ArrayToCartesianArray(
  73. Parse.parsePositions(
  74. leftPnts.concat(headPnts, rightPnts.reverse(), [
  75. swallowTailPnt,
  76. leftPnts[0]
  77. ])
  78. )
  79. )
  80. )
  81. }
  82. }
  83. Overlay.registerType('tailed_attack_arrow')
  84. export default TailedAttackArrow