欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

背景:企業(yè)項目在管理界面可以上傳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. 四個坐標(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àn)
? ? ? ? //獲取或設(shè)置可用于圖像選擇的ProviderViewModel實例數(shù)組。
? ? ? ? imageryProviderViewModels: this.getImageryProviderArr(),
? ? ? ? // //獲取或設(shè)置可用于地形選擇的ProviderViewModel實例數(shù)組。
? ? ? ? terrainProviderViewModels: this.getTerrainProviderViewModelsArr(),
? ? ? });
? ? ? this.viewer._cesiumWidget._creditContainer.style.display = "none"; // 隱藏版權(quán)
? ? },
? ? getImageryProviderArr() {
? ? ? const Cesium = this.cesium;
? ? ? return [
? ? ? ? new Cesium.ProviderViewModel({
? ? ? ? ? //圖層的名稱。
? ? ? ? ? name: "影像底圖",
? ? ? ? ? //顯示項目被隱藏的工具提示
? ? ? ? ? tooltip: "影像底圖",
? ? ? ? ? //代表圖層的圖標(biāo)
? ? ? ? ? iconUrl: require("@/assets/img/yxdt.png"),
? ? ? ? ? //一個函數(shù)或命令,用于創(chuàng)建一個或多個提供程序,這些提供程序?qū)⒃谶x擇此項目時添加到地球儀中。
? ? ? ? ? creationFunction: function () {
? ? ? ? ? ? return new Cesium.ArcGisMapServerImageryProvider({
? ? ? ? ? ? ? url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
? ? ? ? ? ? });
? ? ? ? ? },
? ? ? ? }),
? ? ? ? new Cesium.ProviderViewModel({
? ? ? ? ? //圖層的名稱
? ? ? ? ? name: "電子地圖",
? ? ? ? ? //顯示項目被隱藏的工具提示
? ? ? ? ? tooltip: "電子地圖",
? ? ? ? ? //代表圖層的圖標(biāo)
? ? ? ? ? iconUrl: require("@/assets/img/sldt.png"),
? ? ? ? ? //一個函數(shù)或命令,用于創(chuàng)建一個或多個提供程序,這些提供程序?qū)⒃谶x擇此項目時添加到地球儀中
? ? ? ? ? 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: "無地形",
? ? ? ? ? //顯示項目被隱藏的工具提示
? ? ? ? ? tooltip: "WGS84標(biāo)準(zhǔn)球體",
? ? ? ? ? //代表圖層的圖標(biāo)
? ? ? ? ? iconUrl: require("@/assets/img/WGS84.png"),
? ? ? ? ? //一個函數(shù)或命令,用于創(chuàng)建一個或多個提供程序,這些提供程序?qū)⒃谶x擇此項目時添加到地球儀中
? ? ? ? ? creationFunction: function () {
? ? ? ? ? ? return new Cesium.EllipsoidTerrainProvider({
? ? ? ? ? ? ? ellipsoid: Cesium.Ellipsoid.WGS84,
? ? ? ? ? ? });
? ? ? ? ? },
? ? ? ? }),
? ? ? ? new Cesium.ProviderViewModel({
? ? ? ? ? //圖層的名稱
? ? ? ? ? name: "地形",
? ? ? ? ? //顯示項目被隱藏的工具提示
? ? ? ? ? tooltip: "STK在線地形",
? ? ? ? ? //代表圖層的圖標(biāo)
? ? ? ? ? iconUrl: require("@/assets/img/STK在線地形.png"),
? ? ? ? ? //一個函數(shù)或命令,用于創(chuàng)建一個或多個提供程序,這些提供程序?qū)⒃谶x擇此項目時添加到地球儀中
? ? ? ? ? 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ù),不寫會報錯;
? ? ? ? // layers寫的不對會報如下錯誤: 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);
? ? // 飛入動畫
? ? this.viewer.flyTo(this.wmsLayer, {
? ? ? ? duration: 2
? ? });
? } else {
? ? this.$message.warning('該地圖服務(wù)沒有坐標(biāo)可以定位')
? }

加載WMTS服務(wù)

對與url 屬性: 很多博客都說要進行 如下拼接:

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

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

// 加載geoserver wmts服務(wù)
addWMTS(fileUrl) {
? ? ? const Cesium = this.cesium;
? ? ? let provider = new Cesium.WebMapTileServiceImageryProvider({
? ? ? ? // ?對與url ?很多博客都說要進行 如下拼接
? ? ? ? // 后端返回的wmts/rest/{layer}/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}?format=image/png
?? ??? ?// 其實不用拼接 ?只需要后端返回的/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),
? ? ? ? // 必須加 ?不然地圖出不來
?? ??? ?//之所以要在這里提出這個tileMatrixLabels參數(shù),是因為GeoServer在緩沖切分瓦片時對每一個縮放級別的存儲目錄沒有使用相應(yīng)的數(shù)字,而使用了網(wǎng)格+級別的方式來命名,如“EPSG:9100913:10”表示的是使用“EPSG:9100913”網(wǎng)格切分的第10級瓦片。
? ? ? ? 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)重缺陷:在面對大場景問題,即數(shù)據(jù)量較大時,非常容易卡死、崩潰

方法二

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

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

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

推薦方法:方法二。

總結(jié)

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

相關(guān)文章

  • 基于vue.js快速搭建圖書管理平臺

    基于vue.js快速搭建圖書管理平臺

    Vue.js是當(dāng)下很火的一個JavaScript MVVM(Model-View-ViewModel)庫.這篇文章主要介紹了基于vue.js快速搭建圖書管理平臺 ,需要的朋友可以參考下
    2017-10-10
  • Vue 組件(component)教程之實現(xiàn)精美的日歷方法示例

    Vue 組件(component)教程之實現(xiàn)精美的日歷方法示例

    組件是我們學(xué)習(xí)vue必須會的一部分,下面這篇文章主要給大家介紹了關(guān)于Vue 組件(component)教程之實現(xiàn)精美的日歷的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • Vue使用font-face自定義字體的案例詳解

    Vue使用font-face自定義字體的案例詳解

    @font-face?是?CSS?中的一個規(guī)則,它允許你加載服務(wù)器上的字體文件(遠程或者本地),并在網(wǎng)頁中使用這些字體,本文給大家介紹了Vue使用font-face自定義字體的案例,并通過代碼講解的非常詳細,需要的朋友可以參考下
    2024-03-03
  • vue里的data要用return返回的原因淺析

    vue里的data要用return返回的原因淺析

    這篇文章主要介紹了vue里的data要用return返回的原因淺析,需要的朋友可以參考下
    2019-05-05
  • vite構(gòu)建項目并支持微前端

    vite構(gòu)建項目并支持微前端

    本文主要介紹了vite構(gòu)建項目并支持微前端,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Vue 獲取數(shù)組鍵名的方法

    Vue 獲取數(shù)組鍵名的方法

    本篇文章主要介紹了Vue 獲取數(shù)組鍵名的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • vue package.json文件的使用及說明

    vue package.json文件的使用及說明

    `package.json`是Node.js和npm項目的核心配置文件,定義了項目的元數(shù)據(jù)和依賴項,在Vue項目中,它管理依賴、提供腳本命令、存儲項目信息,并通過語義化版本控制確保項目穩(wěn)定
    2025-01-01
  • vue3無config文件夾打包后頁面空白問題及解決

    vue3無config文件夾打包后頁面空白問題及解決

    這篇文章主要介紹了vue3無config文件夾打包后頁面空白問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • VUE寫一個簡單的表格實例

    VUE寫一個簡單的表格實例

    在本篇文章里小編給大家整理的是關(guān)于VUE中表格的寫法實例以及相關(guān)知識點內(nèi)容,需要的朋友們可以參考下。
    2019-08-08
  • vue.js實現(xiàn)日歷插件使用方法詳解

    vue.js實現(xiàn)日歷插件使用方法詳解

    這篇文章主要為大家詳細介紹了vue.js模擬日歷插件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09

最新評論