earthtrek-core
Version:
Global Nominee NASA Space Apps Challenge 2017 Buenos Aires - Global Finalist (Best Use of Data) NASA Space Apps Challenge 2017 - 1D, 2D, 3D, Go! Challenge
199 lines (172 loc) • 7.9 kB
JavaScript
;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _earthtrekSatellite = require('./earthtrek-satellite');
var _earthtrekSatellite2 = _interopRequireDefault(_earthtrekSatellite);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* @class EarthTrekEntity
* @module EarthTrek
* @author SATrek
* @author Alejandro Sanchez <alejandro.sanchez.trek@gmail.com>
* @description EarthTrek - NASA Space Apps 2017 2 JUN 2017.
*/
/** cesium core*/
var Cesium = require('./utils/cesium');
/**EarthTrek*/
var EarthTrekEntity = function () {
function EarthTrekEntity(satelliteInfo, startTime) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
_classCallCheck(this, EarthTrekEntity);
if (!options.model) {
options.model = {
show: false
};
}
if (!options.billboard) {
options.billboard = {
show: false,
path: 'images/satellites/',
scale: 1
};
}
if (!options.label) {
options.label = {
show: true
};
}
if (!options.path) {
options.path = {
show: true
};
}
if (!options.orbitColor) {
options.orbitColor = '#F0F8FF';
}
if (!options.fadeOrbit) {
options.fadeOrbit = true;
}
if (!options.multiplier) {
options.multiplier = 10; //intervals
}
if (!options.orbitDuration) {
options.orbitDuration = 7200; //seconds
}
this.orbitDuration = options.orbitDuration;
this.frequency = options.frequency;
this.orbitColor = Cesium.Color.fromCssColorString(options.orbitColor);
if (options.fadeOrbit == true) {
this.orbitMaterial = new Cesium.StripeMaterialProperty({
evenColor: this.orbitColor.withAlpha(0.5),
oddColor: this.orbitColor.withAlpha(0.01),
repeat: 1,
offset: 0.2,
orientation: Cesium.StripeOrientation.VERTICAL
});
} else {
this.orbitMaterial = this.orbitColor.withAlpha(0.5);
}
this.create(satelliteInfo, startTime, options);
}
_createClass(EarthTrekEntity, [{
key: 'getDefaultMaterial',
value: function getDefaultMaterial() {
return this.orbitMaterial;
}
/**
* Create Entity
* @param satelliteInfo
* @param startTime
* @param options
* @returns {*}
*/
}, {
key: 'create',
value: function create(satelliteInfo, startTime, options) {
var color = void 0;
if (satelliteInfo.tle == undefined) {
return false;
}
var samples = _earthtrekSatellite2.default.getSamples(satelliteInfo.tle[0], satelliteInfo.tle[1], startTime, this.orbitDuration, this.frequency);
this.entity = {
id: satelliteInfo.satId,
name: satelliteInfo.name,
position: samples.positions,
velocity: samples.velocities,
altitude: samples.heights,
defaultMaterial: this.orbitMaterial,
path: {
path: options.path.show,
resolution: 5,
material: this.orbitMaterial,
width: 1,
trailTime: this.orbitDuration / 2,
leadTime: 0
},
label: {
show: options.label.show,
text: satelliteInfo.name,
scale: 0.6,
scaleByDistance: new Cesium.NearFarScalar(0, 1.5, 15.0e6, 0.85),
fillColor: Cesium.Color.WHITE,
// eyeOffset: new Cesium.Cartesian3(0.0, 300.0, 200.0),
outlineColor: color,
outlineWidth: 3,
style: Cesium.LabelStyle.FILL,
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
pixelOffset: new Cesium.Cartesian2(15, 0)
},
billboard: {
show: options.billboard.show,
imageSubRegion: new Cesium.BoundingRectangle(0, 0, 80, 80),
image: options.billboard.path + satelliteInfo.image,
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(40000.1, 150000000.0),
scale: options.billboard.scale,
alignedAxis: new Cesium.VelocityVectorProperty(samples.positions, true)
},
properties: satelliteInfo
};
if (options.model != undefined && options.model.show == true) {
this.entity.model = {
uri: options.model.uri != undefined ? options.model.uri : 'models/' + satelliteInfo.id + '.glb',
minimumPixelSize: 512,
maximumScale: 1,
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 40000.0)
};
}
this.entity.availability = this.generateInterval(satelliteInfo.launchDate, satelliteInfo.endDate);
return this.entity;
}
/**
*
* @param launchDate
* @param endDate
* @returns {Cesium.TimeIntervalCollection}
*/
}, {
key: 'generateInterval',
value: function generateInterval(launchDate, endDate) {
var timeInterval = new Cesium.TimeInterval({
start: Cesium.JulianDate.fromIso8601(launchDate),
stop: endDate == null ? Cesium.JulianDate.fromIso8601("2099-01-01") : Cesium.JulianDate.fromIso8601(endDate),
isStartIncluded: true,
isStopIncluded: endDate === null ? false : true
});
var intervalCollection = new Cesium.TimeIntervalCollection();
intervalCollection.addInterval(timeInterval);
return intervalCollection;
}
/**
*
* @returns {{id: *, name, position, velocity, altitude, defaultMaterial: (Cesium.StripeMaterialProperty|Color|*), path: {path: boolean, resolution: number, material: (Cesium.StripeMaterialProperty|Color|*), width: number, trailTime: number, leadTime: number}, label: {show: boolean, text, scale: number, scaleByDistance, fillColor: Color, outlineColor, outlineWidth: number, style: (number|Number), horizontalOrigin: (*|number|Number), verticalOrigin: (Number|number), pixelOffset}, billboard: {show: boolean, imageSubRegion, image: string, distanceDisplayCondition, scale: number, alignedAxis}, properties: *}|*}
*/
}, {
key: 'getEntityData',
value: function getEntityData() {
return this.entity;
}
}]);
return EarthTrekEntity;
}();
module.exports = EarthTrekEntity;