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.

DrawAttackArrow.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-30 16:43:12
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { Transform } from '@dc-modules/transform'
  7. import { AttackArrow } from '@dc-modules/overlay'
  8. import Draw from './Draw'
  9. import AttackArrowGraphics from '../graphics/AttackArrowGraphics'
  10. const DEF_STYLE = {
  11. material: Cesium.Color.YELLOW.withAlpha(0.6),
  12. fill: true
  13. }
  14. class DrawAttackArrow extends Draw {
  15. constructor(style) {
  16. super()
  17. this._floatingAnchor = undefined
  18. this._style = {
  19. ...DEF_STYLE,
  20. ...style
  21. }
  22. this._graphics = new AttackArrowGraphics()
  23. }
  24. _mountEntity() {
  25. this._delegate = new Cesium.Entity({
  26. polygon: {
  27. ...this._style,
  28. hierarchy: new Cesium.CallbackProperty(() => {
  29. if (this._positions.length > 2) {
  30. this._graphics.positions = this._positions
  31. return this._graphics.hierarchy
  32. } else {
  33. return null
  34. }
  35. }, false)
  36. }
  37. })
  38. this._layer.add(this._delegate)
  39. }
  40. _onClick(e) {
  41. let len = this._positions.length
  42. let position = this._clampToGround ? e.surfacePosition : e.position
  43. if (!position) {
  44. return false
  45. }
  46. if (len === 0) {
  47. this._positions.push(position)
  48. this.createAnchor(position)
  49. this._floatingAnchor = this.createAnchor(position)
  50. }
  51. this._positions.push(position)
  52. this._graphics.positions = this._positions
  53. this.createAnchor(position)
  54. if (len > 2) {
  55. this._positions.pop()
  56. this.unbindEvent()
  57. let attackArrow = new AttackArrow(
  58. Transform.transformCartesianArrayToWGS84Array(this._positions)
  59. )
  60. attackArrow.setStyle(this._style)
  61. this._plotEvent.raiseEvent(attackArrow)
  62. }
  63. }
  64. }
  65. export default DrawAttackArrow