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

DrawTailedAttackArrow.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-30 16:43:12
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { PlotEventType } from '@dc-modules/event'
  7. import { Transform } from '@dc-modules/transform'
  8. import { TailedAttackArrow } from '@dc-modules/overlay'
  9. import Draw from './Draw'
  10. import TailedAttackArrowGraphics from '../graphics/TailedAttackArrowGraphics'
  11. const DEF_STYLE = {
  12. material: Cesium.Color.YELLOW.withAlpha(0.6),
  13. fill: true
  14. }
  15. class DrawTailedAttackArrow extends Draw {
  16. constructor(style) {
  17. super()
  18. this._maxAnchorSize = 3
  19. this._style = {
  20. ...DEF_STYLE,
  21. ...style
  22. }
  23. this._graphics = new TailedAttackArrowGraphics()
  24. }
  25. /**
  26. *
  27. * @private
  28. */
  29. _mountEntity() {
  30. this.drawTool.tooltipMess = '左击选择点位'
  31. this._delegate = new Cesium.Entity({
  32. polygon: {
  33. ...this._style,
  34. hierarchy: new Cesium.CallbackProperty(() => {
  35. if (this._positions.length > 2) {
  36. this._graphics.positions = this._positions
  37. return this._graphics.hierarchy
  38. } else {
  39. return null
  40. }
  41. }, false)
  42. }
  43. })
  44. this._layer.entities.add(this._delegate)
  45. }
  46. /**
  47. *
  48. * @private
  49. */
  50. _stopdHook() {
  51. let tailedAttackArrow = new TailedAttackArrow(
  52. Transform.transformCartesianArrayToWGS84Array(this._positions)
  53. ).setStyle(this._style)
  54. this._options.onDrawStop && this._options.onDrawStop(tailedAttackArrow)
  55. }
  56. /**
  57. *
  58. * @param position
  59. * @returns {boolean}
  60. * @private
  61. */
  62. _onDrawAnchor(position) {
  63. let len = this._positions.length
  64. this._positions.push(position)
  65. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  66. this._graphics.positions = this._positions
  67. if (len >= this._maxAnchorSize) {
  68. this._positions.pop()
  69. this.drawTool.fire(PlotEventType.DRAW_STOP)
  70. }
  71. }
  72. }
  73. export default DrawTailedAttackArrow