浏览代码

dd @dc-modules/history-track

tags/2.2.4
Caven Chen 4 年前
父节点
当前提交
a782149163
共有 1 个文件被更改,包括 19 次插入45 次删除
  1. 19
    45
      modules/history-track/Track.js

+ 19
- 45
modules/history-track/Track.js 查看文件

import TrackViewMode from './TrackViewMode' import TrackViewMode from './TrackViewMode'


const DEF_OPTS = { const DEF_OPTS = {
showPath: false,
pathWidth: 1,
pathMaterial: Cesium.Color.ORANGE.withAlpha(0.8),
pathLeadTime: 1,
clampToGround: false, clampToGround: false,
clampToTileset: false clampToTileset: false
} }


const DEF_PATH_STYLE = {
width: 2,
material: Cesium.Color.ORANGE,
clampToGround: true,
depthFailMaterial: Cesium.Color.ORANGE.withAlpha(0.8)
}

class Track { class Track {
constructor(positions, duration, callback, options) { constructor(positions, duration, callback, options) {
this._id = Util.uuid() this._id = Util.uuid()
this._controller = undefined this._controller = undefined
this._viewed = false this._viewed = false
this._delegate = new Cesium.Entity() this._delegate = new Cesium.Entity()
this._pathPositions = []
this._path = new Cesium.Entity({
show: false,
polyline: {
positions: new Cesium.CallbackProperty(() => {
return this._pathPositions
})
}
})

this._positionIndex = 0 this._positionIndex = 0
this._timeLine = [] this._timeLine = []
this._startTime = undefined this._startTime = undefined


set positions(postions) { set positions(postions) {
this._positions = Parse.parsePositions(postions) this._positions = Parse.parsePositions(postions)
this._resetTimeLine({})
this._resetTimeLine()
return this return this
} }




set duration(duration) { set duration(duration) {
this._duration = duration this._duration = duration
this._resetTimeLine({})
this._resetTimeLine()
return this return this
} }


} else { } else {
this._startTime = startTime this._startTime = startTime
} }
this._resetTimeLine({})
this._resetTimeLine()
return this return this
} }


} }
this._controller = controller this._controller = controller
this._controller.delegate.add(this._delegate) this._controller.delegate.add(this._delegate)
this._controller.delegate.add(this._path)
!this._startTime && (this._startTime = Cesium.JulianDate.now()) !this._startTime && (this._startTime = Cesium.JulianDate.now())
this._state = State.ADDED this._state = State.ADDED
} }
* @private * @private
*/ */
_onRemove() { _onRemove() {
if (!this._controller) {
return false
if (this._controller) {
this._controller.delegate.remove(this._delegate)
} }
this._controller.delegate.remove(this._delegate)
this._controller.delegate.remove(this._path)
this._viewed = false this._viewed = false
this._startTime = undefined
this._state = State.REMOVED this._state = State.REMOVED
} }


} }
let now = Cesium.JulianDate.now() let now = Cesium.JulianDate.now()
if (Cesium.JulianDate.lessThan(now, this._endTime)) { if (Cesium.JulianDate.lessThan(now, this._endTime)) {
let p = this._sampledPosition.getValue(now)
this._pathPositions.push(p)
if (this._options.clampToTileset) { if (this._options.clampToTileset) {
this._delegate.position = viewer.scene.clampToHeight(p, [
this._delegate
])
this._delegate.position = viewer.scene.clampToHeight(
this._sampledPosition.getValue(now),
[this._delegate]
)
} else { } else {
this._delegate.position = p
this._delegate.position = this._sampledPosition.getValue(now)
} }
let time = this._timeLine[this._positionIndex] let time = this._timeLine[this._positionIndex]
if (time) { if (time) {
let mat = Cesium.Matrix3.fromQuaternion( let mat = Cesium.Matrix3.fromQuaternion(
this._delegate.orientation.getValue(now) this._delegate.orientation.getValue(now)
) )
let mat4 = Cesium.Matrix4.fromRotationTranslation(mat, p)
let mat4 = Cesium.Matrix4.fromRotationTranslation(
mat,
this._sampledPosition.getValue(now)
)
let hpr = Cesium.Transforms.fixedFrameToHeadingPitchRoll(mat4) let hpr = Cesium.Transforms.fixedFrameToHeadingPitchRoll(mat4)
position.heading = Cesium.Math.toDegrees(hpr.heading) position.heading = Cesium.Math.toDegrees(hpr.heading)
position.pitch = Cesium.Math.toDegrees(hpr.pitch) position.pitch = Cesium.Math.toDegrees(hpr.pitch)
this._sampledPosition this._sampledPosition
) )
this._endTime = this._timeLine[this._timeLine.length - 1] this._endTime = this._timeLine[this._timeLine.length - 1]
this._pathPositions = []
} }


/** /**
return this return this
} }


/**
*
* @param visible
* @param style
* @returns {Track}
*/
setPath(visible, style = {}) {
this._path.show = !!visible
Util.merge(this._path.polyline, DEF_PATH_STYLE, style)
return this
}
setPath() {}
} }


export default Track export default Track

正在加载...
取消
保存