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.

Ellipsoid.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-04-14 18:20:23
  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 Ellipsoid extends Overlay {
  12. constructor(position, radius) {
  13. super()
  14. this._position = Parse.parsePosition(position)
  15. this._radius = radius || { x: 10, y: 10, z: 10 }
  16. this._delegate = new Cesium.Entity({ ellipsoid: {} })
  17. this._state = State.INITIALIZED
  18. }
  19. get type() {
  20. return Overlay.getOverlayType('ellipsoid')
  21. }
  22. set position(position) {
  23. this._position = Parse.parsePosition(position)
  24. this._delegate.position = Transform.transformWGS84ToCartesian(
  25. this._position
  26. )
  27. this._delegate.orientation = Cesium.Transforms.headingPitchRollQuaternion(
  28. Transform.transformWGS84ToCartesian(this._position),
  29. new Cesium.HeadingPitchRoll(
  30. Cesium.Math.toRadians(this._position.heading),
  31. Cesium.Math.toRadians(this._position.pitch),
  32. Cesium.Math.toRadians(this._position.roll)
  33. )
  34. )
  35. return this
  36. }
  37. get position() {
  38. return this._position
  39. }
  40. set radius(radius) {
  41. this._radius = radius || { x: 10, y: 10, z: 10 }
  42. this._delegate.ellipsoid.radii = this._radius
  43. return this
  44. }
  45. get radius() {
  46. return this._radius
  47. }
  48. _mountedHook() {
  49. /**
  50. * set the location
  51. */
  52. this.position = this._position
  53. /**
  54. * initialize the Overlay parameter
  55. */
  56. this.radius = this._radius
  57. }
  58. /**
  59. * Sets Style
  60. * @param style
  61. * @returns {Ellipsoid}
  62. */
  63. setStyle(style) {
  64. if (Object.keys(style).length === 0) {
  65. return this
  66. }
  67. delete style['radius']
  68. Util.merge(this._style, style)
  69. Util.merge(this._delegate.ellipsoid, style)
  70. return this
  71. }
  72. }
  73. Overlay.registerType('ellipsoid')
  74. export default Ellipsoid