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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-02-25 18:28:36
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-04-16 20:29:02
  6. */
  7. import Cesium from '@/namespace'
  8. import Overlay from '@/core/overlay/Overlay'
  9. DC.Box = class extends Overlay {
  10. constructor(position, length, width, height) {
  11. if (!DC.Util.checkPosition(position)) {
  12. throw new Error('DC.Box: the position invalid')
  13. }
  14. super()
  15. this._position = position
  16. this._length = length
  17. this._width = width
  18. this._height = height
  19. this._delegate = new Cesium.Entity()
  20. this._state = DC.OverlayState.INITIALIZED
  21. this.type = DC.OverlayType.BOX
  22. }
  23. set position(position) {
  24. if (!DC.Util.checkPosition(position)) {
  25. throw new Error('DC.Box: the position invalid')
  26. }
  27. this._position = position
  28. }
  29. get position() {
  30. return this._position
  31. }
  32. set length(length) {
  33. this._length = length
  34. }
  35. get length() {
  36. return this._length
  37. }
  38. set width(width) {
  39. this._width = width
  40. }
  41. get width() {
  42. return this._width
  43. }
  44. set height(height) {
  45. this._height = height
  46. }
  47. get height() {
  48. return this._height
  49. }
  50. _mountedHook() {
  51. /**
  52. * set the location
  53. */
  54. this._delegate.position = new Cesium.CallbackProperty(time => {
  55. return DC.T.transformWGS84ToCartesian(this._position)
  56. })
  57. /**
  58. * set the orientation
  59. */
  60. this._delegate.orientation = new Cesium.CallbackProperty(time => {
  61. return Cesium.Transforms.headingPitchRollQuaternion(
  62. DC.T.transformWGS84ToCartesian(this._position),
  63. new Cesium.HeadingPitchRoll(
  64. Cesium.Math.toRadians(this._position.heading),
  65. Cesium.Math.toRadians(this._position.pitch),
  66. Cesium.Math.toRadians(this._position.roll)
  67. )
  68. )
  69. })
  70. /**
  71. * initialize the Overlay parameter
  72. */
  73. this._delegate.box = {
  74. ...this._style,
  75. dimensions: new Cesium.CallbackProperty(time => {
  76. return new Cesium.Cartesian3(this._length, this._width, this._height)
  77. })
  78. }
  79. }
  80. /**
  81. *
  82. * @param {*} style
  83. */
  84. setStyle(style) {
  85. if (Object.keys(style).length == 0) {
  86. return this
  87. }
  88. this._style = style
  89. this._delegate.box && DC.Util.merge(this._delegate.box, this._style)
  90. return this
  91. }
  92. }
  93. DC.OverlayType.BOX = 'box'