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

vue中使用Cesium加載shp文件、wms服務(wù)、WMTS服務(wù)問題

 更新時(shí)間:2023年05月19日 10:25:26   作者:愿為浪漫渡此劫  
這篇文章主要介紹了vue中使用Cesium加載shp文件、wms服務(wù)、WMTS服務(wù)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

如何在vue中使用Cesium加載shp文件或者說是wms服務(wù)

背景:企業(yè)項(xiàng)目在管理界面可以上傳shp數(shù)據(jù)文件集合,需要在用戶界面可視化展示

注意: Cesium是不能直接加載shp數(shù)文件的

所以需要后端將上傳的shp數(shù)據(jù)轉(zhuǎn)成WMS服務(wù),這樣Cesium就可以加載WMS服務(wù)來可視化shp數(shù)據(jù)了

注意后端接口必須返回以下關(guān)于WMS服務(wù)的參數(shù)

  1. 工作空間 share:xxxx,用于Cesium加載wms服務(wù)的圖層
  2. srs : 用于Cesium加載wms服務(wù)的srs屬性
  3. wms服務(wù)地址 : 類似 http://localhost:8080/geoServer/wms
  4. 四個(gè)坐標(biāo)xmin,ymin和xmax,ymax : 用于定位WMS地圖的位置

Vue初始化Cesium

前提: Vue使用Cesium處理npm,還需要在Webpack文件配置,詳情可看上期文章

基于Vue的Cesium配置

// 初始化
<template>
? ?// 地圖容器?
? <div class="img-box" id="cesiumContainer"></div>
</template>
<script>
export default {
? props: ["fileUrl","srs","workspace","zb"],
? data() {
? ? return {
? ? ? viewer: {},
? ? ? Cesium: {},
? ? ? highlightColor: null,
? ? ? normalColor: null,
? ? ? wmsLayer : null // wms 地圖服務(wù)圖層
? ? };
? },
? methods: {
? ? // init : 初始化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,
? ? ? ? //baseLayerPicker : false,
? ? ? ? geocoder: false,
? ? ? ? homeButton: false,
? ? ? ? sceneModePicker: false,
? ? ? ? fullscreenButton: false,
? ? ? ? navigationHelpButton: false,
? ? ? ? animation: false,
? ? ? ? timeline: false,
? ? ? ? fulllscreenButtond: false,
? ? ? ? vrButton: false,
?? ??? ?// getImageryProviderArr和getTerrainProviderViewModelsArr ?可根據(jù)項(xiàng)目需求進(jìn)行實(shí)現(xiàn)
? ? ? ? //獲取或設(shè)置可用于圖像選擇的ProviderViewModel實(shí)例數(shù)組。
? ? ? ? imageryProviderViewModels: this.getImageryProviderArr(),
? ? ? ? // //獲取或設(shè)置可用于地形選擇的ProviderViewModel實(shí)例數(shù)組。
? ? ? ? terrainProviderViewModels: this.getTerrainProviderViewModelsArr(),
? ? ? });
? ? ? this.viewer._cesiumWidget._creditContainer.style.display = "none"; // 隱藏版權(quán)
? ? },
? ? getImageryProviderArr() {
? ? ? const Cesium = this.cesium;
? ? ? return [
? ? ? ? new Cesium.ProviderViewModel({
? ? ? ? ? //圖層的名稱。
? ? ? ? ? name: "影像底圖",
? ? ? ? ? //顯示項(xiàng)目被隱藏的工具提示
? ? ? ? ? tooltip: "影像底圖",
? ? ? ? ? //代表圖層的圖標(biāo)
? ? ? ? ? iconUrl: require("@/assets/img/yxdt.png"),
? ? ? ? ? //一個(gè)函數(shù)或命令,用于創(chuàng)建一個(gè)或多個(gè)提供程序,這些提供程序?qū)⒃谶x擇此項(xiàng)目時(shí)添加到地球儀中。
? ? ? ? ? creationFunction: function () {
? ? ? ? ? ? return new Cesium.ArcGisMapServerImageryProvider({
? ? ? ? ? ? ? url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
? ? ? ? ? ? });
? ? ? ? ? },
? ? ? ? }),
? ? ? ? new Cesium.ProviderViewModel({
? ? ? ? ? //圖層的名稱
? ? ? ? ? name: "電子地圖",
? ? ? ? ? //顯示項(xiàng)目被隱藏的工具提示
? ? ? ? ? tooltip: "電子地圖",
? ? ? ? ? //代表圖層的圖標(biāo)
? ? ? ? ? iconUrl: require("@/assets/img/sldt.png"),
? ? ? ? ? //一個(gè)函數(shù)或命令,用于創(chuàng)建一個(gè)或多個(gè)提供程序,這些提供程序?qū)⒃谶x擇此項(xiàng)目時(shí)添加到地球儀中
? ? ? ? ? creationFunction: function () {
? ? ? ? ? ? return new Cesium.ArcGisMapServerImageryProvider({
? ? ? ? ? ? ? url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer",
? ? ? ? ? ? });
? ? ? ? ? },
? ? ? ? }),
? ? ? ];
? ? },
? ? getTerrainProviderViewModelsArr() {
? ? ? const Cesium = this.cesium;
? ? ? return [
? ? ? ? new Cesium.ProviderViewModel({
? ? ? ? ? //圖層的名稱
? ? ? ? ? name: "無地形",
? ? ? ? ? //顯示項(xiàng)目被隱藏的工具提示
? ? ? ? ? tooltip: "WGS84標(biāo)準(zhǔn)球體",
? ? ? ? ? //代表圖層的圖標(biāo)
? ? ? ? ? iconUrl: require("@/assets/img/WGS84.png"),
? ? ? ? ? //一個(gè)函數(shù)或命令,用于創(chuàng)建一個(gè)或多個(gè)提供程序,這些提供程序?qū)⒃谶x擇此項(xiàng)目時(shí)添加到地球儀中
? ? ? ? ? creationFunction: function () {
? ? ? ? ? ? return new Cesium.EllipsoidTerrainProvider({
? ? ? ? ? ? ? ellipsoid: Cesium.Ellipsoid.WGS84,
? ? ? ? ? ? });
? ? ? ? ? },
? ? ? ? }),
? ? ? ? new Cesium.ProviderViewModel({
? ? ? ? ? //圖層的名稱
? ? ? ? ? name: "地形",
? ? ? ? ? //顯示項(xiàng)目被隱藏的工具提示
? ? ? ? ? tooltip: "STK在線地形",
? ? ? ? ? //代表圖層的圖標(biāo)
? ? ? ? ? iconUrl: require("@/assets/img/STK在線地形.png"),
? ? ? ? ? //一個(gè)函數(shù)或命令,用于創(chuàng)建一個(gè)或多個(gè)提供程序,這些提供程序?qū)⒃谶x擇此項(xiàng)目時(shí)添加到地球儀中
? ? ? ? ? creationFunction: function () {
? ? ? ? ? ? return new Cesium.CesiumTerrainProvider({
? ? ? ? ? ? ? url: Cesium.IonResource.fromAssetId(1),
? ? ? ? ? ? ? requestWaterMask: !0,
? ? ? ? ? ? ? requestVertexNormals: !0,
? ? ? ? ? ? });
? ? ? ? ? },
? ? ? ? }),
? ? ? ];
? ? },
? },
};
</script>

