You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-30 23:50:53
  4. */
  5. const { MouseEventType } = DC
  6. const { Cesium } = DC.Namespace
  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._layer = undefined
  18. this._anchorLayer = undefined
  19. this._layer = undefined
  20. this._plotEvent = undefined
  21. this._options = {}
  22. }
  23. _mountEntity() {}
  24. _mountAnchor() {}
  25. _onClick(e) {}
  26. _onMouseMove(e) {}
  27. _onRightClick(e) {}
  28. bindEvent() {
  29. this._viewer.on(MouseEventType.CLICK, this._onClick, this)
  30. this._viewer.on(MouseEventType.MOUSE_MOVE, this._onMouseMove, this)
  31. this._viewer.on(MouseEventType.RIGHT_CLICK, this._onRightClick, this)
  32. }
  33. unbindEvent() {
  34. this._viewer.off(MouseEventType.CLICK, this._onClick, this)
  35. this._viewer.off(MouseEventType.MOUSE_MOVE, this._onMouseMove, this)
  36. this._viewer.off(MouseEventType.RIGHT_CLICK, this._onRightClick, this)
  37. }
  38. createAnchor(position, index, isMid = false, isCenter = false) {
  39. let image = isMid
  40. ? this._options.icon_midAnchor
  41. : isCenter
  42. ? this._options.icon_center
  43. : this._options.icon_anchor
  44. let anchor = this._anchorLayer.add({
  45. position: position,
  46. billboard: {
  47. image: image,
  48. width: 12,
  49. height: 12,
  50. eyeOffset: new Cesium.ConstantProperty(
  51. new Cesium.Cartesian3(0, 0, -500)
  52. ),
  53. heightReference:
  54. this._viewer.scene.mode === Cesium.SceneMode.SCENE3D &&
  55. this._clampToGround
  56. ? Cesium.HeightReference.CLAMP_TO_GROUND
  57. : Cesium.HeightReference.NONE
  58. },
  59. properties: {
  60. isMid: isMid,
  61. index: index
  62. }
  63. })
  64. this._anchors.push(anchor)
  65. }
  66. computeMidPosition(p1, p2) {
  67. let c1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p1)
  68. let c2 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p2)
  69. let cm = new Cesium.EllipsoidGeodesic(c1, c2).interpolateUsingFraction(0.5)
  70. return Cesium.Ellipsoid.WGS84.cartographicToCartesian(cm)
  71. }
  72. start(plot) {
  73. this._viewer = plot.viewer
  74. this._tooltip = plot.viewer.tooltip
  75. this._layer = plot.overlayLayer
  76. this._anchorLayer = plot.anchorLayer
  77. this._plotEvent = plot.plotEvent
  78. this._options = plot.options
  79. this._clampToGround = plot.options.clampToGround ?? true
  80. this._mountEntity()
  81. this._mountAnchor()
  82. this.bindEvent()
  83. }
  84. }
  85. export default Edit