| 
                        123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 | 
                        - /**
 -  * @Author: Caven
 -  * @Date: 2019-12-27 14:35:02
 -  */
 - 
 - import { Cesium } from '@dc-modules/namespace'
 - import { Transform } from '@dc-modules/transform'
 - 
 - class Position {
 -   constructor(lng, lat, alt, heading, pitch, roll) {
 -     this._lng = +lng || 0
 -     this._lat = +lat || 0
 -     this._alt = +alt || 0
 -     this._heading = +heading || 0
 -     this._pitch = +pitch || 0
 -     this._roll = +roll || 0
 -   }
 - 
 -   set lng(lng) {
 -     this._lng = +lng
 -   }
 - 
 -   get lng() {
 -     return this._lng
 -   }
 - 
 -   set lat(lat) {
 -     this._lat = +lat
 -   }
 - 
 -   get lat() {
 -     return this._lat
 -   }
 - 
 -   set alt(alt) {
 -     this._alt = +alt
 -   }
 - 
 -   get alt() {
 -     return this._alt
 -   }
 - 
 -   set heading(heading) {
 -     this._heading = +heading
 -   }
 - 
 -   get heading() {
 -     return this._heading
 -   }
 - 
 -   set pitch(pitch) {
 -     this._pitch = +pitch
 -   }
 - 
 -   get pitch() {
 -     return this._pitch
 -   }
 - 
 -   set roll(roll) {
 -     this._roll = +roll
 -   }
 - 
 -   get roll() {
 -     return this._roll
 -   }
 - 
 -   /**
 -    *
 -    * @returns {string}
 -    */
 -   serialize() {
 -     let position = new Position(
 -       this._lng,
 -       this._lat,
 -       this._alt,
 -       this._heading,
 -       this._pitch,
 -       this._roll
 -     )
 -     return JSON.stringify(position)
 -   }
 - 
 -   /**
 -    * Calculate the distance between two positions
 -    * @param target
 -    * @returns {number}
 -    */
 -   distance(target) {
 -     if (!target || !(target instanceof Position)) {
 -       return 0
 -     }
 -     return Cesium.Cartesian3.distance(
 -       Transform.transformWGS84ToCartesian(this),
 -       Transform.transformWGS84ToCartesian(target)
 -     )
 -   }
 - 
 -   /**
 -    * clone a position
 -    * @returns {Position}
 -    */
 -   clone() {
 -     let position = new Position()
 -     position.lng = this.lng || 0
 -     position.lat = this.lat || 0
 -     position.alt = this.alt || 0
 -     position.heading = this.heading || 0
 -     position.pitch = this.pitch || 0
 -     position.roll = this.roll || 0
 -     return position
 -   }
 - 
 -   /**
 -    * clone a position
 -    * @deprecated
 -    * @returns {Position}
 -    */
 -   copy() {
 -     return this.clone()
 -   }
 - 
 -   /**
 -    *
 -    * @returns {*[]}
 -    */
 -   toArray() {
 -     return [this.lng, this.lat, this.alt, this.heading, this.pitch, this.roll]
 -   }
 - 
 -   /**
 -    *
 -    * @returns {string}
 -    */
 -   toString() {
 -     return `${this.lng},${this.lat},${this.alt},${this.heading},${this.pitch},${this.roll}`
 -   }
 - 
 -   /**
 -    *
 -    * @returns {{lng, heading, alt, roll, pitch, lat}}
 -    */
 -   toObject() {
 -     return {
 -       lng: this.lng,
 -       lat: this.lat,
 -       alt: this.alt,
 -       heading: this.heading,
 -       pitch: this.pitch,
 -       roll: this.roll
 -     }
 -   }
 - 
 -   /**
 -    *
 -    * @param arr
 -    * @returns {Position}
 -    */
 -   static fromArray(arr) {
 -     let position = new Position()
 -     if (Array.isArray(arr)) {
 -       position.lng = arr[0] || 0
 -       position.lat = arr[1] || 0
 -       position.alt = arr[2] || 0
 -       position.heading = arr[3] || 0
 -       position.pitch = arr[4] || 0
 -       position.roll = arr[5] || 0
 -     }
 -     return position
 -   }
 - 
 -   /**
 -    *
 -    * @param str
 -    * @returns {Position}
 -    */
 -   static fromString(str) {
 -     let position = new Position()
 -     if (str && typeof str === 'string') {
 -       let arr = str.split(',')
 -       position = this.fromArray(arr)
 -     }
 -     return position
 -   }
 - 
 -   /**
 -    *
 -    * @param obj
 -    * @returns {Position}
 -    */
 -   static fromObject(obj) {
 -     return new Position(
 -       obj.lng,
 -       obj.lat,
 -       obj.alt,
 -       obj.heading,
 -       obj.pitch,
 -       obj.roll
 -     )
 -   }
 - 
 -   /**
 -    * Deserialize
 -    * @param valStr
 -    * @returns {Position}
 -    */
 -   static deserialize(valStr) {
 -     let position = new Position()
 -     let obj = JSON.parse(valStr)
 -     if (obj) {
 -       position.lng = obj.lng || 0
 -       position.lat = obj.lat || 0
 -       position.alt = obj.alt || 0
 -       position.heading = obj.heading || 0
 -       position.pitch = obj.pitch || 0
 -       position.roll = obj.roll || 0
 -     }
 -     return position
 -   }
 - }
 - 
 - export default Position
 
 
  |