Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

DrawFineArrow.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 { PlotEventType } from '@dc-modules/event'
  8. import { FineArrow } from '@dc-modules/overlay'
  9. import Draw from './Draw'
  10. import FineArrowGraphics from '../graphics/FineArrowGraphics'
  11. const DEF_STYLE = {
  12. material: Cesium.Color.YELLOW.withAlpha(0.6),
  13. fill: true
  14. }
  15. class DrawFineArrow extends Draw {
  16. constructor(style) {
  17. super()
  18. this._maxAnchorSize = 2
  19. this._style = {
  20. ...DEF_STYLE,
  21. ...style
  22. }
  23. this._graphics = new FineArrowGraphics()
  24. }
  25. /**
  26. *
  27. * @private
  28. */
  29. _mountedHook() {
  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 > 1) {
  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 fineArrow = new FineArrow(
  52. Transform.transformCartesianArrayToWGS84Array(this._positions)
  53. ).setStyle(this._style)
  54. this._options.onDrawStop && this._options.onDrawStop(fineArrow)
  55. }
  56. /**
  57. *
  58. * @param position
  59. * @private
  60. */
  61. _onDrawAnchor(position) {
  62. let len = this._positions.length
  63. this._positions.push(position)
  64. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  65. this._graphics.positions = this._positions
  66. if (len >= this._maxAnchorSize) {
  67. this._positions.pop()
  68. this.drawTool.fire(PlotEventType.DRAW_STOP)
  69. }
  70. }
  71. }
  72. export default DrawFineArrow