vue3 cesium datav 可视化大屏

目录

0. 预览效果

 1. 代码库包

2. 技术点

3. 一些注意事项(配置参数)

4. 相关代码详情 


0. 预览效果

        包含的功能:

        ① 地球按照一定速度自转

        ② 修改加载的geojson面样式

        ③ 添加 文字 标注!

 1. 代码库包

        

         直接采用vue-cli5 创建项目,选择vue3,router,vuex等,然后这里选择的datav不是官方的,由于官方的datav-vue3有些问题,暂时采用的为DataV Vue3+TS+Vite版 | DataV - Vue3

2. 技术点

        ① css 父相子绝,父元素position: relative; 子元素position: absolute; datav中的BorderBox11,cesium中viewer的挂接的元素下面就有这种。

        ②这里布局写的有点随意,可以参考其他的可视化大屏的布局,多采用几行几列的形式如:"flex:0 1 50%";此外,这里数据都是写死的,后面可以通过配置数据库实现。

        ③css height top width left 等等 尽量按照 n%的形式。

3. 一些注意事项(配置参数)

       项目采用的JavaScript,而非typescript!!!

        ①参考博主的另一篇关于vue3 cesium安装配置webpack的博客

        ② vue.config.js配置 直接复制上述博客的vue.config.js内容即可!

4. 相关代码详情 

         

        ①index.html 修改

        

        ②App.vue

         

         ③HomeView.vue

<template>
    <BorderBox11 id="container" title="Vue3 Cesium DataV可视化大屏" :title-width="400" :animate="false">
        <div id="CesiumContainer"></div>
        <router-link to="project01">
            <BorderBox13 id="box01" title="第一板块" :title-width="200">
                <div id="title">第一板块</div> 
                <img src="../../public/img01.jpg" alt="">
            </BorderBox13>
        </router-link>
        <BorderBox13 id="box02" title="第二板块" :title-width="200">
            <div id="title">第二板块</div> 
            <img src="../../public/img02.jpg" alt="">
        </BorderBox13>
        <BorderBox13 id="box03" title="第三板块" :title-width="200">
            <div id="title">第三板块</div> 
            <img src="../../public/img03.jpg" alt="">
        </BorderBox13>
        <BorderBox13 id="box04" title="第四板块" :title-width="200">
            <div id="title">第四板块</div> 
            <img src="../../public/img04.jpg" alt="">
        </BorderBox13>
        <router-link to="project05">
            <BorderBox13 id="box05" title="第五板块" :title-width="200">
                <div id="title">第五板块</div> 
                <img src="../../public/img05.jpg" alt="">
            </BorderBox13>
        </router-link>
        <BorderBox13 id="box06" title="第六板块" :title-width="200">
            <div id="title">第六板块</div> 
            <img src="../../public/img06.jpg" alt="">
        </BorderBox13>
        <BorderBox13 id="box07" title="第七板块" :title-width="200">
            <div id="title">第七板块</div> 
            <img src="../../public/img07.jpg" alt="">
        </BorderBox13>
        <BorderBox13 id="box08" title="第八板块" :title-width="200">
            <div id="title">第八板块</div> 
            <img src="../../public/img08.jpg" alt="">
        </BorderBox13>
    </BorderBox11>
</template>

<script>
    import {  BorderBox11, BorderBox13  } from '@kjgl77/datav-vue3';
    import {reactive, ref, onMounted} from "vue";

    // import * as Cesium from "cesium/Cesium.js";
    // 改变了cesium alias的路径,采用推荐的import cesium,自动导入cesium/source/Cesium.js
    import * as Cesium from "cesium";
    // 导入cesium的css样式库,其实有点类似element-plus库全部导入时的样子
    //import "cesium/Widgets/widgets.css";
    import "cesium/Source/Widgets/widgets.css";
    export default {
        name: "App",
        components: {
            BorderBox11,
            BorderBox13,
        },
        setup(){
            var legend = reactive({});

            // 地球旋转
            function rotate(time, viewer) {
                viewer.clock.multiplier = 300; //速度
                viewer.clock.shouldAnimate = true;
                var previousTime = viewer.clock.currentTime.secondsOfDay;
                const onTickCallback = () => {
                    var spinRate = 1;
                    var currentTime = viewer.clock.currentTime.secondsOfDay;
                    var delta = (currentTime - previousTime) / 1000;
                    previousTime = currentTime;
                    viewer.scene.camera.rotate(Cesium.Cartesian3.UNIT_Z, -spinRate * delta);
                }
                // 开启地图自转效果
                viewer.clock.onTick.addEventListener(onTickCallback);

            };

            const firstCesium = ()=>{
                let viewer = new Cesium.Viewer("CesiumContainer", {
                    sceneModePicker: false,
                    navigationHelpButton: false,
                    baseLayerPicker: false,
                    animation: false,
                    timeline: false,
                    geocoder: false,
                    homeButton: false,
                    // infoBox: false,
                });
                // 设置自动旋转
                rotate(4000, viewer);

                // 设置背景颜色
                // viewer.scene.skyBox.show = false;
                // viewer.scene.backgroundColor = Cesium.Color.DARKBLUE;
                // viewer.scene.sun.show = false;
                // viewer.scene.moon.show = false;
            
                // 去掉logo
                viewer.cesiumWidget.creditContainer.style.display = "none"; 
                
                // 去掉背景图层
                // viewer.imageryLayers.removeAll();
        
                // 鼠标右键 倾斜操作
                viewer.scene.screenSpaceCameraController.tiltEventTypes = [
                    Cesium.CameraEventType.RIGHT_DRAG
                ];
                // 鼠标滑轮 放缩操作
                viewer.scene.screenSpaceCameraController.zoomEventTypes = [
                    Cesium.CameraEventType.WHEEL,
                    // Cesium.CameraEventType.PINCH
                ];
                // 鼠标左键 3D下聚焦局部时给人感觉是平移-本质是地球旋转(范围小-旋转类似平移)
                viewer.scene.screenSpaceCameraController.rotateEventTypes = [
                    Cesium.CameraEventType.LEFT_DRAG
                ];
                let geojsonLayer = Cesium.GeoJsonDataSource.load(
                    "http://192.168.1.127:80/HeBei_DiZhi/ZG.json",	// 这里是json文件的地址
                ).then((dataSource)=>{
                    const entities = dataSource.entities.values;
                    const colorHash = {};
                    for (let i = 0; i < entities.length; i++) {
                        //For each entity, create a random color based on the state name.
                        //Some states have multiple entities, so we store the color in a
                        //hash so that we use the same color for the entire state.
                        const entity = entities[i];
                        // console.log(i, entity);
                        const name = entity.name;
                        let color = colorHash[name];
                        if (!color) {
                        color = Cesium.Color.fromRandom({
                            alpha: 1.0,
                        });
                        legend[name] = color.toCssHexString();
                        colorHash[name] = color;
                        }

                        //Set the polygon material to our random color.
                        entity.polygon.material = color;
                        //Remove the outlines.
                        entity.polygon.outline = false;

                        // entity.polygon.extrudedHeight =
                        // entity.properties.Population / 50.0;
                    }
                    
                    viewer.dataSources.add(dataSource);

                    viewer.entities.add({
                        position: Cesium.Cartesian3.fromDegrees(115, 38, 1000000, Cesium.Ellipsoid.WGS84),
                        label: {
                            text: "中华人民共和国",
                            showBackground: true,
                            fillColor: Cesium.Color.WHITE,
                            font: '24px sans-serif',
                            // pixelOffset: new Cesium.Cartesian2(20, -15),
                            // scaleByDistance: new Cesium.NearFarScalar(1.5e2, 2.0, 8e5, 0),
                            backgroundColor: Cesium.Color.TRANSPARENT,
                        }
                    });
                })
            };
            onMounted(() => {
                firstCesium()
            });
            return {
                legend,
            }
        }
    }
