最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue2中配置Cesium全過程

 更新時間:2023年05月19日 10:16:47   作者:愿為浪漫渡此劫  
這篇文章主要介紹了Vue2中配置Cesium全過程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

基于Vue2配置Cesium

本文是關(guān)于基于Vue2,對Cesium,進行在線使用和離線(內(nèi)網(wǎng))使用配置

一、安裝Cesium依賴

npm i Cesium

二、在線Cesimu配置(在vue.config.js文件中進行如下配置)

const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const cesiumSource = "./node_modules/cesium/Source";
function resolve(dir) {
  return path.join(__dirname, dir);
}
module.exports = {
  // 基本路徑
  // publicPath: "./portal", // 打包
  publicPath: "./",
  runtimeCompiler: true,
  // 輸出文件目錄
  outputDir: "dist",
  configureWebpack: {
    output: {
      sourcePrefix: "", // 1 讓webpack 正確處理多行字符串配置 amd參數(shù)
    },
    amd: {
      toUrlUndefined: true, // webpack在cesium中能友好的使用require
    },
    resolve: {
      extensions: [".js", ".vue", ".json"],
      alias: {
        vue$: "vue/dist/vue.esm.js",
        "@": path.resolve("src"),
        components: path.resolve("src/components"),
        assets: path.resolve("src/assets"),
        views: path.resolve("src/views"),
        cesium: path.resolve(__dirname, cesiumSource),
      },
    },
    plugins: [
      new CopyWebpackPlugin([
        { from: path.join(cesiumSource, "Workers"), 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("./"),  // 本地
        //CESIUM_BASE_URL: JSON.stringify("./portal"),  // 打包后
      }),
    ],
    // 導(dǎo)致打包出現(xiàn)length undefined
    // // webpack在cesium中能友好的使用import.meta 
    module: {
      rules: [
        {
          test: /\.js$/,
          use: {
            loader: "@open-wc/webpack-import-meta-loader",
          },
        },
      ],
    }
  },
  assetsDir: "assets",
  filenameHashing: false,
  lintOnSave: process.env.NODE_ENV !== "production",
  // lintOnSave: false,
  productionSourceMap: false,
  devServer: {
    host: "0.0.0.0",
    port: 8080, // 端口號
    https: false, // https:{type:Boolean}
    open: true, //配置自動啟動瀏覽器
    proxy: {
      "/pre": {
        target: "http://192.168.102.54:8733/",
        changeOrigin: true, 
        pathRewrite: {
          "^/pre": "",
        },
      },
    },
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: `@import "./src/assets/css/theme.scss";`, // scss 的目錄文件
      },
    },
  },
};

三、離線Cesium配置

1、將Cesium資源文件夾

放在public/libs/Cesium,如圖所示

這個Cesium文件夾來源于,node-modules下的,如圖所示

2、單頁面 public/index.html引入

<script src="./libs/Cesium/Cesium.js" type="text/javascript"></script>

3、vue.config.js 如下配置

