Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TailedAttackArrow.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 22:51:36
  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 { PlotUtil } from '@dc-modules/utils'
  9. import { Transform } from '@dc-modules/transform'
  10. import Overlay from '../Overlay'
  11. import AttackArrow from './AttackArrow'
  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._state = State.INITIALIZED
  24. }
  25. get type() {
  26. return Overlay.getOverlayType('tailed_attack_arrow')
  27. }
  28. set positions(positions) {
  29. this._positions = Parse.parsePositions(positions)
  30. this._delegate.polygon.hierarchy = this._getHierarchy()
  31. return this
  32. }
  33. get positions() {
  34. return this._positions
  35. }
  36. _getHierarchy() {
  37. let pnts = Parse.parsePolygonCoordToArray(this._positions)[0]
  38. let tailLeft = pnts[0]
  39. let tailRight = pnts[1]
  40. if (PlotUtil.isClockWise(pnts[0], pnts[1], pnts[2])) {
  41. tailLeft = pnts[1]
  42. tailRight = pnts[0]
  43. }
  44. let midTail = PlotUtil.mid(tailLeft, tailRight)
  45. let bonePnts = [midTail].concat(pnts.slice(2))
  46. let headPnts = this._getArrowHeadPoints(bonePnts, tailLeft, tailRight)
  47. let neckLeft = headPnts[0]
  48. let neckRight = headPnts[4]
  49. let tailWidth = PlotUtil.distance(tailLeft, tailRight)
  50. let allLen = PlotUtil.getBaseLength(bonePnts)
  51. let len = allLen * this.tailWidthFactor * this.swallowTailFactor
  52. let swallowTailPnt = PlotUtil.getThirdPoint(
  53. bonePnts[1],
  54. bonePnts[0],
  55. 0,
  56. len,
  57. true
  58. )
  59. let factor = tailWidth / allLen
  60. let bodyPnts = this._getArrowBodyPoints(
  61. bonePnts,
  62. neckLeft,
  63. neckRight,
  64. factor
  65. )
  66. let count = bodyPnts.length
  67. let leftPnts = [tailLeft].concat(bodyPnts.slice(0, count / 2))
  68. leftPnts.push(neckLeft)
  69. let rightPnts = [tailRight].concat(bodyPnts.slice(count / 2, count))
  70. rightPnts.push(neckRight)
  71. leftPnts = PlotUtil.getQBSplinePoints(leftPnts)
  72. rightPnts = PlotUtil.getQBSplinePoints(rightPnts)
  73. return new Cesium.PolygonHierarchy(
  74. Transform.transformWGS84ArrayToCartesianArray(
  75. Parse.parsePositions(
  76. leftPnts.concat(headPnts, rightPnts.reverse(), [
  77. swallowTailPnt,
  78. leftPnts[0]
  79. ])
  80. )
  81. )
  82. )
  83. }
  84. }
  85. Overlay.registerType('tailed_attack_arrow')
  86. export default TailedAttackArrow