Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

FlowLinePrimitive.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. *
  60. * @param text
  61. * @param textStyle
  62. * @returns {FlowLinePrimitive}
  63. */
  64. setLabel(text, textStyle) {
  65. return this
  66. }
  67. /**
  68. * Sets Style
  69. * @param style
  70. * @returns {FlowLinePrimitive}
  71. */
  72. setStyle(style = {}) {
  73. if (Object.keys(style).length === 0) {
  74. return this
  75. }
  76. this._style = style
  77. style.classificationType &&
  78. (this._delegate.classificationType = this._style.classificationType)
  79. this._setAppearance()
  80. return this
  81. }
  82. }
  83. Overlay.registerType('flow_line_primitive')
  84. export default FlowLinePrimitive