| 
                        123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 | 
                        - /**
 -  * @Author: Caven
 -  * @Date: 2021-06-08 20:41:51
 -  */
 - 
 - import { SceneEventType, PathEventType } from '@dc-modules/event'
 - 
 - class RoamingController {
 -   constructor(viewer) {
 -     this._viewer = viewer
 -     this._viewOption = {}
 -     this._cache = {}
 -     this._activedPath = undefined
 -   }
 - 
 -   /**
 -    *
 -    * @returns {boolean}
 -    * @private
 -    */
 -   _onPostRender() {
 -     if (!this._activedPath) {
 -       return false
 -     }
 -     this._activedPath.pathEvent &&
 -       this._activedPath.pathEvent.fire(
 -         PathEventType.POST_RENDER,
 -         this._viewer,
 -         this._viewOption
 -       )
 -   }
 - 
 -   /**
 -    *
 -    * @param path
 -    * @returns {RoamingController}
 -    */
 -   addPath(path) {
 -     if (path && !this._cache.hasOwnProperty(path.pathId)) {
 -       path.pathEvent.fire(PathEventType.ADD)
 -       this._cache[path.pathId] = path
 -     }
 -     return this
 -   }
 - 
 -   /**
 -    *
 -    * @param paths
 -    * @returns {RoamingController}
 -    */
 -   addPaths(paths) {
 -     if (Array.isArray(paths)) {
 -       paths.forEach(item => {
 -         this.addPath(item)
 -       })
 -     }
 -     return this
 -   }
 - 
 -   /**
 -    *
 -    * @param path
 -    * @returns {RoamingController}
 -    */
 -   removePath(path) {
 -     if (path && this._cache.hasOwnProperty(path.pathId)) {
 -       delete this._cache[path.pathId]
 -       path.pathEvent.fire(PathEventType.REMOVE)
 -     }
 -     return this
 -   }
 - 
 -   /**
 -    *
 -    * @param id
 -    * @returns {*|undefined}
 -    */
 -   getPath(id) {
 -     let filters = this.getPaths().filter(item => item.id === id)
 -     return filters && filters.length ? filters[0] : undefined
 -   }
 - 
 -   /**
 -    *
 -    * @returns {*[]}
 -    */
 -   getPaths() {
 -     let result = []
 -     Object.keys(this._cache).forEach(key => {
 -       result.push(this._cache[key])
 -     })
 -     return result
 -   }
 - 
 -   /**
 -    *
 -    * @param path
 -    * @param viewOption
 -    * @returns {RoamingController}
 -    */
 -   activate(path, viewOption = {}) {
 -     if (
 -       !path ||
 -       path?.pathId === this._activedPath?.pathId ||
 -       !this._cache.hasOwnProperty(path?.pathId)
 -     ) {
 -       return this
 -     }
 -     this._viewOption = viewOption
 -     this._activedPath && this.deactivate()
 -     this._activedPath = path
 -     this._activedPath.pathEvent &&
 -       this._activedPath.pathEvent.fire(PathEventType.RESET_TIME_LINE)
 -     this._viewer.on(SceneEventType.POST_RENDER, this._onPostRender, this)
 -     return this
 -   }
 - 
 -   /**
 -    *
 -    * @returns {RoamingController}
 -    */
 -   deactivate() {
 -     this._activedPath && (this._activedPath.actived = false)
 -     this._activedPath = undefined
 -     this._viewer.off(SceneEventType.POST_RENDER, this._onPostRender, this)
 -     return this
 -   }
 - 
 -   /**
 -    *
 -    * @returns {RoamingController}
 -    */
 -   clear() {
 -     this._cache = {}
 -     this._activedPath && (this._activedPath.actived = false)
 -     this._activedPath = undefined
 -     this._viewer.off(SceneEventType.POST_RENDER, this._onPostRender, this)
 -     return this
 -   }
 - }
 - 
 - export default RoamingController
 
 
  |