| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * @Author: Caven
- * @Date: 2021-06-03 21:06:17
- */
-
- import { Cesium } from '@dc-modules/namespace'
- import State from '@dc-modules/state/State'
- import Overlay from '../Overlay'
- import LabelPrimitive from './LabelPrimitive'
-
- const DEF_STYLE = {
- maxOffsetY: 10,
- offsetAmount: 0.1
- }
-
- class BounceLabelPrimitive extends LabelPrimitive {
- constructor(position, text) {
- super(position, text)
- this._currentOffset = new Cesium.Cartesian2(0, 0)
- this._isUp = true
- this._state = State.INITIALIZED
- }
-
- get type() {
- return Overlay.getOverlayType('bounce_label_primitive')
- }
-
- /**
- *
- * @private
- */
- _addedHook() {
- if (!this._delegate || !this._layer) {
- return
- }
- this._delegate.layerId = this._layer?.layerId
- this._delegate.overlayId = this._id
- this._layer.delegate.add(this)
- }
-
- /**
- *
- * @private
- */
- _removedHook() {
- if (!this._layer) {
- return
- }
- this._layer.delegate.remove(this)
- }
-
- update() {
- if (!this._show) {
- return
- }
- let maxOffsetY = this._style?.maxOffsetY || DEF_STYLE.maxOffsetY
- let offsetAmount = this._style?.offsetAmount || DEF_STYLE.offsetAmount
- if (this._currentOffset.y >= 0) {
- this._isUp = true
- } else if (this._currentOffset.y <= -maxOffsetY) {
- this._isUp = false
- }
- this._currentOffset.y += offsetAmount * (this._isUp ? -1 : 1)
- this._delegate.pixelOffset = this._currentOffset
- }
-
- /**
- * @return {*}
- */
- destroy() {
- return Cesium.destroyObject(this)
- }
- }
-
- Overlay.registerType('bounce_label_primitive')
-
- export default BounceLabelPrimitive
|