Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Box.js 2.4KB

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