Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

EditCircle.js 3.2KB

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