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.

FlowLinePrimitive.js 2.2KB

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