選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FlowLinePrimitive.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-01-05 20:18:34
  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 FlowLinePrimitive extends Overlay {
  11. constructor(positions, width = 1) {
  12. super()
  13. this._positions = Parse.parsePositions(positions)
  14. this._width = width
  15. this._delegate = new Cesium.Primitive({
  16. geometryInstances: new Cesium.GeometryInstance({
  17. geometry: {}
  18. })
  19. })
  20. this.type = Overlay.getOverlayType('flow_line_primitive')
  21. this._state = State.INITIALIZED
  22. }
  23. set positions(positions) {
  24. this._positions = Parse.parsePositions(positions)
  25. this._delegate.geometryInstances.geometry = new Cesium.PolylineGeometry({
  26. positions: Transform.transformWGS84ArrayToCartesianArray(this._positions),
  27. width: this._width
  28. })
  29. return this
  30. }
  31. get positions() {
  32. return this._positions
  33. }
  34. /**
  35. *
  36. * @private
  37. */
  38. _setAppearance() {
  39. this._delegate.appearance = new Cesium.PolylineMaterialAppearance({
  40. material: Cesium.Material.fromType('PolylineFlow', {
  41. color: this._style?.color || new Cesium.Color(1.0, 0.0, 0.0, 0.7),
  42. speed: this._style?.speed || 1,
  43. percent: this._style?.percent || 0.03,
  44. gradient: this._style?.gradient || 0.1
  45. })
  46. })
  47. }
  48. _mountedHook() {
  49. /**
  50. * set the positions
  51. */
  52. this.positions = this._positions
  53. /**
  54. * set the appearance
  55. */
  56. !this._delegate.appearance && this._setAppearance()
  57. }
  58. /**
  59. * Sets Style
  60. * @param style
  61. * @returns {FlowLinePrimitive}
  62. */
  63. setStyle(style = {}) {
  64. if (Object.keys(style).length === 0) {
  65. return this
  66. }
  67. this._style = style
  68. style.classificationType &&
  69. (this._delegate.classificationType = this._style.classificationType)
  70. this._setAppearance()
  71. return this
  72. }
  73. }
  74. Overlay.registerType('flow_line_primitive')
  75. export default FlowLinePrimitive