/** * @Author: Caven * @Date: 2021-05-05 09:16:35 */ import { Cesium } from '@dc-modules/namespace' import State from '@dc-modules/state/State' import Parse from '@dc-modules/parse/Parse' import { Util } from '@dc-modules/utils' import { Transform } from '@dc-modules/transform' import Overlay from '../Overlay' import DynamicOverlay from './DynamicOverlay' class DynamicModel extends DynamicOverlay { constructor(position, modelUrl) { super() this._posistion = Parse.parsePosition(position) this._modelUrl = modelUrl this._delegate = new Cesium.Entity({ model: {} }) this.type = Overlay.getOverlayType('dynamic_model') this._state = State.INITIALIZED } set modelUrl(modelUrl) { this._modelUrl = modelUrl this._delegate.model.uri = this._modelUrl return this } get modelUrl() { return this._modelUrl } _mountedHook() { /** * set the location */ this._samplePosition.forwardExtrapolationType = Cesium.ExtrapolationType.HOLD this._startTime = Cesium.JulianDate.now() this._samplePosition.addSample( this._startTime, Transform.transformWGS84ToCartesian(this._posistion) ) this._delegate.position = this._samplePosition this._delegate.orientation = new Cesium.VelocityOrientationProperty( this._samplePosition ) this._cache.push(this._startTime) /** * initialize the Overlay parameter */ this.modelUrl = this._modelUrl } /** * Sets style * @param style * @returns {DynamicModel} */ setStyle(style) { if (!style || Object.keys(style).length === 0) { return this } delete style['uri'] this._style = style Util.merge(this._delegate.model, this._style) return this } } Overlay.registerType('dynamic_model') export default DynamicModel