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 2.4KB

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