Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BounceLabelPrimitive.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. * @param frameState
  26. */
  27. update(frameState) {
  28. if (!this._show) {
  29. return
  30. }
  31. let maxOffsetY = this._style?.maxOffsetY || DEF_STYLE.maxOffsetY
  32. let offsetAmount = this._style?.offsetAmount || DEF_STYLE.offsetAmount
  33. if (this._currentOffset.y >= 0) {
  34. this._isUp = true
  35. } else if (this._currentOffset.y <= -maxOffsetY) {
  36. this._isUp = false
  37. }
  38. this._currentOffset.y += offsetAmount * (this._isUp ? -1 : 1)
  39. this._delegate.pixelOffset = this._currentOffset
  40. }
  41. /**
  42. * @return {*}
  43. */
  44. destroy() {
  45. return Cesium.destroyObject(this)
  46. }
  47. }
  48. Overlay.registerType('bounce_label_primitive')
  49. export default BounceLabelPrimitive