Cesium|xt3d 雷达追踪圆锥体

Cesium|xt3d 雷达追踪圆锥体

效果

在这里插入图片描述

代码

 <!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>cesium|xt3d</title>
    <!-- 引入Cesium -->
    <script src="https://unpkg.com/cesium@1.84.0/Build/Cesium/Cesium.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/cesium@1.84.0/Build/Cesium/Widgets/widgets.css">

    <!--  引入xt3d -->
    <script src="http://www.xt3d.cn/xt3dlib/xt3d.min.js"></script>
    <style>
        html,
        body,
        #map3d {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }
    </style>
</head>

<body>
    <div id="map3d"></div>
    <script>
        let xt3dInit = {
            init(el) {
                this.initViewer(el);
                this.load3dtiles();
                //源点坐标
                this.originPoint = [106.45531788088708, 29.50637660924465, 35];
                this.originPosition = Cesium.Cartesian3.fromDegrees(this.originPoint[0], this.originPoint[1], this.originPoint[2] + 20);
                this.conicSensor = new xt3d.SpacePlugin.ConicSensor(this.viewer, this.originPosition);

                this.addRadarModel();
                this.addTarget();
                this.setView();
            },

            //初始化viewer
            initViewer(el) {
                this.viewer = new Cesium.Viewer(el, {
                    infoBox: false,
                    selectionIndicator: false,
                    navigation: false,
                    animation: false,
                    timeline: false,
                    baseLayerPicker: false,
                    geocoder: false,
                    homeButton: false,
                    sceneModePicker: false,
                    navigationHelpButton: false,
                    shouldAnimate: true,
                    imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
                        url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
                    }),
                });
                this.viewer.scene.globe.depthTestAgainstTerrain = true;

            },

            //设置视角
            setView() {
                this.viewer.scene.camera.setView({
                    duration: 1,
                    destination: {
                        x: -2168792.734068365,
                        y: 6881947.030631928,
                        z: 2564864.3138284963
                    },
                    orientation: {
                        heading: 6.2092497690218975,
                        pitch: -0.8489176138360675,
                        roll: 0.0001151687477829455
                    }
                });
            },

            //添加雷达模型
            addRadarModel() {
                var entity = this.viewer.entities.add({
                    name: "leida",
                    position: Cesium.Cartesian3.fromDegrees(this.originPoint[0], this.originPoint[1], this.originPoint[2]),
                    model: {
                        uri: "/data.xt3d.cn/assets/glb/leida.glb",
                        scale: 0.5,
                        maximumScale: 1,
                        silhouetteColor: Cesium.Color.fromAlpha(Cesium.Color.YELLOW, 0.8), //设置模型外轮廓颜色与透明度
                        silhouetteSize: 1 //设置模型外轮廓线宽度
                    },
                });
            },

            //添加目标 ,这里以运行的飞机为例
            addTarget() {
                var start = Cesium.JulianDate.fromDate(new Date(2015, 2, 25, 16));
                var stop = Cesium.JulianDate.addSeconds(
                    start,
                    360,
                    new Cesium.JulianDate()
                );

                this.viewer.clock.startTime = start.clone();
                this.viewer.clock.stopTime = stop.clone();
                this.viewer.clock.currentTime = start.clone();
                this.viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
                this.viewer.clock.multiplier = 10;
                var position = this.computeCirclularFlight(this.originPoint[0], this.originPoint[1], 5, start);

                this.targetEntity = this.viewer.entities.add({
                    availability: new Cesium.TimeIntervalCollection([
                        new Cesium.TimeInterval({
                            start: start,
                            stop: stop,
                        }),
                    ]),
                    position: position,
                    orientation: new Cesium.VelocityOrientationProperty(position),
                    model: {
                        uri: "/data.xt3d.cn/assets/glb/Cesium_Air.glb",
                        minimumPixelSize: 128,
                    },
                    path: {
                        resolution: 1,
                        material: new Cesium.PolylineGlowMaterialProperty({
                            glowPower: 0.1,
                            color: Cesium.Color.YELLOW,
                        }),
                        width: 10,
                    },
                });

                this.targetEntity.position.setInterpolationOptions({
                    interpolationDegree: 2,
                    interpolationAlgorithm: Cesium.HermitePolynomialApproximation,
                })
                this.addTickEvent(); //注册事件 获取飞机的实时位置
            },

            //生成目标的运行轨迹
            computeCirclularFlight(lon, lat, radius, start) {
                var property = new Cesium.SampledPositionProperty();
                for (var i = 0; i <= 360; i += 45) {
                    var radians = Cesium.Math.toRadians(i);
                    var time = Cesium.JulianDate.addSeconds(
                        start,
                        i,
                        new Cesium.JulianDate()
                    );
                    var position = Cesium.Cartesian3.fromDegrees(
                        lon + radius * 1.5 * Math.cos(radians),
                        lat + radius * Math.sin(radians),
                        300000
                    );
                    property.addSample(time, position);

                    this.viewer.entities.add({
                        position: position,
                        point: {
                            pixelSize: 8,
                            color: Cesium.Color.TRANSPARENT,
                            outlineColor: Cesium.Color.YELLOW,
                            outlineWidth: 3,
                        },
                    });
                }
                return property;
            },

            //动态获取目标点位置
            addTickEvent() {
                this.viewer.clock.onTick.addEventListener(e => {
                    const targetPosition = this.targetEntity.position.getValue(
                        this.viewer.clock.currentTime
                    );
                    this.conicSensor.updateTargetPosition(targetPosition);
                }, this);
            },

            //加载3dtiles数据
            load3dtiles() {
                let tileset = this.viewer.scene.primitives.add(
                    new Cesium.Cesium3DTileset({
                        url: "http://www.xt3d.cn/data/offset_3dtiles/tileset.json",
                    })
                );

                tileset.readyPromise
                    .then(tileset => {
                        xt3d.TilesetPlugin.setTilesetHeight(tileset, 55);
                    })
                    .otherwise(function(error) {
                        console.log(error);
                    });
            },

            destroy() {
                this.viewer.entities.removeAll();
                this.viewer.imageryLayers.removeAll(true);
                this.viewer.destroy();
            }
        }

        xt3dInit.init("map3d");
    </script>
</body>

</html>

预览地址

xt3d 在线预览地址

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xt3d

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值