vue2.0項(xiàng)目集成Cesium的實(shí)現(xiàn)方法
安裝cesium
在已有項(xiàng)目中執(zhí)行,
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參數(shù)
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 中加入下面插件,拷貝靜態(tài)資源
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 中加入下面插件,拷貝靜態(tài)資源
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
在項(xiàng)目根目錄新建文件夾ThirdParty,放入draco_decoder.wasm文件,在加載gltf模型文件需要用到
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue中使用Cesium加載shp文件、wms服務(wù)、WMTS服務(wù)問題
- Vue2中配置Cesium全過程
- cesium開發(fā)之如何在vue項(xiàng)目中使用cesium,使用離線地圖資源
- vue中安裝使用cesium方式(親測可用)
- 使用開源Cesium+Vue實(shí)現(xiàn)傾斜攝影三維展示功能
- vue實(shí)現(xiàn)滾動(dòng)條到頂部或者到指定位置
- Vue列表如何實(shí)現(xiàn)滾動(dòng)到指定位置樣式改變效果
- vue keep-alive列表頁緩存 詳情頁返回上一頁不刷新,定位到之前位置
- vue?cesium加載點(diǎn)與定位到指定位置的實(shí)現(xiàn)方法
相關(guān)文章
解決npm安裝錯(cuò)誤:No matching version found for&
這篇文章主要介紹了解決npm安裝錯(cuò)誤:No matching version found for XXX@3.3.6問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
vue?cli+axios踩坑記錄+攔截器使用方式,代理跨域proxy
這篇文章主要介紹了vue?cli+axios踩坑記錄+攔截器使用方式,代理跨域proxy,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
解決vue中使用swiper插件問題及swiper在vue中的用法
Swiper是純javascript打造的滑動(dòng)特效插件,面向手機(jī)、平板電腦等移動(dòng)終端。這篇文章主要介紹了解決vue中使用swiper插件及swiper在vue中的用法,需要的朋友可以參考下2018-04-04
詳解關(guān)于Vuex的action傳入多個(gè)參數(shù)的問題
這篇文章主要介紹了詳解關(guān)于Vuex的action傳入多個(gè)參數(shù)的問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-02-02
一文帶你深入了解V-model實(shí)現(xiàn)數(shù)據(jù)雙向綁定
這篇文章主要為大家詳細(xì)介紹了V-model實(shí)現(xiàn)數(shù)據(jù)雙向綁定的相關(guān)知識,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-12-12
使用vNode實(shí)現(xiàn)給列表字段打標(biāo)簽
這篇文章主要為大家介紹了使用vNode實(shí)現(xiàn)給列表字段打標(biāo)簽示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
Vue3全局掛載使用Axios學(xué)習(xí)實(shí)戰(zhàn)
這篇文章主要為大家介紹了Vue3全局掛載使用Axios學(xué)習(xí)實(shí)戰(zhàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06

