1 Star 0 Fork 5

CesiumLearn / EarthSDK-vue-cli-app

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

earthsdk-vue-cli-app

简介

通过vue-cli创建项目,然后再基于EarthSDK创建地球。
如果是大型项目,可以参考这种方式来构建程序。
本项目,相当于在vue-cli的基础上做一些稍许修改,就可以加载EarthSDK了。

注意:该项目可以配置成使用纯Cesium开发,看说明文档最下方。

预览

项目安装

npm install

调试模式

npm run serve

发布版本

npm run build

运行测试

npm run test

语法检查

npm run lint

vue-cli的配置说明

See Configuration Reference.

在vue-cli的基础上加入对EarthSDK的支持的方法说明

  1. 加入必须的包
npm install copy-webpack-plugin
npm install earthsdk
  1. 创建vue.config.js
// vue.config.js
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  configureWebpack: config => {
    const cwp = new CopyWebpackPlugin([
      {
        from: './node_modules/earthsdk/dist/XbsjCesium',
        to: 'js/earthsdk/XbsjCesium',
        toType: 'dir'
      },
      {
        from: './node_modules/earthsdk/dist/XbsjEarth',
        to: 'js/earthsdk/XbsjEarth',
        toType: 'dir'
      },
    ]);
    config.plugins.push(cwp);
  }
}
  1. 创建地球组件 EarthComp.vue
<template>
  <div style="width: 100%; height: 100%">
    <div ref="earthContainer" style="width: 100%; height: 100%"></div>
    <div style="position: absolute; left: 18px; top: 18px">
      <button>{{ message }}</button>
    </div>
  </div>
</template>

<script>
// 1 创建Earth的vue组件
var EarthComp = {
  data() {
    return {
      message: "页面加载于 " + new Date().toLocaleString(),
      _earth: undefined, // 注意:Earth和Cesium的相关变量放在vue中,必须使用下划线作为前缀!
      _bgImagery: undefined
    };
  },
  // 1.1 资源创建
  mounted() {
    // 1.1.1 创建地球
    var earth = new XE.Earth(this.$refs.earthContainer);

    // 1.1.2 添加默认地球影像
    earth.sceneTree.root = {
      children: [
        {
          czmObject: {
            name: "默认离线影像",
            xbsjType: "Imagery",
            xbsjImageryProvider: {
              createTileMapServiceImageryProvider: {
                url: XE.HTML.cesiumDir + "Assets/Textures/NaturalEarthII",
                fileExtension: "jpg"
              },
              type: "createTileMapServiceImageryProvider"
            }
          }
        }
      ]
    };

    this._earth = earth;

    // 仅为调试方便用
    window.earth = earth;
  },
  // 1.2 资源销毁
  beforeDestroy() {
    // vue程序销毁时,需要清理相关资源
    this._earth = this._earth && this._earth.destroy();
  }
};

export default EarthComp;
</script>
  1. 修改main.js,

需要等待earthsdk载入以后(XE.ready()),再创建vue的示例(new Vue(...)),代码如下:

// 之前的代码注释掉
// new Vue({
//   render: h => h(App),
// }).$mount('#app')

// 修改后的代码
function startup() {
  new Vue({
    render: h => h(App),
  }).$mount('#app')
}

// 1 XE.ready()会加载Cesium.js等其他资源,注意ready()返回一个Promise对象。
XE.ready().then(startup);    
  1. 再改改index.html文件中的css样式等

将此项目配置成使用纯Cesium开发

找到public/index.html文件,做如下修改,即可使用纯Cesium进行开发。

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/CesiumLearn/EarthSDK-vue-cli-app.git
git@gitee.com:CesiumLearn/EarthSDK-vue-cli-app.git
CesiumLearn
EarthSDK-vue-cli-app
EarthSDK-vue-cli-app
master

搜索帮助