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

TrailLinePrimitive.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 { Transform } from '@dc-modules/transform'
  9. import Overlay from '../Overlay'
  10. class TrailLinePrimitive 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('trail_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('PolylineTrail', {
  43. color: this._style?.color || new Cesium.Color(1.0, 0.0, 0.0, 0.7),
  44. speed: this._style?.speed || 5
  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 {TrailLinePrimitive}
  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('trail_line_primitive')
  75. export default TrailLinePrimitive