選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DrawGatheringPlace.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-30 17:22:21
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { Transform } from '@dc-modules/transform'
  7. import { PlotEventType } from '@dc-modules/event'
  8. import { GatheringPlace } from '@dc-modules/overlay'
  9. import Draw from './Draw'
  10. import GatheringPlaceGraphics from '../graphics/GatheringPlaceGraphics'
  11. const DEF_STYLE = {
  12. material: Cesium.Color.YELLOW.withAlpha(0.6),
  13. fill: true
  14. }
  15. class DrawGatheringPlace extends Draw {
  16. constructor(style) {
  17. super()
  18. this._maxAnchorSize = 3
  19. this._style = {
  20. ...DEF_STYLE,
  21. ...style
  22. }
  23. this._graphics = new GatheringPlaceGraphics()
  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 gatheringPlace = null
  52. if (this._positions.length) {
  53. gatheringPlace = new GatheringPlace(
  54. Transform.transformCartesianArrayToWGS84Array(this._positions)
  55. ).setStyle(this._style)
  56. }
  57. this._options.onDrawStop && this._options.onDrawStop(gatheringPlace)
  58. }
  59. /**
  60. *
  61. * @param position
  62. * @private
  63. */
  64. _onDrawAnchor(position) {
  65. let len = this._positions.length
  66. this._positions.push(position)
  67. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  68. this._graphics.positions = this._positions
  69. if (len >= this._maxAnchorSize) {
  70. this._positions.pop()
  71. this.drawTool.fire(PlotEventType.DRAW_STOP)
  72. }
  73. }
  74. }
  75. export default DrawGatheringPlace