Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

VideoPrimitive.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-11-09 20:04:30
  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 VideoPrimitive extends Overlay {
  11. constructor(positions, video) {
  12. super()
  13. this._positions = Parse.parsePositions(positions)
  14. this._delegate = new Cesium.GroundPrimitive({
  15. geometryInstances: new Cesium.GeometryInstance({
  16. geometry: {}
  17. })
  18. })
  19. this._video = video
  20. this._state = State.INITIALIZED
  21. }
  22. get type() {
  23. return Overlay.getOverlayType('video_primitive')
  24. }
  25. set positions(positions) {
  26. this._positions = Parse.parsePositions(positions)
  27. this._delegate.geometryInstances.geometry = Cesium.PolygonGeometry.fromPositions(
  28. {
  29. positions: Transform.transformWGS84ArrayToCartesianArray(
  30. this._positions
  31. ),
  32. height: this._style?.height,
  33. extrudedHeight: this._style?.extrudedHeight,
  34. closeTop: this._style?.closeTop,
  35. closeBottom: this._style?.closeBottom,
  36. vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
  37. }
  38. )
  39. return this
  40. }
  41. get positions() {
  42. return this._positions
  43. }
  44. set video(video) {
  45. this._video = video
  46. this._setAppearance()
  47. return this
  48. }
  49. get video() {
  50. return this._video
  51. }
  52. /**
  53. *
  54. * @private
  55. */
  56. _setAppearance() {
  57. this._delegate.appearance = new Cesium.EllipsoidSurfaceAppearance({
  58. material: Cesium.Material.fromType('Image', {
  59. image: this._video
  60. })
  61. })
  62. }
  63. _mountedHook() {
  64. /**
  65. * set the positions
  66. */
  67. this.positions = this._positions
  68. /**
  69. * initialize the Overlay parameter
  70. */
  71. this.video = this._video
  72. }
  73. /**
  74. * Sets Style
  75. * @param style
  76. * @returns {VideoPrimitive}
  77. */
  78. setStyle(style) {
  79. if (Object.keys(style).length === 0) {
  80. return this
  81. }
  82. this._style = style
  83. if (this._style?.classificationType) {
  84. this._delegate.classificationType = this._style.classificationType
  85. }
  86. return this
  87. }
  88. }
  89. Overlay.registerType('video_primitive')
  90. export default VideoPrimitive