Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DrawTailedAttackArrow.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-30 16:43:12
  4. */
  5. import Draw from './Draw'
  6. import TailedAttackArrowGraphics from '@dc-modules/overlay/graphics/TailedAttackArrowGraphics'
  7. const { Transform } = DC
  8. const { Cesium } = DC.Namespace
  9. const DEF_STYLE = {
  10. material: Cesium.Color.YELLOW.withAlpha(0.6),
  11. fill: true
  12. }
  13. class DrawTailedAttackArrow extends Draw {
  14. constructor(style) {
  15. super()
  16. this._positions = []
  17. this._floatingAnchor = undefined
  18. this._style = {
  19. ...DEF_STYLE,
  20. ...style
  21. }
  22. this._graphics = new TailedAttackArrowGraphics()
  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 position = this._clampToGround ? e.surfacePosition : e.position
  42. let len = this._positions.length
  43. if (len === 0) {
  44. this._positions.push(position)
  45. this.createAnchor(position)
  46. this._floatingAnchor = this.createAnchor(position)
  47. }
  48. this._positions.push(position)
  49. this._graphics.positions = this._positions
  50. this.createAnchor(position)
  51. if (len > 2) {
  52. this._positions.pop()
  53. this.unbindEvent()
  54. let tailedAttackArrow = new DC.TailedAttackArrow(
  55. Transform.transformCartesianArrayToWGS84Array(this._positions)
  56. )
  57. tailedAttackArrow.setStyle(this._style)
  58. this._plotEvent.raiseEvent(tailedAttackArrow)
  59. }
  60. }
  61. _onMouseMove(e) {
  62. this._tooltip.showAt(e.windowPosition, '单击选择点位')
  63. if (this._floatingAnchor) {
  64. let position = this._clampToGround ? e.surfacePosition : e.position
  65. this._floatingAnchor.position.setValue(position)
  66. this._positions.pop()
  67. this._positions.push(position)
  68. }
  69. }
  70. }
  71. export default DrawTailedAttackArrow