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.

VideoPrimitive.js 2.3KB

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