const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const cesiumSource = "./node_modules/cesium/Source";
function resolve(dir) {
  return path.join(__dirname, dir);
}
module.exports = {
  // 基本路徑
  // publicPath: "./portal", // 打包
  publicPath: "./",
  runtimeCompiler: true,
  // 輸出文件目錄
  outputDir: "dist",
  configureWebpack: {
    output: {
      sourcePrefix: "", // 1 讓webpack 正確處理多行字符串配置 amd參數(shù)
    },
    amd: {
      toUrlUndefined: true, // webpack在cesium中能友好的使用require
    },
    resolve: {
      extensions: [".js", ".vue", ".json"],
      alias: {
        vue$: "vue/dist/vue.esm.js",
        "@": path.resolve("src"),
        components: path.resolve("src/components"),
        assets: path.resolve("src/assets"),
        views: path.resolve("src/views"),
        cesium: path.resolve(__dirname, cesiumSource),
      },
    },
    plugins: [
      new CopyWebpackPlugin([
        {
          from: 'node_modules/cesium/Build/Cesium',
          to: 'libs/Cesium',
          filter: (resourcePath) => {
            if (/cesium[\\/]Build[\\/]Cesium[\\/]Cesium.js$/.test(resourcePath)) {
              return false;
            } else if (/cesium[\\/]Build[\\/]Cesium[\\/]Cesium.d.ts$/.test(resourcePath)) {
              return false;
            }
            return true;
          },
        },
      ]),
      new webpack.DefinePlugin({
        // CESIUM_BASE_URL: JSON.stringify("./"),  // 本地
        CESIUM_BASE_URL: JSON.stringify('libs/Cesium'),
        //CESIUM_BASE_URL: JSON.stringify("./portal"),  // 打包后
      }),
    ],
    optimization : {
      splitChunks : {
        chunks : "all",
        cacheGroups : {
          cesium: {
            name: 'Cesium',
            priority: 30,
            test: /[\\/]node_modules[\\/]@smart[\\/]cesium[\\/]Build[\\/]Cesium[\\/]Cesium.js/
          },
        }
      }
    },
    // 導(dǎo)致打包出現(xiàn)length undefined
    // // webpack在cesium中能友好的使用import.meta 
    module: {
      rules: [
        {
          test: /\.js$/,
          use: {
            loader: "@open-wc/webpack-import-meta-loader",
          },
        },
      ],
    }
  },
  assetsDir: "assets",
  filenameHashing: false,
  lintOnSave: process.env.NODE_ENV !== "production",
  // lintOnSave: false,
  productionSourceMap: false,
  devServer: {
    host: "0.0.0.0",
    port: 8080, // 端口號
    https: false, // https:{type:Boolean}
    open: true, //配置自動啟動瀏覽器
    proxy: {
      "/sso": {
        target: "http://192.168.102.194:8098/",
        changeOrigin: true, //開啟代理:在本地會創(chuàng)建一個虛擬服務(wù)端,然后發(fā)送請求的數(shù)據(jù),并同時接收請求的數(shù)據(jù),這樣服務(wù)端和服務(wù)端進行數(shù)據(jù)的交互就不會有跨域問題
        pathRewrite: {
          "^/sso": "", //這里理解成用'/api'代替target里面的地址,比如我要調(diào)用'http://40.00.100.100:3002/user/add',直接寫'/api/user/add'即可
        },
      },
      // 共享中心
      "/pre": {
        target: "http://192.168.102.54:8733/",   // zk
        // target: "http://192.168.102.43:8733/",   // s
        changeOrigin: true, 
        pathRewrite: {
          "^/pre": "", 
        },
      },
      "/zk": {
        target: "http://192.168.102.54:8736/",
        changeOrigin: true,
        pathRewrite: {
          "^/zk": "", 
        },
      },
      "/scene": {
        target: "http://192.168.102.43:8070/",
        changeOrigin: true, 
        pathRewrite: {
          "^/scene": "",
        },
      },
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: `@import "./src/assets/css/theme.scss";`, // scss 的目錄文件
      },
    },
  },
};

4、在Cesium初始化時

