Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DynamicModel.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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._state = State.INITIALIZED
  19. }
  20. get type() {
  21. return Overlay.getOverlayType('dynamic_model')
  22. }
  23. set modelUrl(modelUrl) {
  24. this._modelUrl = modelUrl
  25. this._delegate.model.uri = this._modelUrl
  26. return this
  27. }
  28. get modelUrl() {
  29. return this._modelUrl
  30. }
  31. _mountedHook() {
  32. /**
  33. * set the location
  34. */
  35. this._sampledPosition.forwardExtrapolationType =
  36. Cesium.ExtrapolationType.HOLD
  37. this._startTime = Cesium.JulianDate.now()
  38. this._sampledPosition.addSample(
  39. this._startTime,
  40. Transform.transformWGS84ToCartesian(this._posistion)
  41. )
  42. this._delegate.position = this._sampledPosition
  43. this._delegate.orientation = new Cesium.VelocityOrientationProperty(
  44. this._sampledPosition
  45. )
  46. this._cache.push(this._startTime)
  47. /**
  48. * initialize the Overlay parameter
  49. */
  50. this.modelUrl = this._modelUrl
  51. }
  52. /**
  53. * Sets style
  54. * @param style
  55. * @returns {DynamicModel}
  56. */
  57. setStyle(style) {
  58. if (!style || Object.keys(style).length === 0) {
  59. return this
  60. }
  61. delete style['uri']
  62. this._style = style
  63. Util.merge(this._delegate.model, this._style)
  64. return this
  65. }
  66. }
  67. Overlay.registerType('dynamic_model')
  68. export default DynamicModel