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.

Plane.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-02-18 19:08:26
  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 Plane extends Overlay {
  12. constructor(position, width, height, plane = {}) {
  13. super()
  14. this._position = Parse.parsePosition(position)
  15. this._width = +width || 0
  16. this._height = +height || 0
  17. if (plane.normal && typeof plane.normal === 'string') {
  18. let n = String(plane.normal).toLocaleUpperCase()
  19. plane.normal =
  20. n === 'X'
  21. ? Cesium.Cartesian3.UNIT_X
  22. : n === 'Y'
  23. ? Cesium.Cartesian3.UNIT_Y
  24. : Cesium.Cartesian3.UNIT_Z
  25. } else {
  26. plane.normal = Cesium.Cartesian3.UNIT_Z
  27. }
  28. this._normal = plane.normal
  29. this._distance = plane.distance || 0
  30. this._delegate = new Cesium.Entity({
  31. plane: {
  32. dimensions: {
  33. x: this._width,
  34. y: this._height
  35. },
  36. plane: new Cesium.Plane(this._normal, this._distance)
  37. }
  38. })
  39. this.type = Overlay.getOverlayType('plane')
  40. this._state = State.INITIALIZED
  41. }
  42. set position(position) {
  43. this._position = Parse.parsePosition(position)
  44. this._delegate.position = Transform.transformWGS84ToCartesian(
  45. this._position
  46. )
  47. this._delegate.orientation = Cesium.Transforms.headingPitchRollQuaternion(
  48. Transform.transformWGS84ToCartesian(this._position),
  49. new Cesium.HeadingPitchRoll(
  50. Cesium.Math.toRadians(this._position.heading),
  51. Cesium.Math.toRadians(this._position.pitch),
  52. Cesium.Math.toRadians(this._position.roll)
  53. )
  54. )
  55. return this
  56. }
  57. get position() {
  58. return this._position
  59. }
  60. set width(width) {
  61. this._width = +width || 0
  62. this._delegate.plan.dimensions.x = this._width
  63. return this
  64. }
  65. get width() {
  66. return this._width
  67. }
  68. set height(height) {
  69. this._height = +height || 0
  70. this._delegate.plan.dimensions.y = this._height
  71. return this
  72. }
  73. get height() {
  74. return this._height
  75. }
  76. set distance(distance) {
  77. this._distance = distance
  78. this._delegate.plane.plane.distance = distance
  79. return this
  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. *
  96. * @param {*} text
  97. * @param {*} textStyle
  98. */
  99. setLabel(text, textStyle) {
  100. return this
  101. }
  102. /**
  103. * Sets Style
  104. * @param style
  105. * @returns {Plane}
  106. */
  107. setStyle(style) {
  108. if (Object.keys(style).length === 0) {
  109. return this
  110. }
  111. delete style['dimensions'] && delete ['plane']
  112. this._style = style
  113. Util.merge(this._delegate.plane, this._style)
  114. return this
  115. }
  116. }
  117. Overlay.registerType('plane')
  118. export default Plane