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.

Box.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-02-25 18:28:36
  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 Box extends Overlay {
  12. constructor(position, length, width, height) {
  13. super()
  14. this._position = Parse.parsePosition(position)
  15. this._length = length
  16. this._width = width
  17. this._height = height
  18. this._delegate = new Cesium.Entity({
  19. box: {
  20. dimensions: {
  21. x: +this._length,
  22. y: +this._width,
  23. z: +this._height
  24. }
  25. }
  26. })
  27. this.type = Overlay.getOverlayType('box')
  28. this._state = State.INITIALIZED
  29. }
  30. /**
  31. *
  32. * @param position
  33. * @returns {Box}
  34. */
  35. set position(position) {
  36. this._position = Parse.parsePosition(position)
  37. this._delegate.position = Transform.transformWGS84ToCartesian(
  38. this._position
  39. )
  40. this._delegate.orientation = Cesium.Transforms.headingPitchRollQuaternion(
  41. Transform.transformWGS84ToCartesian(this._position),
  42. new Cesium.HeadingPitchRoll(
  43. Cesium.Math.toRadians(this._position.heading),
  44. Cesium.Math.toRadians(this._position.pitch),
  45. Cesium.Math.toRadians(this._position.roll)
  46. )
  47. )
  48. return this
  49. }
  50. get position() {
  51. return this._position
  52. }
  53. set length(length) {
  54. this._length = length || 0
  55. this._delegate.box.dimensions.x = +this._length
  56. return this
  57. }
  58. get length() {
  59. return this._length
  60. }
  61. set width(width) {
  62. this._width = width || 0
  63. this._delegate.box.dimensions.y = +this._width
  64. return this
  65. }
  66. get width() {
  67. return this._width
  68. }
  69. set height(height) {
  70. this._height = height || 0
  71. this._delegate.box.dimensions.z = +this._height
  72. return this
  73. }
  74. get height() {
  75. return this._height
  76. }
  77. _mountedHook() {
  78. /**
  79. * set the location
  80. */
  81. this.position = this._position
  82. }
  83. /**
  84. * Sets Style
  85. * @param style
  86. * @returns {Box}
  87. */
  88. setStyle(style) {
  89. if (Object.keys(style).length === 0) {
  90. return this
  91. }
  92. delete style['length'] && delete style['width'] && delete style['height']
  93. this._style = style
  94. Util.merge(this._delegate.box, this._style)
  95. return this
  96. }
  97. }
  98. Overlay.registerType('box')
  99. export default Box