</script>

<style lang="scss" scoped>
    #container {
        position: relative;
        height: 100%;
        width: 100%;
        background-color: darkblue;
    }
    #CesiumContainer {
        position: absolute;
        top: 15%;
        left: 20%;
        height: 70%;
        width: 60%;
    }
    #box01 {
        position: absolute;
        top: 8%;
        left: 2.5%;
        height: 20%;
        width: 15%;
    }
    #title {
        position: absolute;
        top: 2%;
        left: 3.5%;
        font-size: 0.4vh;
        color: white;

    }
    #box02 {
        position: absolute;
        top: 30%;
        left: 2.5%;
        height: 20%;
        width: 15%;
    }
    #box03 {
        position: absolute;
        top: 8%;
        right: 2.5%;
        height: 20%;
        width: 15%;
    }
    #box04 {
        position: absolute;
        top: 30%;
        right: 2.5%;
        height: 20%;
        width: 15%;
    }
    #box05 {
        position: absolute;
        top: 52%;
        left: 2.5%;
        height: 20%;
        width: 15%;
    }
    #box06 {
        position: absolute;
        top: 52%;
        right: 2.5%;
        height: 20%;
        width: 15%;
    }
    #box07 {
        position: absolute;
        top: 74%;
        left: 2.5%;
        height: 20%;
        width: 15%;
    }
    #box08 {
        position: absolute;
        top: 74%;
        right: 2.5%;
        height: 20%;
        width: 15%;
    }
    img {
        position: absolute;
        top: 20%;
        left: 15%;
        height: 70%;
        width: 70%;
    }
    #legend {
        position: absolute;
        bottom: 100px;
        right: 20px;
    }
    
</style>

        ④ router index.js

        

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于使用Vue来实现DataV可视化大屏,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Vue CLI,如果没有安装,可以通过以下命令进行安装: ``` npm install -g @vue/cli ``` 2. 创建一个新的Vue项目,可以使用以下命令: ``` vue create datav-visualization ``` 3. 进入到项目目录中: ``` cd datav-visualization ``` 4. 安装DataV可视化库,可以使用以下命令: ``` npm install @jiaminghi/data-view ``` 5. 在项目中引入DataV可视化组件。你可以在`main.js`文件中添加以下代码: ```javascript import Vue from 'vue'; import App from './App.vue'; import DataV from '@jiaminghi/data-view'; Vue.use(DataV); new Vue({ render: (h) => h(App), }).$mount('#app'); ``` 6. 创建一个新的组件用于展示DataV可视化大屏。你可以在`src/components`目录下创建一个新的组件文件,例如`DataVScreen.vue`,然后在该文件中编写DataV可视化大屏的代码。 7. 在需要展示DataV可视化大屏的地方使用该组件。例如,在`App.vue`文件中添加以下代码: ```vue <template> <div id="app"> <DataVScreen /> </div> </template> <script> import DataVScreen from './components/DataVScreen.vue'; export default { name: 'App', components: { DataVScreen, }, }; </script> ``` 8. 运行项目,可以使用以下命令启动开发服务器: ``` npm run serve ``` 这样,你就可以使用Vue来实现DataV可视化大屏了。当然,具体的可视化效果和功能需要根据你的需求进行定制和开发。希望对你有所帮助!如果有任何问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值