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.

BounceLabelPrimitive.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-06-03 21:06:17
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. import State from '@dc-modules/state/State'
  7. import Overlay from '../Overlay'
  8. import LabelPrimitive from './LabelPrimitive'
  9. const DEF_STYLE = {
  10. maxOffsetY: 10,
  11. offsetAmount: 0.1
  12. }
  13. class BounceLabelPrimitive extends LabelPrimitive {
  14. constructor(position, text) {
  15. super(position, text)
  16. this._currentOffset = new Cesium.Cartesian2(0, 0)
  17. this._isUp = true
  18. this._state = State.INITIALIZED
  19. }
  20. get type() {
  21. return Overlay.getOverlayType('bounce_label_primitive')
  22. }
  23. /**
  24. *
  25. * @private
  26. */
  27. _addedHook() {
  28. if (!this._delegate || !this._layer) {
  29. return
  30. }
  31. this._delegate.layerId = this._layer?.layerId
  32. this._delegate.overlayId = this._id
  33. this._layer.delegate.add(this)
  34. }
  35. /**
  36. *
  37. * @private
  38. */
  39. _removedHook() {
  40. if (!this._layer) {
  41. return
  42. }
  43. this._layer.delegate.remove(this)
  44. }
  45. /**
  46. *
  47. */
  48. update() {
  49. if (!this._show) {
  50. return
  51. }
  52. let maxOffsetY = this._style?.maxOffsetY || DEF_STYLE.maxOffsetY
  53. let offsetAmount = this._style?.offsetAmount || DEF_STYLE.offsetAmount
  54. if (this._currentOffset.y >= 0) {
  55. this._isUp = true
  56. } else if (this._currentOffset.y <= -maxOffsetY) {
  57. this._isUp = false
  58. }
  59. this._currentOffset.y += offsetAmount * (this._isUp ? -1 : 1)
  60. this._delegate.pixelOffset = this._currentOffset
  61. }
  62. }
  63. Overlay.registerType('bounce_label_primitive')
  64. export default BounceLabelPrimitive