cesium绘制卫星

首先需要注意new Cesium.Viewer的时候需要将

 timeline: true,
 shouldAnimate: true, // 初始时刻运动

两个属性置为true否则不生效

export class initSatellite {
    start: any;
    stop: any;
    viewer: any;
    constructor(option) {
        // 赋值实例
        this.viewer = option.viewer.value;
        this.start = new Cesium.JulianDate.fromDate(new Date());
        this.start = Cesium.JulianDate.addHours(
            this.start,
            8,
            new Cesium.JulianDate()
        ); //东八区时间
        // 结束时间
        this.stop = Cesium.JulianDate.addSeconds(
            this.start,
            360,
            new Cesium.JulianDate()
        );
        //确保查看器处于预期的时间
        this.viewer.clock.startTime = this.start.clone();
        this.viewer.clock.stopTime = this.stop.clone();
        this.viewer.clock.currentTime = this.start.clone();
        this.viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; //循环结束时
        //时间变化来控制速度 // 时间速率,数字越大时间过的越快
        this.viewer.clock.multiplier = 1;
        //给时间线设置边界
        this.viewer.timeline.zoomTo(this.start, stop);
        this.startfunc();
    }
    mySatePosition() {
        let lon = 0;
        let lat = 0;
        let hei = 700000; //卫星高度
        let phei = 700000 / 2; //轨道高度
        let time = 10;
        return { lon, lat, hei, phei, time };
    }
    computeCirclularFlight(source, panduan) {
        var property = new Cesium.SampledPositionProperty();
        if (panduan == 1) {
            //卫星位置
            for (var i = 0; i < source.length; i++) {
                var time = Cesium.JulianDate.addSeconds(
                    this.start,
                    source[i].time,
                    new Cesium.JulianDate()
                );
                var position = Cesium.Cartesian3.fromDegrees(
                    source[i].lon,
                    source[i].lat,
                    source[i].hei
                );
                // 添加位置,和时间对应
                property.addSample(time, position);
            }
        } else if (panduan == 2) {
            //轨道位置
            for (var i = 0; i < source.length; i++) {
                var time = Cesium.JulianDate.addSeconds(
                    this.start,
                    source[i].time,
                    new Cesium.JulianDate()
                );
                var position = Cesium.Cartesian3.fromDegrees(
                    source[i].lon,
                    source[i].lat,
                    source[i].phei
                );
                // 添加位置,和时间对应
                property.addSample(time, position);
            }
        }
        return property;
    }
    // 位置
    getRandState() {
        let horzin = {};
        var arr = [];
        var t1 = Math.floor(Math.random() * 360);
        var t2 = Math.floor(Math.random() * 360);
        for (var i = t1; i <= 360 + t1; i += 30) {
            var aaa = this.mySatePosition();
            aaa.lon = t2;
            aaa.lat = i;
            aaa.time = i - t1;
            arr.push(aaa);
        }
        horzin = arr;
        return horzin;
    }
    getStatePath(aaa) {
        var entity_ty1p = this.computeCirclularFlight(aaa, 2);
        var entity_ty1 = this.viewer.entities.add({
            availability: new Cesium.TimeIntervalCollection([
                new Cesium.TimeInterval({
                    start: this.start,
                    stop: this.stop,
                }),
            ]),
            position: entity_ty1p, //轨道高度
            orientation: new Cesium.VelocityOrientationProperty(entity_ty1p),
            cylinder: {
                HeightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                length: 700000,
                topRadius: 0,
                bottomRadius: 700000 / 2,
                material: Cesium.Color.RED.withAlpha(0.4),
                outline: !0,
                numberOfVerticalLines: 0,
                outlineColor: Cesium.Color.RED.withAlpha(0.8),
            },
        });

        entity_ty1.position.setInterpolationOptions({
            interpolationDegree: 5,
            interpolationAlgorithm: Cesium.LagrangePolynomialApproximation,
        });

        var entity1p = this.computeCirclularFlight(aaa, 1);
        //创建实体
        var entity1 = this.viewer.entities.add({
            // 将实体availability设置为与模拟时间相同的时间间隔。
            availability: new Cesium.TimeIntervalCollection([
                new Cesium.TimeInterval({
                    start: this.start,
                    stop: this.stop,
                }),
            ]),
            position: entity1p, //计算实体位置属性
            //基于位置移动自动计算方向.
            orientation: new Cesium.VelocityOrientationProperty(
                this.computeCirclularFlight(aaa, 1)
            ),
            //加载飞机模型
            model: {
                uri: "/sr71.glb",
                minimumPixelSize: 32,
            },
            //路径
            path: {
                resolution: 1,
                material: new Cesium.PolylineGlowMaterialProperty({
                    glowPower: 0.1,
                    color: Cesium.Color.PINK,
                }),
                width: 5,
            },
        });

        //差值器
        entity1.position.setInterpolationOptions({
            interpolationDegree: 5,
            interpolationAlgorithm: Cesium.LagrangePolynomialApproximation,
        });
    }
    startfunc() {
        this.getStatePath(this.getRandState());
    }
}

使用

new initSatellite({ viewer });
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用Cesium绘制卫星轨道,您需要了解两个基本概念:TLE和CZML。 TLE(Two-Line Element)是一种描述卫星轨道的格式,通常由两行数字组成。第一行包括了卫星编号、轨道周期、轨道倾角、近地点角度、升交点经度、平近点角以及修正因子。第二行包括了卫星轨道的一些时间信息。TLE可以通过多种方式获取,例如NASA的网站、Space-Track等。 CZML(Cesium Language)是一种用于描述三维场景的JSON格式。它允许您在Cesium上创建实例、位置、姿态、时间等。CZML文件可以通过多种方式创建,例如手动编写、使用Cesium的CZML工具、使用第三方工具等。 要在Cesium绘制卫星轨道,您需要执行以下步骤: 1. 获取TLE:从NASA网站、Space-Track等获取卫星TLE。 2. 使用Sgp4Propagator将TLE转换为卫星位置信息。Sgp4Propagator是一个用于计算卫星位置的工具,它使用TLE和当前时间来计算卫星位置。 3. 将位置信息转换为CZML格式。您可以使用Cesium的CZML工具或编写脚本来实现。 4. 在Cesium中加载CZML文件,绘制卫星轨道。 下面是一个简单的示例代码: ```javascript // 获取TLE var tle = "1 25544U 98067A 21200.54034253 .00001114 00000-0 32243-4 0 9995\n2 25544 51.6467 84.4509 0004939 77.1537 283.7394 15.48922298291569"; // 使用Sgp4Propagator计算卫星位置 var propagator = new Cesium.Sgp4Propagator.fromTle(tle); var startTime = Cesium.JulianDate.now(); var endTime = Cesium.JulianDate.addSeconds(startTime, 3600, new Cesium.JulianDate()); var interval = new Cesium.TimeInterval({ start: startTime, stop: endTime }); var positions = []; var time = new Cesium.JulianDate(); while (Cesium.JulianDate.lessThanOrEquals(time, endTime)) { var position = propagator.propagate(time); positions.push(position.x, position.y, position.z); time = Cesium.JulianDate.addSeconds(time, 60, new Cesium.JulianDate()); } // 将位置信息转换为CZML格式 var czml = [{ "id": "Satellite", "availability": interval.toString(), "position": { "epoch": startTime.toString(), "cartographicDegrees": positions }, "point": { "color": { "rgba": [255, 255, 255, 255] }, "pixelSize": 5 } }]; // 在Cesium中加载CZML文件 viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); ``` 这将在Cesium绘制一个卫星轨道。您可以根据需要调整代码以适应不同的卫星和时间。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值