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.

Edit.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-30 23:50:53
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { MouseEventType } from '@dc-modules/event'
  7. class Edit {
  8. constructor() {
  9. this._viewer = undefined
  10. this._overlay = undefined
  11. this._anchors = []
  12. this._delegate = undefined
  13. this._pickedAnchor = undefined
  14. this._isMoving = false
  15. this._clampToGround = true
  16. this._tooltip = undefined
  17. this._tooltipMess = '点击锚点移动,右击结束编辑'
  18. this._layer = undefined
  19. this._anchorLayer = undefined
  20. this._layer = undefined
  21. this._plotEvent = undefined
  22. this._options = {}
  23. this._positions = []
  24. }
  25. _mountEntity() {}
  26. _mountAnchor() {}
  27. _onClick(e) {}
  28. _onMouseMove(e) {
  29. this._tooltip.showAt(e.windowPosition, this._tooltipMess)
  30. if (!this._isMoving) {
  31. return false
  32. }
  33. if (this._pickedAnchor && this._pickedAnchor.position) {
  34. let properties = this._pickedAnchor.properties.getValue(
  35. Cesium.JulianDate.now()
  36. )
  37. let position = this._clampToGround ? e.surfacePosition : e.position
  38. if (!position) {
  39. return false
  40. }
  41. this._pickedAnchor.position.setValue(position)
  42. this._positions[properties.index] = position
  43. }
  44. }
  45. _onRightClick(e) {}
  46. bindEvent() {
  47. this._viewer.on(MouseEventType.CLICK, this._onClick, this)
  48. this._viewer.on(MouseEventType.MOUSE_MOVE, this._onMouseMove, this)
  49. this._viewer.on(MouseEventType.RIGHT_CLICK, this._onRightClick, this)
  50. }
  51. unbindEvent() {
  52. this._viewer.off(MouseEventType.CLICK, this._onClick, this)
  53. this._viewer.off(MouseEventType.MOUSE_MOVE, this._onMouseMove, this)
  54. this._viewer.off(MouseEventType.RIGHT_CLICK, this._onRightClick, this)
  55. }
  56. /**
  57. *
  58. * @param position
  59. * @param index
  60. * @param isMid
  61. * @param isCenter
  62. */
  63. createAnchor(position, index, isMid = false, isCenter = false) {
  64. let image = isMid
  65. ? this._options.icon_midAnchor
  66. : isCenter
  67. ? this._options.icon_center
  68. : this._options.icon_anchor
  69. let anchor = this._anchorLayer.add({
  70. position: position,
  71. billboard: {
  72. image: image,
  73. width: 12,
  74. height: 12,
  75. eyeOffset: new Cesium.ConstantProperty(
  76. new Cesium.Cartesian3(0, 0, -500)
  77. ),
  78. heightReference:
  79. this._viewer.scene.mode === Cesium.SceneMode.SCENE3D &&
  80. this._clampToGround
  81. ? Cesium.HeightReference.CLAMP_TO_GROUND
  82. : Cesium.HeightReference.NONE
  83. },
  84. properties: {
  85. isMid: isMid,
  86. index: index
  87. }
  88. })
  89. this._anchors.push(anchor)
  90. }
  91. /**
  92. *
  93. * @param p1
  94. * @param p2
  95. * @returns {Cartesian3}
  96. */
  97. computeMidPosition(p1, p2) {
  98. let c1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p1)
  99. let c2 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p2)
  100. let cm = new Cesium.EllipsoidGeodesic(c1, c2).interpolateUsingFraction(0.5)
  101. return Cesium.Ellipsoid.WGS84.cartographicToCartesian(cm)
  102. }
  103. /**
  104. *
  105. * @param plot
  106. * @param clampToGround
  107. */
  108. start(plot, clampToGround) {
  109. this._viewer = plot.viewer
  110. this._tooltip = plot.viewer.tooltip
  111. this._layer = plot.overlayLayer
  112. this._anchorLayer = plot.anchorLayer
  113. this._plotEvent = plot.plotEvent
  114. this._options = plot.options
  115. this._clampToGround = clampToGround
  116. this._mountEntity()
  117. this._mountAnchor()
  118. this.bindEvent()
  119. }
  120. }
  121. export default Edit