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

CustomLabel.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-07-28 18:37: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 CustomLabel extends Overlay {
  12. constructor(position, text) {
  13. super()
  14. this._delegate = new Cesium.Entity({ label: {} })
  15. this._position = Parse.parsePosition(position)
  16. this._text = text
  17. this._state = State.INITIALIZED
  18. }
  19. get type() {
  20. return Overlay.getOverlayType('custom_label')
  21. }
  22. set position(position) {
  23. this._position = Parse.parsePosition(position)
  24. this._delegate.position = Transform.transformWGS84ToCartesian(
  25. this._position
  26. )
  27. return this
  28. }
  29. get position() {
  30. return this._position
  31. }
  32. set text(text) {
  33. this._text = text
  34. this._delegate.label.text = this._text
  35. return this
  36. }
  37. get text() {
  38. return this._text
  39. }
  40. _mountedHook() {
  41. /**
  42. * set the location
  43. */
  44. this.position = this._position
  45. /**
  46. * initialize the Overlay parameter
  47. */
  48. this.text = this._text
  49. }
  50. /**
  51. *
  52. * @param {*} style
  53. */
  54. setStyle(style) {
  55. if (!style || Object.keys(style).length === 0) {
  56. return this
  57. }
  58. delete style['text']
  59. Util.merge(this._style, style)
  60. Util.merge(this._delegate.label, style)
  61. return this
  62. }
  63. /**
  64. * Sets VLine style
  65. * @param style
  66. * @returns {CustomLabel}
  67. */
  68. setVLine(style = {}) {
  69. if (this._position.alt > 0 && !this._delegate.polyline) {
  70. let position = this._position.copy()
  71. position.alt = style.height || 0
  72. this._delegate.polyline = {
  73. ...style,
  74. positions: Transform.transformWGS84ArrayToCartesianArray([
  75. position,
  76. this._position
  77. ])
  78. }
  79. }
  80. return this
  81. }
  82. /**
  83. * Sets bottom circle
  84. * @param radius
  85. * @param style
  86. * @param rotateAmount
  87. * @returns {CustomLabel}
  88. */
  89. setBottomCircle(radius, style = {}, rotateAmount = 0) {
  90. let stRotation = 0
  91. let amount = rotateAmount
  92. this._delegate.ellipse = {
  93. ...style,
  94. semiMajorAxis: radius,
  95. semiMinorAxis: radius,
  96. stRotation: new Cesium.CallbackProperty(() => {
  97. stRotation += amount
  98. if (stRotation >= 360 || stRotation <= -360) {
  99. stRotation = 0
  100. }
  101. return stRotation
  102. }, false)
  103. }
  104. return this
  105. }
  106. }
  107. Overlay.registerType('custom_label')
  108. export default CustomLabel