Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

DrawTailedAttackArrow.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 = null
  52. if (this._positions.length) {
  53. tailedAttackArrow = new TailedAttackArrow(
  54. Transform.transformCartesianArrayToWGS84Array(this._positions)
  55. ).setStyle(this._style)
  56. }
  57. this._options.onDrawStop && this._options.onDrawStop(tailedAttackArrow)
  58. }
  59. /**
  60. *
  61. * @param position
  62. * @returns {boolean}
  63. * @private
  64. */
  65. _onDrawAnchor(position) {
  66. let len = this._positions.length
  67. this._positions.push(position)
  68. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  69. this._graphics.positions = this._positions
  70. if (len >= this._maxAnchorSize) {
  71. this._positions.pop()
  72. this.drawTool.fire(PlotEventType.DRAW_STOP)
  73. }
  74. }
  75. }
  76. export default DrawTailedAttackArrow