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/[email protected]/Build/Cesium/Cesium.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/Build/Cesium/Widgets/widgets.css">

    <script src='http://www.xt3d.cn/libs/turf.min.js'></script>

    <!-- 使用vue绑定控件 -->
    <script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/[email protected]/lib/index.js"></script>

    <!--  引入xt3d -->
    <script src="http://www.xt3d.cn/xt3dlib/xt3d.min.js"></script>
    <style>
        html,
        body,
        #map3d {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }
        
        .form-container {
            position: absolute;
            left: 10px;
            top: 90px;
            padding: 10px 15px;
            border-radius: 4px;
            border: 1px solid rgba(128, 128, 128, 0.5);
            color: #ffffff;
            background: rgba(0, 0, 0, 0.4);
            box-shadow: 0 3px 14px rgb(128 128 128 / 50%);
            max-width: 300px;
        }
        
        button {
            background: transparent;
            border: 1px solid #00d0ffb8;
            color: white;
            padding: 7px 9px;
            border-radius: 2px;
            margin: 3px;
            cursor: pointer
        }
        
        .el-form-item__label {
            color: white;
        }
    </style>
</head>

<body>
    <div id="map3d"></div>

    <div class="form-container">
        <video id="video" muted="muted" width="300" controls height="220" src="/data.xt3d.cn/assets/lukou.mp4" autoplay="autoplay" loop></video>

        <div id="formContainer">
            <el-form ref="form" :model="form" label-width="60px" label-position="left" size="mini">
                <el-form-item label="翻转">
                    <el-slider v-model="form.rotation.x" :show-tooltip="true" @input="valueChange" :min="-180" :max="180"></el-slider>
                </el-form-item>
                <el-form-item label="旋转">
                    <el-slider v-model="form.rotation.y" :show-tooltip="true" @input="valueChange" :min="-360" :max="360"></el-slider>
                </el-form-item>
                <el-form-item label="夹角">
                    <el-slider v-model="form.fov" :show-tooltip="true" @input="valueChange" :min="1" :max="90"></el-slider>
                </el-form-item>

                <el-form-item label="透明">
                    <el-slider v-model="form.alpha" :show-tooltip="true" @input="valueChange" :step="0.1" :min="0" :max="1"></el-slider>
                </el-form-item>
                <el-form-item label="投影线">
                    <el-switch v-model="form.debugFrustum" @change="setFrustumVisible" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
                </el-form-item>
            </el-form>
        </div>
    </div>
    <script>
        let xt3dInit = {
            init(el) {
                this.initViewer(el);
                this.load3dtiles();
                this.setView();
            },

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

            //设置视角
            setView() {
                let flyToOpts = {
                    destination: {
                        x: -1715364.449942997,
                        y: 4993248.386956065,
                        z: 3566686.6600144217
                    },
                    orientation: {
                        heading: 6.005026929302029,
                        pitch: -1.1614799523621118,
                        roll: 6.281017982608725
                    },
                    duration: 1
                };
                this.viewer.scene.camera.setView(flyToOpts);
            },

            //加载三维模型
            load3dtiles() {
                let tileset = this.viewer.scene.primitives.add(
                    new Cesium.Cesium3DTileset({
                        url: "http://earthsdk.com/v/last/Apps/assets/dayanta/tileset.json"
                    })
                );

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

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

        xt3dInit.init("map3d");


        let videoEl = document.getElementById("video"); //播放成功的video标签
        let videoShed3d = new xt3d.VideoPlugin.VideoShed3d(xt3dInit.viewer, {
            video: videoEl,
            position: {
                x: 108.95941714166067,
                y: 34.219812715439865,
                z: 72.01781951233912
            },
            //旋转参数
            rotation: {
                x: -53,
                y: 3,
                z: 0
            },
            near: 0,
            far: 240, //距离
            fov: 12, //张角
            aspectRatio: 1,
            alpha: 1, //透明
            debugFrustum: true //是否显示投影线
        });

        //界面控制
        let vm = new Vue({
            el: "#formContainer",
            data() {
                return {
                    form: {
                        rotation: {}
                    }
                }
            },

            methods: {
                valueChange() {
                    videoShed3d.updateStyle(this.form);
                },

                setFrustumVisible() {
                    videoShed3d.setFrustumVisible(this.form.debugFrustum);
                }
            }
        })

        vm.form = videoShed3d.getStyle();
    </script>
</body>

</html>

预览地址

xt3d 在线预览地址

你可能感兴趣的:(cesium,xt3d,3d,javascript,vue.js,cesium,xt3d)