Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DrawRectangle.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-08-29 21:30:41
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import { PlotEventType } from '@dc-modules/event'
  7. import { Transform } from '@dc-modules/transform'
  8. import { Rectangle } from '@dc-modules/overlay'
  9. import Draw from './Draw'
  10. const DEF_STYLE = {
  11. material: Cesium.Color.YELLOW.withAlpha(0.6)
  12. }
  13. class DrawRectangle extends Draw {
  14. constructor(style) {
  15. super()
  16. this._maxAnchorSize = 2
  17. this._style = {
  18. ...DEF_STYLE,
  19. ...style
  20. }
  21. }
  22. /**
  23. *
  24. * @private
  25. */
  26. _mountedHook() {
  27. this.drawTool.tooltipMess = '左击选择点位'
  28. this._delegate = new Cesium.Entity({
  29. rectangle: {
  30. ...this._style,
  31. coordinates: new Cesium.CallbackProperty(time => {
  32. if (this._positions.length > 1) {
  33. return Cesium.Rectangle.fromCartesianArray(this._positions)
  34. } else {
  35. return null
  36. }
  37. }, false)
  38. }
  39. })
  40. this._layer.entities.add(this._delegate)
  41. }
  42. /**
  43. *
  44. * @private
  45. */
  46. _stopdHook() {
  47. let rectangle = new Rectangle(
  48. Transform.transformCartesianArrayToWGS84Array(this._positions)
  49. ).setStyle(this._style)
  50. this._options.onDrawStop && this._options.onDrawStop(rectangle)
  51. }
  52. /**
  53. *
  54. * @param position
  55. * @private
  56. */
  57. _onDrawAnchor(position) {
  58. let len = this._positions.length
  59. this._positions.push(position)
  60. this.drawTool.fire(PlotEventType.CREATE_ANCHOR, { position })
  61. if (len >= this._maxAnchorSize) {
  62. this._positions.pop()
  63. this.drawTool.fire(PlotEventType.DRAW_STOP)
  64. }
  65. }
  66. }
  67. export default DrawRectangle