Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DrawCircle.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 21:24:55
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { PlotEventType } from '@dc-modules/event'
  7. import { Transform } from '@dc-modules/transform'
  8. import { Circle } from '@dc-modules/overlay'
  9. import Draw from './Draw'
  10. const DEF_STYLE = {
  11. material: Cesium.Color.YELLOW.withAlpha(0.6),
  12. fill: true
  13. }
  14. class DrawCircle extends Draw {
  15. constructor(style) {
  16. super()
  17. this._maxAnchorSize = 2
  18. this._radius = 0
  19. this._style = {
  20. ...DEF_STYLE,
  21. ...style
  22. }
  23. }
  24. /**
  25. *
  26. * @private
  27. */
  28. _mountedHook() {
  29. this.drawTool.tooltipMess = '单击选择点位'
  30. this._delegate = new Cesium.Entity({
  31. polygon: {
  32. ...this._style,
  33. hierarchy: new Cesium.CallbackProperty(() => {
  34. if (this._positions.length > 1) {
  35. this._radius = Cesium.Cartesian3.distance(
  36. this._positions[0],
  37. this._positions[1]
  38. )
  39. if (this._radius <= 0) {
  40. return null
  41. }
  42. let cep = Cesium.EllipseGeometryLibrary.computeEllipsePositions(
  43. {
  44. center: this._positions[0],
  45. semiMajorAxis: this._radius,
  46. semiMinorAxis: this._radius,
  47. rotation: 0,
  48. granularity: 0.005
  49. },
  50. false,
  51. true
  52. )
  53. let pnts = Cesium.Cartesian3.unpackArray(cep.outerPositions)
  54. pnts.push(pnts[0])
  55. return new Cesium.PolygonHierarchy(pnts)
  56. } else {
  57. return null
  58. }
  59. }, false)
  60. }
  61. })
  62. this._layer.entities.add(this._delegate)
  63. }
  64. /**
  65. *
  66. * @private
  67. */
  68. _stopdHook() {
  69. let circle = null
  70. if (this._positions.length) {
  71. circle = new Circle(
  72. Transform.transformCartesianToWGS84(this._positions[0]),
  73. this._radius
  74. ).setStyle(this._style)
  75. }
  76. this._options.onDrawStop && this._options.onDrawStop(circle)
  77. }
  78. /**
  79. *
  80. * @param position
  81. * @private
  82. */
  83. _onDrawAnchor(position) {
  84. let len = this._positions.length
  85. this._positions.push(position)
  86. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, {
  87. position,
  88. isCenter: len === 1
  89. })
  90. if (len >= this._maxAnchorSize) {
  91. this._positions.pop()
  92. this.drawTool.fire(PlotEventType.DRAW_STOP)
  93. }
  94. }
  95. }
  96. export default DrawCircle