加載WMS服務(wù)

// 加載geoserver wms服務(wù)
addWMS(fileUrl) {
? ? // 刪除之前的wms 圖層?
? ? // 這塊移除圖層 需要指出圖層變量名
? ?this.viewer.imageryLayers.remove(this.wmsLayer);
? ?this.wmsLayer = null;
? const Cesium = this.cesium;
? if(this.zb.xmin) {
? ? var provider = new Cesium.WebMapServiceImageryProvider({
? ? ? ? url : fileUrl, // wms服務(wù)地址
? ? ? ? // layers 必須參數(shù),不寫會(huì)報(bào)錯(cuò);
? ? ? ? // layers寫的不對(duì)會(huì)報(bào)如下錯(cuò)誤: An error occered in "WebMapServiceImageryProvider":
? ? ? ? // Failed to obtain image tile X : 425y ? ?(有的博客說這是跨域????)
?? ??? ?// 后端API接口返回
? ? ? ? layers: this.workspace, ?
? ? ? ? // 必須參數(shù)rectangle : 用來定位加載的WMS位置 ?后端API接口返回
? ? ? ? rectangle: Cesium.Rectangle.fromDegrees(
? ? ? ? ? +this.zb.xmin, +this.zb.ymin, +this.zb.xmax, +this.zb.ymax), ? // 必須有
? ? ? ? parameters: {
? ? ? ? ? ? service : 'WMS',
? ? ? ? ? ? format: 'image/png',
? ? ? ? ? ? transparent: true,
? ? ? ? ? ? // 后端API接口返回的
? ? ? ? ? ? srs: this.srs,
? ? ? ? } ?
? ? });
? ? // 加載WMS服務(wù)到viewer
? ? this.wmsLayer = this.viewer.imageryLayers.addImageryProvider(provider);
? ? // 飛入動(dòng)畫
? ? this.viewer.flyTo(this.wmsLayer, {
? ? ? ? duration: 2
? ? });
? } else {
? ? this.$message.warning('該地圖服務(wù)沒有坐標(biāo)可以定位')
? }

加載WMTS服務(wù)

對(duì)與url 屬性: 很多博客都說要進(jìn)行 如下拼接:

后端返回的wmts/rest/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}?format=image/png

