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.

Rectangle.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-04-14 20:46:23
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import State from '@dc-modules/state/State'
  7. import Parse from '@dc-modules/parse/Parse'
  8. import { Util } from '@dc-modules/utils'
  9. import { Transform } from '@dc-modules/transform'
  10. import Overlay from '../Overlay'
  11. class Rectangle extends Overlay {
  12. constructor(positions) {
  13. super()
  14. this._positions = Parse.parsePositions(positions)
  15. this._delegate = new Cesium.Entity({ rectangle: {} })
  16. this._state = State.INITIALIZED
  17. }
  18. get type() {
  19. return Overlay.getOverlayType('rectangle')
  20. }
  21. set positions(positions) {
  22. this._positions = Parse.parsePositions(positions)
  23. this._delegate.rectangle.coordinates = Cesium.Rectangle.fromCartesianArray(
  24. Transform.transformWGS84ArrayToCartesianArray(this._positions)
  25. )
  26. return this
  27. }
  28. get positions() {
  29. return this._positions
  30. }
  31. _mountedHook() {
  32. /**
  33. * set the location
  34. */
  35. this.positions = this._positions
  36. }
  37. /**
  38. * @param text
  39. * @param textStyle
  40. * @returns {Rectangle}
  41. */
  42. setLabel(text, textStyle) {
  43. return this
  44. }
  45. /**
  46. * Sets Style
  47. * @param style
  48. * @returns {Rectangle}
  49. */
  50. setStyle(style) {
  51. if (Object.keys(style).length === 0) {
  52. return this
  53. }
  54. delete style['positions']
  55. Util.merge(this._style, style)
  56. Util.merge(this._delegate.rectangle, style)
  57. return this
  58. }
  59. }
  60. Overlay.registerType('rectangle')
  61. export default Rectangle