您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Ellipse.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-04-14 11:10:00
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-05-11 22:24:34
  6. */
  7. const { Overlay, Util, State, Transform } = DC
  8. const { Cesium } = DC.Namespace
  9. class Ellipse extends Overlay {
  10. constructor(position, semiMajorAxis, semiMinorAxis) {
  11. if (!Util.checkPosition(position)) {
  12. throw new Error('Ellipse: the position invalid')
  13. }
  14. super()
  15. this._position = position
  16. this._semiMajorAxis = semiMajorAxis || 0
  17. this._semiMinorAxis = semiMinorAxis || 0
  18. this._delegate = new Cesium.Entity()
  19. this.type = Overlay.getOverlayType('ellipse')
  20. this._state = State.INITIALIZED
  21. }
  22. set position(position) {
  23. if (!Util.checkPosition(position)) {
  24. throw new Error('Ellipse: the position invalid')
  25. }
  26. this._position = position
  27. }
  28. get position() {
  29. return this._position
  30. }
  31. set semiMajorAxis(semiMajorAxis) {
  32. this._semiMajorAxis = semiMajorAxis
  33. }
  34. get semiMajorAxis() {
  35. return this._semiMajorAxis
  36. }
  37. set semiMinorAxis(semiMinorAxis) {
  38. this._semiMinorAxis = semiMinorAxis
  39. }
  40. get semiMinorAxis() {
  41. return this._semiMinorAxis
  42. }
  43. _mountedHook() {
  44. /**
  45. * set the location
  46. */
  47. this._delegate.position = new Cesium.CallbackProperty(time => {
  48. return Transform.transformWGS84ToCartesian(this._position)
  49. })
  50. /**
  51. * set the orientation
  52. */
  53. this._delegate.orientation = new Cesium.CallbackProperty(time => {
  54. return Cesium.Transforms.headingPitchRollQuaternion(
  55. Transform.transformWGS84ToCartesian(this._position),
  56. new Cesium.HeadingPitchRoll(
  57. Cesium.Math.toRadians(this._position.heading),
  58. Cesium.Math.toRadians(this._position.pitch),
  59. Cesium.Math.toRadians(this._position.roll)
  60. )
  61. )
  62. })
  63. /**
  64. * initialize the Overlay parameter
  65. */
  66. this._delegate.ellipse = {
  67. ...this._style,
  68. semiMajorAxis: new Cesium.CallbackProperty(time => {
  69. return this._semiMajorAxis
  70. }),
  71. semiMinorAxis: new Cesium.CallbackProperty(time => {
  72. return this._semiMinorAxis
  73. })
  74. }
  75. }
  76. /**
  77. *
  78. * @param {*} style
  79. */
  80. setStyle(style) {
  81. if (Object.keys(style).length == 0) {
  82. return this
  83. }
  84. this._style = style
  85. this._delegate.ellipse && Util.merge(this._delegate.ellipse, this._style)
  86. return this
  87. }
  88. }
  89. Overlay.registerType('ellipse')
  90. export default Ellipse