Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DynamicOverlay.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 { Transform } from '@dc-modules/transform'
  9. import Overlay from '../Overlay'
  10. class DynamicOverlay extends Overlay {
  11. constructor() {
  12. super()
  13. this._startTime = undefined
  14. this._lastTime = undefined
  15. this._samplePosition = new Cesium.SampledPositionProperty()
  16. this._cache = []
  17. this._maxCacheSize = 10
  18. this._state = State.INITIALIZED
  19. }
  20. set maxCacheSize(maxCacheSize) {
  21. this._maxCacheSize = maxCacheSize
  22. return this
  23. }
  24. get maxCacheSize() {
  25. return this._maxCacheSize
  26. }
  27. get position() {
  28. return Transform.transformCartesianToWGS84(
  29. this._samplePosition.getValue(Cesium.JulianDate.now())
  30. )
  31. }
  32. /**
  33. *
  34. * @private
  35. */
  36. _removePosition() {
  37. if (this._cache.length > this._maxCacheSize) {
  38. let start = Cesium.JulianDate.addSeconds(
  39. this._cache[0],
  40. -0.2,
  41. new Cesium.JulianDate()
  42. )
  43. let stop = Cesium.JulianDate.addSeconds(
  44. this._cache[this._cache.length - this._maxCacheSize],
  45. -0.2,
  46. new Cesium.JulianDate()
  47. )
  48. this._samplePosition.removeSamples(
  49. new Cesium.TimeInterval({
  50. start: start,
  51. stop: stop
  52. })
  53. )
  54. this._cache.splice(0, this._cache.length - this._maxCacheSize)
  55. }
  56. }
  57. /**
  58. *
  59. * @param position
  60. * @param interval
  61. * @returns {DynamicOverlay}
  62. */
  63. addPosition(position, interval) {
  64. this._removePosition()
  65. let now = Cesium.JulianDate.now()
  66. let time = Cesium.JulianDate.addSeconds(
  67. now,
  68. interval,
  69. new Cesium.JulianDate()
  70. )
  71. this._samplePosition.addSample(
  72. time,
  73. Transform.transformWGS84ToCartesian(Parse.parsePosition(position))
  74. )
  75. this._lastTime = time
  76. this._cache.push(this._lastTime)
  77. return this
  78. }
  79. /**
  80. *
  81. * @param content
  82. * @returns {DynamicOverlay}
  83. */
  84. bindDom(content) {
  85. return this
  86. }
  87. }
  88. Overlay.registerType('dynamic-model')
  89. export default DynamicOverlay