Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Edit.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. createAnchor(position, index, isMid = false, isCenter = false) {
  57. let image = isMid
  58. ? this._options.icon_midAnchor
  59. : isCenter
  60. ? this._options.icon_center
  61. : this._options.icon_anchor
  62. let anchor = this._anchorLayer.add({
  63. position: position,
  64. billboard: {
  65. image: image,
  66. width: 12,
  67. height: 12,
  68. eyeOffset: new Cesium.ConstantProperty(
  69. new Cesium.Cartesian3(0, 0, -500)
  70. ),
  71. heightReference:
  72. this._viewer.scene.mode === Cesium.SceneMode.SCENE3D &&
  73. this._clampToGround
  74. ? Cesium.HeightReference.CLAMP_TO_GROUND
  75. : Cesium.HeightReference.NONE
  76. },
  77. properties: {
  78. isMid: isMid,
  79. index: index
  80. }
  81. })
  82. this._anchors.push(anchor)
  83. }
  84. computeMidPosition(p1, p2) {
  85. let c1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p1)
  86. let c2 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p2)
  87. let cm = new Cesium.EllipsoidGeodesic(c1, c2).interpolateUsingFraction(0.5)
  88. return Cesium.Ellipsoid.WGS84.cartographicToCartesian(cm)
  89. }
  90. start(plot) {
  91. this._viewer = plot.viewer
  92. this._tooltip = plot.viewer.tooltip
  93. this._layer = plot.overlayLayer
  94. this._anchorLayer = plot.anchorLayer
  95. this._plotEvent = plot.plotEvent
  96. this._options = plot.options
  97. this._clampToGround = plot.options.clampToGround ?? true
  98. this._mountEntity()
  99. this._mountAnchor()
  100. this.bindEvent()
  101. }
  102. }
  103. export default Edit