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.

DynamicModel.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. class DynamicModel extends Overlay {
  12. constructor(modelUrl) {
  13. super()
  14. this._delegate = new Cesium.Entity({ model: {} })
  15. this._posistion = new Cesium.SampledPositionProperty()
  16. this._modelUrl = modelUrl
  17. this._timeLine = {}
  18. this._lastTime = undefined
  19. this.type = Overlay.getOverlayType('dynamic-model')
  20. this._state = State.INITIALIZED
  21. }
  22. get position() {
  23. return this._position
  24. }
  25. get timeLine() {
  26. return this._timeLine
  27. }
  28. _mountedHook() {
  29. this._posistion.forwardExtrapolationType = Cesium.ExtrapolationType.HOLD
  30. this._delegate.position = this._posistion
  31. this._delegate.orientation = new Cesium.VelocityOrientationProperty(
  32. this._posistion
  33. )
  34. }
  35. /**
  36. *
  37. * @param position
  38. * @param interval
  39. */
  40. addPosition(position, interval) {
  41. let now = Cesium.JulianDate.now()
  42. let time = Cesium.JulianDate.addSeconds(
  43. now,
  44. interval,
  45. new Cesium.JulianDate()
  46. )
  47. this._lastTime = Cesium.JulianDate.toIso8601(time)
  48. let cartesian = Transform.transformWGS84ToCartesian(
  49. Parse.parsePosition(position)
  50. )
  51. this._posistion.addSample(time, cartesian)
  52. this._timeLine[this._lastTime] = cartesian
  53. return this
  54. }
  55. /**
  56. * Sets style
  57. * @param style
  58. * @returns {DynamicModel}
  59. */
  60. setStyle(style) {
  61. if (!style || Object.keys(style).length === 0) {
  62. return this
  63. }
  64. delete style['uri'] && delete style['position']
  65. this._style = style
  66. Util.merge(this._delegate.model, this._style)
  67. return this
  68. }
  69. }
  70. Overlay.registerType('dynamic-model')
  71. export default DynamicModel