其實(shí)不用拼接 只需要后端返回的/wtms路徑即可

// 加載geoserver wmts服務(wù)
addWMTS(fileUrl) {
? ? ? const Cesium = this.cesium;
? ? ? let provider = new Cesium.WebMapTileServiceImageryProvider({
? ? ? ? // ?對(duì)與url ?很多博客都說要進(jìn)行 如下拼接
? ? ? ? // 后端返回的wmts/rest/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}?format=image/png
?? ??? ?// 其實(shí)不用拼接 ?只需要后端返回的/wtms路徑即可
? ? ? ? url: fileUrl, //服務(wù)地址 服務(wù)地址只需要后端返回的 /WMTS ? 不需要給后面拼接任何東西, ?
? ? ? ? layer: this.workspace, //圖層名稱 : "pucheng:satellite"
? ? ? ? style: '',
? ? ? ? format: 'image/png',
? ? ? ? tileMatrixSetID: this.srs, ?// "EPSG:900913"
? ? ? ? // 地圖飛入 ?定位的坐標(biāo) ?后端返回的數(shù)據(jù)
? ? ? ? rectangle: Cesium.Rectangle.fromDegrees(
? ? ? ? ? ? +this.zb.xmin, +this.zb.ymin, +this.zb.xmax, +this.zb.ymax),
? ? ? ? // 必須加 ?不然地圖出不來
?? ??? ?//之所以要在這里提出這個(gè)tileMatrixLabels參數(shù),是因?yàn)镚eoServer在緩沖切分瓦片時(shí)對(duì)每一個(gè)縮放級(jí)別的存儲(chǔ)目錄沒有使用相應(yīng)的數(shù)字,而使用了網(wǎng)格+級(jí)別的方式來命名,如“EPSG:9100913:10”表示的是使用“EPSG:9100913”網(wǎng)格切分的第10級(jí)瓦片。
? ? ? ? tileMatrixLabels : [`${this.srs}:0`,`${this.srs}:1`, `${this.srs}:2`,`${this.srs}:3`,`${this.srs}:4`,`${this.srs}:5`,`${this.srs}:6`,
? ? ? ? `${this.srs}:7`,`${this.srs}:8`,`${this.srs}:9`,`${this.srs}:10`,`${this.srs}:11`,`${this.srs}:12`,`${this.srs}:13`,`${this.srs}:14`,
? ? ? ? `${this.srs}:15`,`${this.srs}:16`,`${this.srs}:17`,`${this.srs}:18`,
? ? ? ? ],
? ? ? ? // 必須加 ?不然地圖出不來
? ? ? ? tilingScheme: new Cesium.GeographicTilingScheme({//此處很重要,很重要。。。
? ? ? ? ? numberOfLevelZeroTilesX: 2,
? ? ? ? ? numberOfLevelZeroTilesY: 1
? ? ? ? }),
? ? ? ? // tilematrixset: this.srs,
? ? ? ? // maximumLevel: 18,
? ? ? });
? ? ? let layer = this.viewer.imageryLayers.addImageryProvider(provider);
? ? ? //控制圖層顯示
? ? ? this.viewer.flyTo(layer, {
? ? ? ? ? duration: 2
? ? ? ? });
? ? },

cesium加載shp格式的白模建筑

ceisum加載shp格式的建筑。有兩種思路,目前推薦第二種。

方法一

將shp格式轉(zhuǎn)換為geojson格式,然后采用cesium提供的接口加載到ceisum中。

嚴(yán)重缺陷:在面對(duì)大場(chǎng)景問題,即數(shù)據(jù)量較大時(shí),非常容易卡死、崩潰

方法二

將shp轉(zhuǎn)換為3dtiles,然后加載到ceiusm中。

3dtiles是ceisum解決大場(chǎng)景問題專門提供的一種數(shù)據(jù)格式。

關(guān)鍵:轉(zhuǎn)換工具,我使用的是cesiumLab,比較好用,工具中需要加載dem,目測(cè)是用來與地形貼合的。

