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.

TrailLinePrimitive.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-01-09 21:33:59
  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 TrailLinePrimitive 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('trail_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('PolylineTrail', {
  44. color: this._style?.color || new Cesium.Color(1.0, 0.0, 0.0, 0.7),
  45. speed: this._style?.speed || 5
  46. })
  47. })
  48. }
  49. _mountedHook() {
  50. /**
  51. * set the positions
  52. */
  53. this.positions = this._positions
  54. /**
  55. * set the appearance
  56. */
  57. !this._delegate.appearance && this._setAppearance()
  58. }
  59. /**
  60. * Sets Style
  61. * @param style
  62. * @returns {TrailLinePrimitive}
  63. */
  64. setStyle(style = {}) {
  65. if (Object.keys(style).length === 0) {
  66. return this
  67. }
  68. Util.merge(this._style, style)
  69. style.classificationType &&
  70. (this._delegate.classificationType = this._style.classificationType)
  71. this._setAppearance()
  72. return this
  73. }
  74. }
  75. Overlay.registerType('trail_line_primitive')
  76. export default TrailLinePrimitive