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://cdn.jsdelivr.net/npm/cesium@1.84.0/Build/Cesium/Cesium.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/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.addPolylineLinkPulse();
                this.addPolylineTrialFlow();
                this.addPolylineArrowOpacity();
                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: false,
                    imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
                        url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
                    })
                });

                //是否开启抗锯齿
                this.viewer.scene.fxaa = true;
                this.viewer.scene.postProcessStages.fxaa.enabled = true;
            },

            addPolylineLinkPulse() {
                let lines = [
                    [{
                        x: -1705722.7375782044,
                        y: 5456272.240635795,
                        z: 2818985.3064158773
                    }, {
                        x: -1707465.3050721162,
                        y: 5455799.126313257,
                        z: 2818846.9912274643
                    }, {
                        x: -1709648.901559206,
                        y: 5455193.614325796,
                        z: 2818696.3690761398
                    }],
                    [{
                        x: -1705743.9778158371,
                        y: 5456179.3424243955,
                        z: 2819151.1387875197
                    }, {
                        x: -1708235.6078501693,
                        y: 5455529.657677858,
                        z: 2818901.457562383
                    }, {
                        x: -1709625.693373575,
                        y: 5455126.525294995,
                        z: 2818839.3192474963
                    }]
                ];
                let colors = [Cesium.Color.RED, Cesium.Color.AQUA]
                lines.forEach((item, index) => {
                    this.viewer.entities.add({
                        polyline: {
                            positions: item,
                            width: 8,
                            material: new xt3d.PolylineObject.PolylineLinkPulseMaterialProperty({
                                color: colors[index], //颜色
                                duration: 10000, //时间 控制速度
                                url: "/data.xt3d.cn/assets/images/polylinematerial/LinkPulse.png", //材质图片
                            }),
                            clampToGround: true
                        }
                    });
                })
            },

            addPolylineTrialFlow() {
                let lines = [
                    [{
                        x: -1705719.5727869077,
                        y: 5456375.624182519,
                        z: 2818788.4358880203
                    }, {
                        x: -1707268.7350737453,
                        y: 5455952.069465352,
                        z: 2818671.210907333
                    }, {
                        x: -1709635.8100880147,
                        y: 5455271.383798028,
                        z: 2818554.747371558
                    }],
                    [{
                        x: -1705774.083582354,
                        y: 5456455.8386593675,
                        z: 2818601.42995507
                    }, {
                        x: -1708265.7347283296,
                        y: 5455756.4481896395,
                        z: 2818447.2990572792
                    }, {
                        x: -1709574.189798031,
                        y: 5455378.459767089,
                        z: 2818386.0095119956
                    }]
                ]

                let colors = [Cesium.Color.RED, Cesium.Color.AQUA]
                lines.forEach((item, index) => {
                    this.viewer.entities.add({
                        polyline: {
                            positions: item,
                            width: 8,
                            material: new xt3d.PolylineObject.PolylineTrialFlowMaterialProperty({
                                color: colors[index],
                                duration: 2000,
                            }),
                            clampToGround: true
                        }
                    });
                })
            },

            addPolylineArrowOpacity() {
                let lines = [
                    [{
                        x: -1705759.1254791946,
                        y: 5456563.243728887,
                        z: 2818403.8820573976
                    }, {
                        x: -1709580.2897493609,
                        y: 5455451.370047656,
                        z: 2818242.146330367
                    }],
                    [{
                        x: -1705781.5982320097,
                        y: 5456612.565487121,
                        z: 2818295.519493847
                    }, {
                        x: -1709605.7903465675,
                        y: 5455497.846780045,
                        z: 2818137.4127685623
                    }]
                ]

                let colors = [Cesium.Color.YELLOW, Cesium.Color.AQUA]
                lines.forEach((item, index) => {
                    this.viewer.entities.add({
                        polyline: {
                            positions: item,
                            width: 8,
                            material: new xt3d.PolylineObject.PolylineArrowMaterialProperty({
                                color: colors[index],
                                duration: 800,
                                count: 3, //重复次数
                                url: "/data.xt3d.cn/assets/images/polylinematerial/arrowopacity.png", //材质图片"
                            }),
                            clampToGround: true
                        }
                    });
                })
            },

            setView() {
                this.viewer.scene.camera.setView({
                    duration: 1,
                    destination: {
                        x: -1709251.0767395466,
                        y: 5461386.32337908,
                        z: 2820645.238657382
                    },
                    orientation: {
                        heading: 0.13762265446730737,
                        pitch: -1.460307026543739,
                        roll: 0.003401834066556475
                    }
                });
            },


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

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

</html>

预览地址

xt3d 在线预览地址

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

xt3d

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

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

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

打赏作者

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

抵扣说明:

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

余额充值