Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

TrailLinePrimitive.js 1.9KB

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