vue-cesium
Version:
Vue 3.x components for CesiumJS.
84 lines (81 loc) • 2.78 kB
JavaScript
import { makeJulianDate, makeCartesian3 } from '../../utils/cesium-helpers.mjs';
"use strict";
class DynamicOverlay {
constructor(options) {
const { SampledPositionProperty, Entity, ExtrapolationType, VelocityOrientationProperty, CallbackProperty } = Cesium;
this._lastTime = void 0;
this._sampledPosition = new SampledPositionProperty();
this._sampledPosition.forwardExtrapolationType = options.forwardExtrapolationType || ExtrapolationType.HOLD;
this._sampledPosition.backwardExtrapolationType = options.backwardExtrapolationType || ExtrapolationType.HOLD;
this._cache = [];
this._maxCacheSize = options.maxCacheSize || 10;
const entity = new Entity(options);
entity.position = this._sampledPosition;
if (!Cesium.defined(options.orientation)) {
const orientation = new VelocityOrientationProperty(this._sampledPosition);
let lastOri;
entity.orientation = new CallbackProperty((time, result) => {
const ori = orientation.getValue(time);
if (ori) {
lastOri = ori;
} else {
return lastOri;
}
return ori;
}, false);
}
this._entity = entity;
this._velocityVectorProperty = new Cesium.VelocityVectorProperty(this._sampledPosition, false);
}
get id() {
return this._entity.id;
}
set id(id) {
this._entity.id = id;
}
set maxCacheSize(maxCacheSize) {
this._maxCacheSize = maxCacheSize;
}
get maxCacheSize() {
return this._maxCacheSize;
}
get position() {
return this._sampledPosition.getValue(Cesium.JulianDate.now());
}
_removePosition() {
if (this._cache.length > this._maxCacheSize) {
const start = Cesium.JulianDate.addSeconds(this._cache[0], -0.2, new Cesium.JulianDate());
const stop = Cesium.JulianDate.addSeconds(this._cache[this._cache.length - this._maxCacheSize], -0.2, new Cesium.JulianDate());
this._sampledPosition.removeSamples(
new Cesium.TimeInterval({
start,
stop
})
);
this._cache.splice(0, this._cache.length - this._maxCacheSize);
}
}
/**
*
* @param position
* @param interval
* @returns
*/
addPosition(position, timeOrInterval) {
this._removePosition();
let time;
if (typeof timeOrInterval === "number") {
const now = Cesium.JulianDate.now();
time = Cesium.JulianDate.addSeconds(now, timeOrInterval, new Cesium.JulianDate());
Cesium.destroyObject(now);
} else {
time = makeJulianDate(timeOrInterval);
}
this._sampledPosition.addSample(time, makeCartesian3(position));
this._lastTime = time;
this._cache.push(this._lastTime);
return time;
}
}
export { DynamicOverlay as default };
//# sourceMappingURL=DynamicOverlay.mjs.map