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.

EditRectangle.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-30 23:41:34
  4. */
  5. import Edit from './Edit'
  6. const { Transform } = DC
  7. const { Cesium } = DC.Namespace
  8. class EditRectangle extends Edit {
  9. constructor(overlay) {
  10. super()
  11. this._overlay = overlay
  12. this._positions = []
  13. }
  14. _mountEntity() {
  15. this._delegate = new Cesium.Entity()
  16. this._delegate.merge(this._overlay.delegate)
  17. this._overlay.show = false
  18. this._delegate.rectangle.coordinates = new Cesium.CallbackProperty(time => {
  19. if (this._positions.length > 1) {
  20. return Cesium.Rectangle.fromCartesianArray(this._positions)
  21. } else {
  22. return null
  23. }
  24. }, false)
  25. this._layer.add(this._delegate)
  26. }
  27. _mountAnchor() {
  28. this._positions = [].concat(
  29. Transform.transformWGS84ArrayToCartesianArray(this._overlay.positions)
  30. )
  31. this._positions.forEach((item, index) => {
  32. this.createAnchor(item, index)
  33. })
  34. }
  35. _onClick(e) {
  36. if (this._isMoving) {
  37. this._isMoving = false
  38. if (this._pickedAnchor && this._pickedAnchor.position) {
  39. let position = this._clampToGround ? e.surfacePosition : e.position
  40. this._pickedAnchor.position.setValue(position)
  41. let properties = this._pickedAnchor.properties.getValue(
  42. Cesium.JulianDate.now()
  43. )
  44. this._positions[properties.index] = position
  45. }
  46. } else {
  47. this._isMoving = true
  48. if (!e.target || !e.target.id) {
  49. return false
  50. }
  51. this._pickedAnchor = e.target.id
  52. }
  53. }
  54. _onMouseMove(e) {
  55. this._tooltip.showAt(e.windowPosition, '点击锚点移动,右击结束编辑')
  56. if (!this._isMoving) {
  57. return
  58. }
  59. if (this._pickedAnchor && this._pickedAnchor.position) {
  60. let properties = this._pickedAnchor.properties.getValue(
  61. Cesium.JulianDate.now()
  62. )
  63. let position = this._clampToGround ? e.surfacePosition : e.position
  64. this._pickedAnchor.position.setValue(position)
  65. this._positions[properties.index] = position
  66. }
  67. }
  68. _onRightClick(e) {
  69. this.unbindEvent()
  70. this._overlay.positions = Transform.transformCartesianArrayToWGS84Array(
  71. this._positions
  72. )
  73. this._overlay.show = true
  74. this._plotEvent.raiseEvent(this._overlay)
  75. }
  76. }
  77. export default EditRectangle