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.

EditPolygon.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-30 23:12:09
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { PlotEventType } from '@dc-modules/event'
  7. import { Transform } from '@dc-modules/transform'
  8. import { midCartesian } from '@dc-modules/math'
  9. import Edit from './Edit'
  10. class EditPolygon extends Edit {
  11. constructor(overlay) {
  12. super(overlay)
  13. }
  14. /**
  15. *
  16. * @private
  17. */
  18. _mountedHook() {
  19. this._delegate.polygon.hierarchy = new Cesium.CallbackProperty(time => {
  20. if (this._positions.length > 2) {
  21. return new Cesium.PolygonHierarchy(this._positions)
  22. } else {
  23. return null
  24. }
  25. }, false)
  26. this._layer.entities.add(this._delegate)
  27. }
  28. /**
  29. *
  30. * @private
  31. */
  32. _mountAnchor() {
  33. let positions = [].concat(
  34. this._overlay.delegate.polygon.hierarchy.getValue(Cesium.JulianDate.now())
  35. .positions
  36. )
  37. positions.push(positions[0])
  38. for (let i = 0; i < positions.length - 1; i++) {
  39. let mid = midCartesian(positions[i], positions[i + 1])
  40. this._positions.push(positions[i])
  41. this._positions.push(mid)
  42. }
  43. this._positions.forEach((item, index) => {
  44. this.editTool.fire(PlotEventType.CREATE_ANCHOR, {
  45. position: item,
  46. index: index,
  47. isMid: index % 2 !== 0
  48. })
  49. })
  50. }
  51. /**
  52. *
  53. * @param pickedAnchor
  54. * @param position
  55. * @returns {boolean}
  56. * @private
  57. */
  58. _onEditAnchorStop({ pickedAnchor, position }) {
  59. let properties = pickedAnchor.properties.getValue(Cesium.JulianDate.now())
  60. let currentIndex = properties.index
  61. if (properties.isMid) {
  62. let preMidPosition
  63. let nextMidPosition
  64. let len = this._positions.length
  65. if (currentIndex === len - 1) {
  66. preMidPosition = midCartesian(
  67. this._positions[currentIndex],
  68. this._positions[currentIndex - 1]
  69. )
  70. nextMidPosition = midCartesian(
  71. this._positions[currentIndex],
  72. this._positions[0]
  73. )
  74. } else {
  75. preMidPosition = midCartesian(
  76. this._positions[currentIndex],
  77. this._positions[currentIndex - 1]
  78. )
  79. nextMidPosition = midCartesian(
  80. this._positions[currentIndex],
  81. this._positions[currentIndex + 1]
  82. )
  83. }
  84. this._positions.splice(
  85. currentIndex,
  86. 1,
  87. preMidPosition,
  88. position,
  89. nextMidPosition
  90. )
  91. this.editTool.fire(PlotEventType.CLEAR_ANCHOR)
  92. this._positions.forEach((item, index) => {
  93. this.editTool.fire(PlotEventType.CREATE_ANCHOR, {
  94. position: item,
  95. index: index,
  96. isMid: index % 2 !== 0
  97. })
  98. })
  99. }
  100. }
  101. /**
  102. *
  103. * @param pickedAnchor
  104. * @param position
  105. * @private
  106. */
  107. _onAnchorMoving({ pickedAnchor, position }) {
  108. let properties = pickedAnchor.properties.getValue(Cesium.JulianDate.now())
  109. let currentIndex = properties.index
  110. this._positions[currentIndex] = position
  111. let len = this._positions.length
  112. if (!properties.isMid) {
  113. let preAnchorIndex = -1
  114. let preMidAnchorIndex = -1
  115. let nextAnchorIndex = -1
  116. let nextMidAnchorIndex = -1
  117. if (currentIndex === 0) {
  118. preAnchorIndex = len - 2
  119. preMidAnchorIndex = len - 1
  120. nextAnchorIndex = currentIndex + 2
  121. nextMidAnchorIndex = currentIndex + 1
  122. } else if (currentIndex === len - 2) {
  123. preAnchorIndex = currentIndex - 2
  124. preMidAnchorIndex = currentIndex - 1
  125. nextAnchorIndex = 0
  126. nextMidAnchorIndex = len - 1
  127. } else {
  128. preAnchorIndex = currentIndex - 2
  129. preMidAnchorIndex = currentIndex - 1
  130. nextAnchorIndex = currentIndex + 2
  131. nextMidAnchorIndex = currentIndex + 1
  132. }
  133. let preMidPosition = midCartesian(
  134. this._positions[preAnchorIndex],
  135. this._positions[currentIndex]
  136. )
  137. let nextMidPosition = midCartesian(
  138. this._positions[nextAnchorIndex],
  139. this._positions[currentIndex]
  140. )
  141. this._positions[preMidAnchorIndex] = preMidPosition
  142. this._positions[nextMidAnchorIndex] = nextMidPosition
  143. this.editTool.fire(PlotEventType.UPDATE_ANCHOR, {
  144. index: preMidAnchorIndex,
  145. position: preMidPosition
  146. })
  147. this.editTool.fire(PlotEventType.UPDATE_ANCHOR, {
  148. index: nextMidAnchorIndex,
  149. position: nextMidPosition
  150. })
  151. }
  152. }
  153. }
  154. export default EditPolygon