選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DrawRectangle.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 21:30:41
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { Transform } from '@dc-modules/transform'
  7. import { Rectangle } from '@dc-modules/overlay'
  8. import Draw from './Draw'
  9. const DEF_STYLE = {
  10. material: Cesium.Color.YELLOW.withAlpha(0.6)
  11. }
  12. class DrawRectangle extends Draw {
  13. constructor(style) {
  14. super()
  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. if (!position) {
  38. return false
  39. }
  40. let len = this._positions.length
  41. if (len === 0) {
  42. this._positions.push(position)
  43. this.createAnchor(position)
  44. this._floatingAnchor = this.createAnchor(position)
  45. }
  46. this._positions.push(position)
  47. this.createAnchor(position)
  48. if (len > 1) {
  49. this._positions.pop()
  50. this.unbindEvent()
  51. let rectangle = new Rectangle(
  52. Transform.transformCartesianArrayToWGS84Array(this._positions)
  53. )
  54. rectangle.setStyle(this._style)
  55. this._plotEvent.raiseEvent(rectangle)
  56. }
  57. }
  58. }
  59. export default DrawRectangle