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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 21:24:55
  4. */
  5. import Draw from './Draw'
  6. const { Transform } = DC
  7. const { Cesium } = DC.Namespace
  8. const DEF_STYLE = {
  9. material: Cesium.Color.YELLOW.withAlpha(0.6),
  10. fill: true
  11. }
  12. class DrawCircle extends Draw {
  13. constructor(style) {
  14. super()
  15. this._positions = []
  16. this._radius = 0
  17. this._style = {
  18. ...DEF_STYLE,
  19. ...style
  20. }
  21. }
  22. _mountEntity() {
  23. this._delegate = new Cesium.Entity({
  24. polygon: {
  25. ...this._style,
  26. hierarchy: new Cesium.CallbackProperty(() => {
  27. if (this._positions.length > 1) {
  28. this._radius = Cesium.Cartesian3.distance(
  29. this._positions[0],
  30. this._positions[1]
  31. )
  32. if (this._radius <= 0) {
  33. return null
  34. }
  35. let cep = Cesium.EllipseGeometryLibrary.computeEllipsePositions(
  36. {
  37. center: this._positions[0],
  38. semiMajorAxis: this._radius,
  39. semiMinorAxis: this._radius,
  40. rotation: 0,
  41. granularity: 0.005
  42. },
  43. false,
  44. true
  45. )
  46. let pnts = Cesium.Cartesian3.unpackArray(cep.outerPositions)
  47. pnts.push(pnts[0])
  48. return new Cesium.PolygonHierarchy(pnts)
  49. } else {
  50. return null
  51. }
  52. }, false)
  53. }
  54. })
  55. this._layer.add(this._delegate)
  56. }
  57. _onClick(e) {
  58. let len = this._positions.length
  59. let position = this._clampToGround ? e.surfacePosition : e.position
  60. if (len === 0) {
  61. this._positions.push(position)
  62. this.createAnchor(position, true)
  63. this._floatingAnchor = this.createAnchor(position)
  64. }
  65. this._positions.push(position)
  66. if (len > 0) {
  67. this.createAnchor(position)
  68. }
  69. if (len > 1) {
  70. this._positions.pop()
  71. this.unbindEvent()
  72. let circle = new DC.Circle(
  73. Transform.transformCartesianToWGS84(this._positions[0]),
  74. this._radius
  75. )
  76. circle.setStyle(this._style)
  77. this._plotEvent.raiseEvent(circle)
  78. }
  79. }
  80. _onMouseMove(e) {
  81. this._tooltip.showAt(e.windowPosition, '单击选择点位')
  82. if (this._floatingAnchor) {
  83. let position = this._clampToGround ? e.surfacePosition : e.position
  84. this._floatingAnchor.position.setValue(position)
  85. this._positions.pop()
  86. this._positions.push(position)
  87. }
  88. }
  89. }
  90. export default DrawCircle