推薦方法:方法二。

總結(jié)

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

相關(guān)文章

  • Vue?3中defineProps與defineEmits用法深度解析

    Vue?3中defineProps與defineEmits用法深度解析

    defineProps 和 defineEmits 這兩個(gè)是Vue3中<script setup>語法糖特有的編譯宏,專門用于組件通信,這篇文章主要介紹了Vue3中defineProps與defineEmits用法的相關(guān)資料,需要的朋友可以參考下
    2026-02-02
  • Vue多層數(shù)據(jù)結(jié)構(gòu)響應(yīng)式失效,視圖更新失敗問題

    Vue多層數(shù)據(jù)結(jié)構(gòu)響應(yīng)式失效,視圖更新失敗問題

    這篇文章主要介紹了Vue多層數(shù)據(jù)結(jié)構(gòu)響應(yīng)式失效,視圖更新失敗問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • vue組件之全局注冊(cè)和局部注冊(cè)方式

    vue組件之全局注冊(cè)和局部注冊(cè)方式

    這篇文章主要介紹了vue組件之全局注冊(cè)和局部注冊(cè)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue實(shí)現(xiàn)分頁欄效果

    vue實(shí)現(xiàn)分頁欄效果

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)分頁欄效果,分頁欄設(shè)計(jì)的步驟與實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • vue?serve及其與vue-cli-service?serve之間的關(guān)系解讀

    vue?serve及其與vue-cli-service?serve之間的關(guān)系解讀

    這篇文章主要介紹了vue?serve及其與vue-cli-service?serve之間的關(guān)系,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue 路由 過渡動(dòng)效 數(shù)據(jù)獲取方法

    Vue 路由 過渡動(dòng)效 數(shù)據(jù)獲取方法

    這篇文章主要介紹了Vue 路由 過渡動(dòng)效 數(shù)據(jù)獲取方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-07-07
  • element plus tree拖動(dòng)節(jié)點(diǎn)交換位置和改變層級(jí)問題(解決方案)

    element plus tree拖動(dòng)節(jié)點(diǎn)交換位置和改變層級(jí)問題(解決方案)

    圖層list里有各種組件,用element plus的tree來渲染,可以把圖片等組件到面板里,面板是容器,非容器組件,比如圖片、文本等,就不能讓其他組件拖進(jìn)來,這篇文章主要介紹了element plus tree拖動(dòng)節(jié)點(diǎn)交換位置和改變層級(jí)問題(解決方案),需要的朋友可以參考下
    2024-04-04
  • vue3使用localStorage實(shí)現(xiàn)登錄注冊(cè)功能實(shí)例

    vue3使用localStorage實(shí)現(xiàn)登錄注冊(cè)功能實(shí)例

    這篇文章主要給大家介紹了關(guān)于vue3使用localStorage實(shí)現(xiàn)登錄注冊(cè)功能的相關(guān)資料, localStorage這個(gè)特性主要是用來作為本地存儲(chǔ)來使用的,解決了cookie存儲(chǔ)空間不足的問題,需要的朋友可以參考下
    2023-06-06
  • Vue中的ESLint配置方式

    Vue中的ESLint配置方式

    這篇文章主要介紹了Vue中的ESLint配置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • vue與axios上傳視頻并顯示上傳進(jìn)度情況

    vue與axios上傳視頻并顯示上傳進(jìn)度情況

    本文講述了項(xiàng)目中實(shí)現(xiàn)上傳視頻并顯示上傳進(jìn)度的功能,首先使用axios庫進(jìn)行單文件引入,未進(jìn)行封裝,通過element組件庫實(shí)現(xiàn)選擇文件上傳,并打印選擇文件的信息,上傳完成后,可以在展示區(qū)域顯示上傳的視頻,鼠標(biāo)移入播放區(qū)域時(shí)會(huì)有相應(yīng)的效果
    2026-02-02

最新評(píng)論

乐安县| 堆龙德庆县| 正宁县| 三原县| 涪陵区| 伊春市| 武汉市| 甘孜县| 邯郸市| 郧西县| 文昌市| 礼泉县| 普兰县| 苏尼特右旗| 平陆县| 木里| 泽普县| 运城市| 乌拉特前旗| 建湖县| 嘉定区| 东光县| 海淀区| 铁岭县| 廊坊市| 江津市| 虞城县| 瑞金市| 政和县| 昌图县| 克拉玛依市| 娱乐| 泾源县| 格尔木市| 阿拉尔市| 巴林右旗| 邳州市| 东港市| 石台县| 富锦市| 独山县|