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.

DrawRectangle.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 21:30:41
  4. */
  5. import Draw from './Draw'
  6. const { Transform } = DC
  7. const { Cesium } = DC.Namespace
  8. const DEF_STYLE = {
  9. material: Cesium.Color.YELLOW.withAlpha(0.6)
  10. }
  11. class DrawRectangle extends Draw {
  12. constructor(style) {
  13. super()
  14. this._positions = []
  15. this._style = {
  16. ...DEF_STYLE,
  17. ...style
  18. }
  19. }
  20. _mountEntity() {
  21. this._delegate = new Cesium.Entity({
  22. rectangle: {
  23. ...this._style,
  24. coordinates: new Cesium.CallbackProperty(time => {
  25. if (this._positions.length > 1) {
  26. return Cesium.Rectangle.fromCartesianArray(this._positions)
  27. } else {
  28. return null
  29. }
  30. }, false)
  31. }
  32. })
  33. this._layer.add(this._delegate)
  34. }
  35. _onClick(e) {
  36. let position = this._clampToGround ? e.surfacePosition : e.position
  37. let len = this._positions.length
  38. if (len === 0) {
  39. this._positions.push(position)
  40. this.createAnchor(position)
  41. this._floatingAnchor = this.createAnchor(position)
  42. }
  43. this._positions.push(position)
  44. this.createAnchor(position)
  45. if (len > 1) {
  46. this._positions.pop()
  47. this.unbindEvent()
  48. let rectangle = new DC.Rectangle(
  49. Transform.transformCartesianArrayToWGS84Array(this._positions)
  50. )
  51. rectangle.setStyle(this._style)
  52. this._plotEvent.raiseEvent(rectangle)
  53. }
  54. }
  55. _onMouseMove(e) {
  56. this._tooltip.showAt(e.windowPosition, '左击选择点位')
  57. if (this._floatingAnchor) {
  58. let position = this._clampToGround ? e.surfacePosition : e.position
  59. this._floatingAnchor.position.setValue(position)
  60. this._positions.pop()
  61. this._positions.push(position)
  62. }
  63. }
  64. }
  65. export default DrawRectangle