您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FlowLinePrimitive.js 2.2KB

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