Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Plane.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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._state = State.INITIALIZED
  40. }
  41. get type() {
  42. return Overlay.getOverlayType('plane')
  43. }
  44. set position(position) {
  45. this._position = Parse.parsePosition(position)
  46. this._delegate.position = Transform.transformWGS84ToCartesian(
  47. this._position
  48. )
  49. this._delegate.orientation = Cesium.Transforms.headingPitchRollQuaternion(
  50. Transform.transformWGS84ToCartesian(this._position),
  51. new Cesium.HeadingPitchRoll(
  52. Cesium.Math.toRadians(this._position.heading),
  53. Cesium.Math.toRadians(this._position.pitch),
  54. Cesium.Math.toRadians(this._position.roll)
  55. )
  56. )
  57. return this
  58. }
  59. get position() {
  60. return this._position
  61. }
  62. set width(width) {
  63. this._width = +width || 0
  64. this._delegate.plan.dimensions.x = this._width
  65. return this
  66. }
  67. get width() {
  68. return this._width
  69. }
  70. set height(height) {
  71. this._height = +height || 0
  72. this._delegate.plan.dimensions.y = this._height
  73. return this
  74. }
  75. get height() {
  76. return this._height
  77. }
  78. set distance(distance) {
  79. this._distance = distance
  80. this._delegate.plane.plane.distance = distance
  81. return this
  82. }
  83. get distance() {
  84. return this._distance
  85. }
  86. _mountedHook() {
  87. /**
  88. * set the location
  89. */
  90. this.position = this._position
  91. /**
  92. * initialize the Overlay parameter
  93. */
  94. this.distance = this._distance
  95. }
  96. /**
  97. * Sets Style
  98. * @param style
  99. * @returns {Plane}
  100. */
  101. setStyle(style) {
  102. if (Object.keys(style).length === 0) {
  103. return this
  104. }
  105. delete style['dimensions'] && delete ['plane']
  106. Util.merge(this._style, style)
  107. Util.merge(this._delegate.plane, style)
  108. return this
  109. }
  110. }
  111. Overlay.registerType('plane')
  112. export default Plane