vue2.0项目集成Cesium的实现方法
作者:林珞 发布时间:2024-06-07 15:22:22
标签:vue2,集成,Cesium
安装cesium
在已有项目中执行,
npm i cesium
修改配置
build/webpack.base.conf.js
1、定义 Cesium 源码路径
const cesiumSource = '../node_modules/cesium/Source'
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
//--cesium--配置
const cesiumSource = '../node_modules/cesium/Source';
2、在output 里加入sourcePrefix: ' ' 让webpack 正确处理多行字符串
3、配置 amd参数
4、module中在rules后添加 unknownContextCritical: false,
module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: ["babel-polyfill", './src/main.js']
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production' ?
config.build.assetsPublicPath : config.dev.assetsPublicPath,
//--cesium--配置------------------------------------
sourcePrefix: ' '
},
//--cesium--配置----------------------------------------
amd:{
toUrlUndefined: true
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
//--cesium--配置
'cesium': path.resolve(__dirname, cesiumSource)
}
},
module: {
rules: [
...
],
//--cesium--配置-------------------------------------
//unknownContextRegExp: /^.\/.*$/
unknownContextCritical: false,
}
}
build/webpack.dev.conf.js
1、定义 Cesium 源码路径和Cesium Workers 路径
const cesiumSource = 'node_modules/cesium/Source'
const cesiumWorkers = '../Build/Cesium/Workers'
(注意这里的 node_modules 与webpack.base.conf.js的不同,前面没有../)
2、定义CESIUM_BASE_URL变量
3、在plugins 中加入下面插件,拷贝静态资源
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env'),
//--cesium--配置-------------------------------------------
'CESIUM_BASE_URL': JSON.stringify('')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}),
//--cesium--配置---------------------------------------------
new CopyWebpackPlugin([ { from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' } ]), //flag
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 CopyWebpackPlugin([ { from: 'ThirdParty', to: 'ThirdParty' } ]),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.dev.assetsSubDirectory,
ignore: ['.*']
}
])
]
build/webpack.prod.conf.js
1、定义
const cesiumSource = 'node_modules/cesium/Source';
const cesiumWorkers = '../Build/Cesium/Workers';
2、定义'CESIUM_BASE_URL'变量
3、在plugins 中加入下面插件,拷贝静态资源
plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
'process.env': env,
//--cesium--配置--------------------------------------
'CESIUM_BASE_URL': JSON.stringify('static')
}),
...
new HtmlWebpackPlugin({
...
},
//--cesium--配置--------------------------------------
new CopyWebpackPlugin([ { from: path.join(cesiumSource, cesiumWorkers), to: 'static/Workers' } ]),//flag
new CopyWebpackPlugin([ { from: path.join(cesiumSource, 'Assets'), to: 'static/Assets' } ]),
new CopyWebpackPlugin([ { from: path.join(cesiumSource, 'Widgets'), to: 'static/Widgets' } ]),
new CopyWebpackPlugin([ { from: path.join(cesiumSource, 'ThirdParty/Workers'), to: 'ThirdParty/Workers' } ]),
new CopyWebpackPlugin([ { from: 'ThirdParty', to: 'ThirdParty' } ]),
...
ThirdParty
在项目根目录新建文件夹ThirdParty,放入draco_decoder.wasm文件,在加载gltf模型文件需要用到
来源:https://segmentfault.com/a/1190000019909927


猜你喜欢
- 一、前言如果你自己打印过东西,应该有过这种经历。如果用自己拍的图片,在手机上看感觉还是清晰可见,但是一打印出来就是漆黑一片。比如下面这两张图
- 例如:性别 gender 男 女 保密基本语法:enum(数据值 1,数据值 2...);数据值列表在 255 个以内,使用 1 个字节来存
- time简介世界上第一台计算机操作系统Unix是诞生于1970年,然后就开始了计算机的时间计算,所以我们计算机的时间是开始于1970年1月1
- Python 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。Python 的设计具有很强的可读性,相比其他语言经常使用英文
- 使用requests下载文件1、获取token,或者session如不需要可忽略login_url = "http://xxxx/
- 一、利用webbrowser.open()打开一个网站:>>> import webbrowser >>>
- declare @tt varchar(20) set @tt = 'monisubbouns' declare @int
- 【OpenCV】⚠️高手勿入! 半小时学会基本操作 ⚠️ 图像轮廓概述OpenCV 是一个跨平台的计算机视觉库, 支持多语言, 功能强大.
- 前言:很多人都在使用mysql数据库,但是很少有人能够说出来整个sql语句的执行过程是怎样的,如果不了解执行过程的话,就很难进行sql语句的
- 废话不多说了,直接给大家贴代码了,具体代码如下所示:<script type="text/javascript"&
- 1.1 简介深层神经网络一般都需要大量的训练数据才能获得比较理想的结果。在数据量有限的情况下,可以通过数据增强(Data Augmentat
- 三重相等运算符 === 严格检查2个值是否相同:1 === 1; // => true1 === '1';
- 1.可以通过settings/dev.py的ALLOWED_HOSTS,设置允许访问# 设置哪些客户端可以通过地址访问到后端 A
- 本文实例总结了PHP常用字符串操作函数。分享给大家供大家参考,具体如下:/*常用的字符串输出函数** echo() 输出字符串* print
- 1069错误(由于登录失败而无法启动服务)解决方法在本版面出现这个问题的频率也算是很高的了,新手通常会比较多遇到这个问题原因很简单,安装SQ
- 最多16列。 create table test ( f1 int, f2 int, f3 int, f4 int, f5 int, f6
- 今天因工作需要写了个小程序,用于在图片集中自动抽取需要的照片。该程序只是实现了基本功能,还有很多需要完善的地方,展示出来算是给自己鼓鼓气吧。
- 目录1 、一般同步下载2、 使用流式请求,requests.get方法的stream3 、异步下载文件4、 异步拆分下载文件5、注意1 、一
- 本文给出了MySQL数据库中定义外键的必要性、具体的定义步骤和相关的一些基本操作,供大家参考!定义数据表假如某个电脑生产商,它的数据库中保存
- 本文实例讲述了Python ORM编程。分享给大家供大家参考,具体如下:ORM编程ORM(object-relational mapping