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.

EditPolyline.js 3.9KB

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