Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DrawGatheringPlace.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 { GatheringPlace } from '@dc-modules/overlay'
  8. import Draw from './Draw'
  9. import GatheringPlaceGraphics from '../graphics/GatheringPlaceGraphics'
  10. const DEF_STYLE = {
  11. material: Cesium.Color.YELLOW.withAlpha(0.6),
  12. fill: true
  13. }
  14. class DrawGatheringPlace extends Draw {
  15. constructor(style) {
  16. super()
  17. this._floatingAnchor = undefined
  18. this._style = {
  19. ...DEF_STYLE,
  20. ...style
  21. }
  22. this._graphics = new GatheringPlaceGraphics()
  23. }
  24. _mountEntity() {
  25. this._delegate = new Cesium.Entity({
  26. polygon: {
  27. ...this._style,
  28. hierarchy: new Cesium.CallbackProperty(() => {
  29. if (this._positions.length > 1) {
  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 gatheringPlace = new GatheringPlace(
  55. Transform.transformCartesianArrayToWGS84Array(this._positions)
  56. )
  57. gatheringPlace.setStyle(this._style)
  58. this._plotEvent.raiseEvent(gatheringPlace)
  59. }
  60. }
  61. }
  62. export default DrawGatheringPlace