You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DrawGatheringPlace.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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._positions = []
  18. this._floatingAnchor = undefined
  19. this._style = {
  20. ...DEF_STYLE,
  21. ...style
  22. }
  23. this._graphics = new GatheringPlaceGraphics()
  24. }
  25. _mountEntity() {
  26. this._delegate = new Cesium.Entity({
  27. polygon: {
  28. ...this._style,
  29. hierarchy: new Cesium.CallbackProperty(() => {
  30. if (this._positions.length > 1) {
  31. this._graphics.positions = this._positions
  32. return this._graphics.hierarchy
  33. } else {
  34. return null
  35. }
  36. }, false)
  37. }
  38. })
  39. this._layer.add(this._delegate)
  40. }
  41. _onClick(e) {
  42. let position = this._clampToGround ? e.surfacePosition : e.position
  43. let len = this._positions.length
  44. if (len === 0) {
  45. this._positions.push(position)
  46. this.createAnchor(position)
  47. this._floatingAnchor = this.createAnchor(position)
  48. }
  49. this._positions.push(position)
  50. this._graphics.positions = this._positions
  51. this.createAnchor(position)
  52. if (len > 2) {
  53. this._positions.pop()
  54. this.unbindEvent()
  55. let gatheringPlace = new GatheringPlace(
  56. Transform.transformCartesianArrayToWGS84Array(this._positions)
  57. )
  58. gatheringPlace.setStyle(this._style)
  59. this._plotEvent.raiseEvent(gatheringPlace)
  60. }
  61. }
  62. _onMouseMove(e) {
  63. this._tooltip.showAt(e.windowPosition, '单击选择点位')
  64. if (this._floatingAnchor) {
  65. let position = this._clampToGround ? e.surfacePosition : e.position
  66. this._floatingAnchor.position.setValue(position)
  67. this._positions.pop()
  68. this._positions.push(position)
  69. }
  70. }
  71. }
  72. export default DrawGatheringPlace