Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Label.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-02-01 11:59:28
  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 Label 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('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 {*} text
  53. * @param {*} textStyle
  54. */
  55. setLabel(text, textStyle) {
  56. return this
  57. }
  58. /**
  59. * Sets Style
  60. * @param style
  61. * @returns {Label}
  62. */
  63. setStyle(style) {
  64. if (!style || Object.keys(style).length === 0) {
  65. return this
  66. }
  67. delete style['text']
  68. Util.merge(this._style, style)
  69. Util.merge(this._delegate.label, style)
  70. return this
  71. }
  72. /**
  73. * Parse from entity
  74. * @param entity
  75. * @returns {any}
  76. */
  77. static fromEntity(entity) {
  78. let now = Cesium.JulianDate.now()
  79. let position = Transform.transformCartesianToWGS84(
  80. entity.position.getValue(now)
  81. )
  82. let label = undefined
  83. if (entity.billboard) {
  84. label = new Label(position, entity.name)
  85. label.attr = {
  86. ...entity?.properties?.getValue(now)
  87. }
  88. }
  89. return label
  90. }
  91. }
  92. Overlay.registerType('label')
  93. export default Label