Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DynamicModel.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-05-05 09:16:35
  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. import DynamicOverlay from './DynamicOverlay'
  12. class DynamicModel extends DynamicOverlay {
  13. constructor(position, modelUrl) {
  14. super()
  15. this._posistion = Parse.parsePosition(position)
  16. this._modelUrl = modelUrl
  17. this._delegate = new Cesium.Entity({ model: {} })
  18. this.type = Overlay.getOverlayType('dynamic_model')
  19. this._state = State.INITIALIZED
  20. }
  21. set modelUrl(modelUrl) {
  22. this._modelUrl = modelUrl
  23. this._delegate.model.uri = this._modelUrl
  24. return this
  25. }
  26. get modelUrl() {
  27. return this._modelUrl
  28. }
  29. _mountedHook() {
  30. /**
  31. * set the location
  32. */
  33. this._samplePosition.forwardExtrapolationType =
  34. Cesium.ExtrapolationType.HOLD
  35. this._startTime = Cesium.JulianDate.now()
  36. this._samplePosition.addSample(
  37. this._startTime,
  38. Transform.transformWGS84ToCartesian(this._posistion)
  39. )
  40. this._delegate.position = this._samplePosition
  41. this._delegate.orientation = new Cesium.VelocityOrientationProperty(
  42. this._samplePosition
  43. )
  44. this._cache.push(this._startTime)
  45. /**
  46. * initialize the Overlay parameter
  47. */
  48. this.modelUrl = this._modelUrl
  49. }
  50. /**
  51. * Sets style
  52. * @param style
  53. * @returns {DynamicModel}
  54. */
  55. setStyle(style) {
  56. if (!style || Object.keys(style).length === 0) {
  57. return this
  58. }
  59. delete style['uri']
  60. this._style = style
  61. Util.merge(this._delegate.model, this._style)
  62. return this
  63. }
  64. }
  65. Overlay.registerType('dynamic_model')
  66. export default DynamicModel