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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-06 20:03:25
  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 Model extends Overlay {
  12. constructor(position, modelUrl) {
  13. super()
  14. this._delegate = new Cesium.Entity({ model: {} })
  15. this._position = Parse.parsePosition(position)
  16. this._modelUrl = modelUrl
  17. this._rotateAmount = 0
  18. this._state = State.INITIALIZED
  19. }
  20. get type() {
  21. return Overlay.getOverlayType('model')
  22. }
  23. set position(position) {
  24. this._position = Parse.parsePosition(position)
  25. this._delegate.position = Transform.transformWGS84ToCartesian(
  26. this._position
  27. )
  28. if (this._rotateAmount === 0) {
  29. this._delegate.orientation = Cesium.Transforms.headingPitchRollQuaternion(
  30. Transform.transformWGS84ToCartesian(this._position),
  31. new Cesium.HeadingPitchRoll(
  32. Cesium.Math.toRadians(this._position.heading),
  33. Cesium.Math.toRadians(this._position.pitch),
  34. Cesium.Math.toRadians(this._position.roll)
  35. )
  36. )
  37. }
  38. return this
  39. }
  40. get position() {
  41. return this._position
  42. }
  43. set modelUrl(modelUrl) {
  44. this._modelUrl = modelUrl
  45. this._delegate.model.uri = this._modelUrl
  46. return this
  47. }
  48. get modelUrl() {
  49. return this._modelUrl
  50. }
  51. set rotateAmount(amount) {
  52. this._rotateAmount = +amount
  53. this._delegate.orientation = new Cesium.CallbackProperty(() => {
  54. this._position.heading += this._rotateAmount
  55. if (this._position.heading >= 360 || this._position.heading <= -360) {
  56. this._position.heading = 0
  57. }
  58. return Cesium.Transforms.headingPitchRollQuaternion(
  59. Transform.transformWGS84ToCartesian(this._position),
  60. new Cesium.HeadingPitchRoll(
  61. Cesium.Math.toRadians(this._position.heading),
  62. Cesium.Math.toRadians(this._position.pitch),
  63. Cesium.Math.toRadians(this._position.roll)
  64. )
  65. )
  66. })
  67. return this
  68. }
  69. get rotateAmount() {
  70. return this._rotateAmount
  71. }
  72. _mountedHook() {
  73. /**
  74. * set the location
  75. */
  76. this.position = this._position
  77. /**
  78. * initialize the Overlay parameter
  79. */
  80. this.modelUrl = this._modelUrl
  81. }
  82. /**
  83. * Sets style
  84. * @param style
  85. * @returns {Model}
  86. */
  87. setStyle(style) {
  88. if (!style || Object.keys(style).length === 0) {
  89. return this
  90. }
  91. delete style['uri']
  92. this._style = style
  93. Util.merge(this._delegate.model, this._style)
  94. return this
  95. }
  96. /**
  97. * Parse from entity
  98. * @param entity
  99. * @param modelUrl
  100. * @returns {Model}
  101. */
  102. static fromEntity(entity, modelUrl) {
  103. let now = Cesium.JulianDate.now()
  104. let position = Transform.transformCartesianToWGS84(
  105. entity.position.getValue(now)
  106. )
  107. let model = new Model(position, modelUrl)
  108. model.attr = {
  109. ...entity.properties.getValue(now)
  110. }
  111. return model
  112. }
  113. }
  114. Overlay.registerType('model')
  115. export default Model