如下使用

 init() {
      const Cesium = this.cesium;
      this.highlightColor = Cesium.Color.GREEN.withAlpha(0.6);
      this.normalColor = Cesium.Color.YELLOW.withAlpha(0.6);
      this.viewer = new Cesium.Viewer("cesiumContainer", {
        //先行禁止infoBox彈出
        selectionIndicator: false,
        infoBox: false,
        geocoder: false,
        homeButton: false,
        sceneModePicker: false,
        fullscreenButton: false,
        navigationHelpButton: false,
        animation: false,
        timeline: false,
        fulllscreenButtond: false,
        vrButton: false,
        // 加載本地離線Cesium資源
        imageryProvider: new Cesium.TileMapServiceImageryProvider({
          url: Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII'),
        }),
      });
      this.viewer._cesiumWidget._creditContainer.style.display = "none"; // 隱藏版權(quán)
    },

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue3實現(xiàn)全局公共函數(shù)的完整方案(創(chuàng)建、掛載、引用、使用)

    Vue3實現(xiàn)全局公共函數(shù)的完整方案(創(chuàng)建、掛載、引用、使用)

    本文詳細介紹了如何在Vue3項目中創(chuàng)建、掛載、引用和使用全局公共函數(shù),包括標(biāo)準(zhǔn)目錄結(jié)構(gòu)、創(chuàng)建公共函數(shù)、全局注冊、頁面使用以及規(guī)范,通過本文,新手開發(fā)者可以快速搭建企業(yè)級規(guī)范工具庫,需要的朋友可以參考下
    2026-03-03
  • Vue 3中的defineEmits()和defineProps()使用小結(jié)

    Vue 3中的defineEmits()和defineProps()使用小結(jié)

    defineProps()和defineEmits()是Vue 3中Composition API的重要組成部分,它們分別用于定義組件接收的屬性和觸發(fā)的事件,本文給大家介紹Vue 3中的defineEmits()和defineProps()解析,感興趣的朋友跟隨小編一起看看吧
    2024-04-04
  • Vue前端高效分包指南

    Vue前端高效分包指南

    在 Vue 項目中,隨著業(yè)務(wù)迭代,代碼體積會像冬天的羽絨服一樣越來越膨脹,如果不加以控制,單個體積過大的JS文件會導(dǎo)致頁面加載緩慢、用戶體驗下降,甚至影響轉(zhuǎn)化率,今天就帶大家走進前端分包的奇妙世界,用實戰(zhàn)經(jīng)驗告訴你如何優(yōu)雅地拆分代碼包,需要的朋友可以參考下
    2025-08-08
  • 公共Hooks封裝文件下載useDownloadFile實例詳解

    公共Hooks封裝文件下載useDownloadFile實例詳解

    這篇文章主要為大家介紹了公共Hooks封裝文件下載useDownloadFile實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • vue watch自動檢測數(shù)據(jù)變化實時渲染的方法

    vue watch自動檢測數(shù)據(jù)變化實時渲染的方法

    本篇文章主要介紹了vue watch自動檢測數(shù)據(jù)變化實時渲染的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • vue-video-player視頻播放器使用配置詳解

    vue-video-player視頻播放器使用配置詳解

    這篇文章主要為大家詳細介紹了vue-video-player視頻播放器的使用和配置,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • vue+elementui實現(xiàn)點擊table中的單元格觸發(fā)事件--彈框

    vue+elementui實現(xiàn)點擊table中的單元格觸發(fā)事件--彈框

    這篇文章主要介紹了vue+elementui實現(xiàn)點擊table中的單元格觸發(fā)事件--彈框,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • Vue利用AJAX請求獲取XML文件數(shù)據(jù)的操作方法

    Vue利用AJAX請求獲取XML文件數(shù)據(jù)的操作方法

    在現(xiàn)代Web開發(fā)中,從前端框架到后端API的交互是必不可少的一部分,Vue.js作為一個輕量級且功能強大的前端框架,支持多種方式與服務(wù)器通信,從而獲取或發(fā)送數(shù)據(jù),本文將詳細介紹如何在Vue.js項目中使用AJAX請求來獲取XML格式的數(shù)據(jù),需要的朋友可以參考下
    2024-09-09
  • 詳解在vue開發(fā)中如何利用.env文件

    詳解在vue開發(fā)中如何利用.env文件

    我們在 vue 項目的目錄中經(jīng)常看到 env 開頭的文件,在文件內(nèi)聲明一些變量,這些變量就是一些配置變量,在不同環(huán)境下可使用的變量,本文我們將給大家介紹在vue開發(fā)中如何利用.env文件,需要的朋友可以參考下
    2023-10-10
  • Vue3中v-model雙向綁定的避坑指南(2026最新)

    Vue3中v-model雙向綁定的避坑指南(2026最新)

    這篇文章主要為大家詳細介紹了Vue3中v-model雙向綁定的正確用法和避坑指南,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2026-04-04

最新評論

馆陶县| 万全县| 西林县| 西乌珠穆沁旗| 永康市| 旬邑县| 鄂托克前旗| 普洱| 宝应县| 通州市| 琼中| 清水河县| 凌源市| 芷江| 忻州市| 利津县| 乃东县| 慈利县| 冷水江市| 古田县| 南陵县| 许昌市| 克拉玛依市| 西平县| 晋宁县| 师宗县| 灵寿县| 灵丘县| 彭泽县| 永济市| 永定县| 通渭县| 房山区| 昌图县| 灵寿县| 清远市| 闵行区| 轮台县| 红桥区| 葵青区| 沭阳县|