vue+cesium入门学习01

1安装cesium

我使用的软件是idea ,基于node.js进行开发,目前还有挺多东西是不了解的,所以现在跟着教程学习,创建三维球。
安装命令:

npm  install cesium 

2创建vue.config.js文件

这里主要是vue继承cesium的配置。在项目文件夹下创建vue.config.js文件。
然后复制粘贴以下代码。现在我依然理解不了某部分代码的意思,后续在了解吧。

const CopyWebpackPlugin = require('copy-webpack-plugin')
const webpack = require('webpack')
const path = require('path')

let cesiumSource = './node_modules/cesium/Source'
let cesiumWorkers = '../Build/Cesium/Workers'

module.exports = {
    // 基本路径
    publicPath: "./",
    // 输出文件目录
    outputDir: "dist",
    // eslint-loader 是否在保存的时候检查
    lintOnSave: false,
    // webpack-dev-server 相关配置
    devServer: {
        open: process.platform === "darwin",
        host: "0.0.0.0",
        port: 5000,
        https: false,
        hotOnly: false
    },
    configureWebpack: {
        output: {
            sourcePrefix: ' '
        },
        amd: {
            toUrlUndefined: true
        },
        resolve: {
            alias: {
                'vue$': 'vue/dist/vue.esm.js',
                '@': path.resolve('src'),
                'cesium': path.resolve(__dirname, cesiumSource)
            }
        },
        plugins: [
            new CopyWebpackPlugin([{ from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' }]),
            new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Assets'), to: 'Assets' }]),
            new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' }]),
            new CopyWebpackPlugin([{ from: path.join(cesiumSource, 'ThirdParty/Workers'), to: 'ThirdParty/Workers' }]),
            new webpack.DefinePlugin({
                CESIUM_BASE_URL: JSON.stringify('./')
            })
        ],
        module: {
            unknownContextCritical: /^.\/.*$/,
            unknownContextCritical: false
        }
    }
    };

3可以开始创建三维球了

新建一个vue文件.然后就可以得到一个三维球了

<template>
    <div class="mapBox">
        <div id="earthContainer">
        </div>
    </div>

</template>

<script>
    var Cesium=require("cesium/Cesium");
    var widgets=require("cesium/Widgets/widgets.css");
    Cesium.Ion.defaultAccessToken = '你的token';//不需要token也可以加载球,
    //想要知道token是什么东西,建议看一下原博主,也是我参考的教程,很详细:https://blog.csdn.net/sinat_36226553/article/details/107910880
    export default {
        name: "earth",
        mounted() {
            var viewer = new Cesium.Viewer("earthContainer",{
                // geocoder: false,//地理位置查询定位控件,默认使用bing地图服务
                homeButton: false,//默认相机位置
                sceneModePicker: false, //是否显示投影方式控件//3D、2D和哥伦布模式的切换按钮
                baseLayerPicker: true,  //是否显示图层选择控件//选择地形、影像等图层
                navigationHelpButton: false, //是否显示帮助信息控件//显示默认的相机控制提示
                geocoder:false, //是否显示地名查找控件
                animation: false, //是否显示动画控件//控制场景动画的播放速度.
                timeline: false, //是否显示时间线控件
                fullscreenButton: false,//是否全屏显示
                vrButton: false,
                shadows: true, //影子
                infoBox: false //是否显示点击要素之后显示的信息
            });
            viewer._cesiumWidget._creditContainer.style.display="none";//取消版权信息
        },

    }
</script>

<style scoped>
.mapBox{
    height: 100%;
    width: 100%;
}
    #earthContainer{
        height: 100%;
        width: 100%;
    }
</style>

在这里插入图片描述
参考博文:

https://blog.csdn.net/sinat_36226553/article/details/105896271

https://blog.csdn.net/qq_26610239/article/details/114044263

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

LH的苏小花

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

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

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

打赏作者

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

抵扣说明:

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

余额充值