Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @Author : Caven Chen
  3. */
  4. import { Cesium } from '../../../namespace'
  5. import Overlay from '../Overlay'
  6. import State from '../../state/State'
  7. import Parse from '../../parse/Parse'
  8. import { Util } from '../../utils'
  9. import { Transform } from '../../transform'
  10. class Plane extends Overlay {
  11. constructor(position, width, height, plane = {}) {
  12. super()
  13. this._position = Parse.parsePosition(position)
  14. this._width = +width || 100
  15. this._height = +height || 100
  16. if (plane.normal && typeof plane.normal === 'string') {
  17. let n = String(plane.normal).toLocaleUpperCase()
  18. plane.normal =
  19. n === 'X'
  20. ? Cesium.Cartesian3.UNIT_X
  21. : n === 'Y'
  22. ? Cesium.Cartesian3.UNIT_Y
  23. : Cesium.Cartesian3.UNIT_Z
  24. } else {
  25. plane.normal = Cesium.Cartesian3.UNIT_Z
  26. }
  27. this._normal = plane.normal
  28. this._distance = plane.distance || 0
  29. this._delegate = new Cesium.Entity({
  30. plane: {
  31. dimensions: {
  32. x: this._width,
  33. y: this._height,
  34. },
  35. plane: new Cesium.Plane(this._normal, this._distance),
  36. },
  37. })
  38. this._state = State.INITIALIZED
  39. }
  40. get type() {
  41. return Overlay.getOverlayType('plane')
  42. }
  43. set position(position) {
  44. this._position = Parse.parsePosition(position)
  45. this._delegate.position = Transform.transformWGS84ToCartesian(
  46. this._position
  47. )
  48. this._delegate.orientation = Cesium.Transforms.headingPitchRollQuaternion(
  49. Transform.transformWGS84ToCartesian(this._position),
  50. new Cesium.HeadingPitchRoll(
  51. Cesium.Math.toRadians(this._position.heading),
  52. Cesium.Math.toRadians(this._position.pitch),
  53. Cesium.Math.toRadians(this._position.roll)
  54. )
  55. )
  56. }
  57. get position() {
  58. return this._position
  59. }
  60. set width(width) {
  61. const dimensions = this._delegate.plane.dimensions.getValue()
  62. this._width = +width || 0
  63. dimensions.x = this._width
  64. }
  65. get width() {
  66. return this._width
  67. }
  68. set height(height) {
  69. const dimensions = this._delegate.plane.dimensions.getValue()
  70. this._height = +height || 0
  71. dimensions.y = this._height
  72. }
  73. get height() {
  74. return this._height
  75. }
  76. set distance(distance) {
  77. const plane = this.entityGraphic.plane.getValue()
  78. this._distance = distance
  79. plane.distance = distance
  80. }
  81. get distance() {
  82. return this._distance
  83. }
  84. _mountedHook() {
  85. /**
  86. * set the location
  87. */
  88. this.position = this._position
  89. /**
  90. * initialize the Overlay parameter
  91. */
  92. this.distance = this._distance
  93. }
  94. /**
  95. * Sets Style
  96. * @param style
  97. * @returns {Plane}
  98. */
  99. setStyle(style) {
  100. if (Object.keys(style).length === 0) {
  101. return this
  102. }
  103. delete style['dimensions'] && delete ['plane']
  104. Util.merge(this._style, style)
  105. Util.merge(this._delegate.plane, style)
  106. return this
  107. }
  108. }
  109. Overlay.registerType('plane')
  110. export default Plane