Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

EditCircle.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-31 10:54:38
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { Transform } from '@dc-modules/transform'
  7. import Edit from './Edit'
  8. class EditCircle extends Edit {
  9. constructor(overlay) {
  10. super()
  11. this._overlay = overlay
  12. this._center = undefined
  13. this._radius = 0
  14. }
  15. _mountEntity() {
  16. this._radius = this._overlay.radius
  17. this._center = Transform.transformWGS84ToCartesian(this._overlay.center)
  18. this._overlay.show = false
  19. this._delegate = new Cesium.Entity({
  20. polygon: {
  21. material: this._overlay.delegate?.polygon?.material
  22. }
  23. })
  24. this._positions = [].concat([
  25. this._center,
  26. this._computeCirclePoints(this._center, this._radius)[0]
  27. ])
  28. this._delegate.polygon.hierarchy = new Cesium.CallbackProperty(time => {
  29. if (this._positions.length > 1) {
  30. this._radius = Cesium.Cartesian3.distance(
  31. this._positions[0],
  32. this._positions[1]
  33. )
  34. if (this._radius <= 0) {
  35. return null
  36. }
  37. let pnts = this._computeCirclePoints(this._positions[0], this._radius)
  38. pnts.push(pnts[0])
  39. return new Cesium.PolygonHierarchy(pnts)
  40. } else {
  41. return null
  42. }
  43. }, false)
  44. this._layer.add(this._delegate)
  45. }
  46. _mountAnchor() {
  47. this._positions.forEach((item, index) => {
  48. this.createAnchor(item, index, false, index % 2 === 0)
  49. })
  50. }
  51. _computeCirclePoints(center, radius) {
  52. let pnts = []
  53. let cep = Cesium.EllipseGeometryLibrary.computeEllipsePositions(
  54. {
  55. center: center,
  56. semiMajorAxis: radius,
  57. semiMinorAxis: radius,
  58. rotation: 0,
  59. granularity: 0.005
  60. },
  61. false,
  62. true
  63. )
  64. if (cep && cep.outerPositions) {
  65. pnts = Cesium.Cartesian3.unpackArray(cep.outerPositions)
  66. }
  67. return pnts
  68. }
  69. _onClick(e) {
  70. let now = Cesium.JulianDate.now()
  71. if (this._isMoving) {
  72. this._isMoving = false
  73. if (this._pickedAnchor && this._pickedAnchor.position) {
  74. let position = this._clampToGround ? e.surfacePosition : e.position
  75. if (!position) {
  76. return false
  77. }
  78. this._pickedAnchor.position.setValue(position)
  79. let properties = this._pickedAnchor.properties.getValue(now)
  80. this._positions[properties.index] = position
  81. }
  82. } else {
  83. this._isMoving = true
  84. if (!e.target || !e.target.id) {
  85. return false
  86. }
  87. this._pickedAnchor = e.target.id
  88. }
  89. }
  90. _onRightClick(e) {
  91. this.unbindEvent()
  92. this._overlay.center = Transform.transformCartesianToWGS84(
  93. this._positions[0]
  94. )
  95. this._overlay.radius = this._radius
  96. this._overlay.show = true
  97. this._plotEvent.raiseEvent(this._overlay)
  98. }
  99. }
  100. export default EditCircle