Cesium在vue3中的简单使用

目录

一、介绍

二、创建和基础配置

2.1 使用vite创建vue3项目

 2.2 安装所需依赖

2.3 修改配置文件vite.config.js

 2.4 配置路由文件

2.5 使用路由文件

三、使用cesium原本的进行渲染

3.1 渲染效果

3.2 代码实现

 3.2.1 默认效果代码

3.2.2 空白地图效果代码

 3.2.3 修改默认视角代码

3.2.4 解决控制台报错

四、使用天地图进行渲染

4.1 渲染效果

4.2 代码实现

 4.2.1 天地图矢量底图效果代码

 4.2.2 天地图矢量底图叠加矢量注记效果代码

4.2.3 天地图影像底图效果代码

4.2.4 天地图影像底图叠加影像注记效果代码

五、使用OSM地图进行渲染

5.1 渲染效果

5.2 代码实现

5.2.1 HOT瓦片效果代码

5.2.2 标准 OpenStreetMap 瓦片效果代码

六、使用高德地图进行渲染

6.1 渲染效果

6.2 代码实现

6.2.1 矢量底图效果代码

6.2.2 影像底图叠加影像注记效果代码


一、介绍

CesiumJS 是一个开源 JavaScript 库,用于创建具有最佳性能、精度、视觉质量和易用性的世界级 3D 地球仪和地图。从航空航天到智慧城市再到无人机,各行各业的开发人员都使用 CesiumJS 创建交互式 Web 应用程序来共享动态地理空间数据。

CesiumJS 基于开放格式构建,旨在为海量数据集提供强大的互操作性和扩展能力。

  • 从 Cesium ion 或其他来源以 3D 平铺和其他标准格式流式传输
  • 在高精度 WGS84 地球上进行可视化和分析
  • 与桌面或移动设备上的用户共享

✨ 相关网址:

官网文档:Cesium: The Platform for 3D Geospatial

中文文档:Cesium中文api文档 | Index - Cesium Documentation

✨ 官网上提供的一些示例:

Hello World - Cesium Sandcastleicon-default.png?t=O83Ahttps://sandcastle.cesium.com/

二、创建和基础配置

在vue3中进行渲染的时候需要使用cesium中提供的Token,所以使用之前需要先自行注册。

获取地址:Access Tokens | Cesium ionicon-default.png?t=O83Ahttps://ion.cesium.com/tokens?page=1

2.1 使用vite创建vue3项目

yarn create vite cesium-basic --template vue

 2.2 安装所需依赖

# 先进入到项目的根目录,然后再进行相关依赖的安装
cd cesium-basicyarnyarn add sass vue-router -Dyarn add cesium vite-plugin-cesium -D

2.3 修改配置文件vite.config.js

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// 导入cesium插件
import cesium from 'vite-plugin-cesium'// https://vite.dev/config/
export default defineConfig({plugins: [vue(), cesium()],// 配置路径别名resolve: {alias: {'@': '/src'}}
})

 2.4 配置路由文件

在src文件夹下创建router文件夹,在其下创建index.js路由配置文件,配置内容如下:

// 引入需要的模块
import { createRouter, createWebHistory } from 'vue-router'// 下面使用了es6的对象增强写法,命名必须是routes
const routes = [{path: '/',component: () => import('@/pages/Cesium/index.vue'),},{path: '/tianditu/vector',component: () => import('@/pages/Tianditu/Vector.vue'),},{path: '/tianditu/screenage',component: () => import('@/pages/Tianditu/Screenage.vue'),},{path: '/google',component: () => import('@/pages/Google/index.vue'),},{path: '/osm',component: () => import('@/pages/OSM/index.vue'),}
]// 创建路由
const router = createRouter({history: createWebHistory(),routes
})// 导出路由
export default router

2.5 使用路由文件

 在入口文件main.js中引入路由文件并使用:

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'createApp(App).use(router).mount('#app')

三、使用cesium原本的进行渲染

3.1 渲染效果

默认效果,默认视角为北美洲
让页面只显示一个地球,其余的都去掉
设置默认视角为中国

3.2 代码实现

 3.2.1 默认效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'onMounted(() => {Cesium.Ion.defaultAccessToken = "替换为你的token"// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer')})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}
</style>

3.2.2 空白地图效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'onMounted(() => {Cesium.Ion.defaultAccessToken = "替换为你的token"// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

 3.2.3 修改默认视角代码

  // 设置cesium默认视角,设置到中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)

3.2.4 解决控制台报错

  const viewer = new Cesium.Viewer('cesiumContainer',{/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})

四、使用天地图进行渲染

天地图官网:国家地理信息公共服务平台 天地图 (tianditu.gov.cn)

使用天地图的话需要先申请成为开发者,然后创建应用得到应用的key,因为后续的代码需要用到这个key。

4.1 渲染效果

使用天地图的矢量底图
使用天地图的矢量底图叠加适量注记

使用天地图的影像底图

使用天地图的影像底图叠加影像注记

4.2 代码实现

Cesium中WebMapTileServiceImageryProvider配置项的说明:

属性类型默认值描述
urlResource | String

WMTS GetTile操作的基本URL(用于KVP编码的请求)或tile-URL模板(用于RESTful请求)。tile-URL模板应包含以下变量:{style},{TileMatrixSet},{TileMatrix},{TileRow},{TileCol}。如果实际值是硬编码的,或者服务器不想需要,则前两个是可选的。{s}关键字可用于指定子域。

layerStringWMTS请求层名称
styleStringWMTS请求的样式名称
formatString‘image/jpeg’【可选】从服务器检索图像的MIME类型

tileMatrixSetID

String用于WMTS请求的TileMatrixSet的标识符
showBooleantrue控制图层在初始化时隐藏

更多属性可参考:Resource - Cesium Documentation

 4.2.1 天地图矢量底图效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'// 天地图的应用key
const webKey = "修改为自己的key"onMounted(() => {// 设置Cesium的Token// https://ion.cesium.com/tokens?page=1Cesium.Ion.defaultAccessToken = "修改为自己的token"// 设置cesium默认视角,设置到中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{terrain: Cesium.Terrain.fromWorldTerrain(),//用于启用全球地形数据/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})// 矢量底图viewer.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({// url: "http://t0.tianditu.com/vec_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=vec&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=" + webKey,url: "http://t0.tianditu.gov.cn/vec_w/wmts?tk=" + webKey,layer: "tdtVecBasicLayer",style: "default",format: "image/jpeg",tileMatrixSetID: "GoogleMapsCompatible",show: false}));
})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

 4.2.2 天地图矢量底图叠加矢量注记效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'// 天地图的应用key
const webKey = "修改为自己的key"onMounted(() => {// 设置Cesium的Token// https://ion.cesium.com/tokens?page=1Cesium.Ion.defaultAccessToken = "修改为自己的token"// 设置cesium默认视角,设置到中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{terrain: Cesium.Terrain.fromWorldTerrain(),//用于启用全球地形数据/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})// 矢量底图viewer.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({// url: "http://t0.tianditu.com/vec_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=vec&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=" + webKey,url: "http://t0.tianditu.gov.cn/vec_w/wmts?tk=" + webKey,layer: "tdtVecBasicLayer",style: "default",format: "image/jpeg",tileMatrixSetID: "GoogleMapsCompatible",show: false}));//矢量注记viewer.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({url: "http://t0.tianditu.com/cva_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cva&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default.jpg&tk=" + webKey,// url: "http://t0.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=image%2Fjpeg&TILEMATRIX={TileMatrix}&TILEROW={TileRow}&TILECOL={TileCol}&tk=" + webKey,layer: "tdtAnnoLayer",style: "default",format: "image/jpeg",tileMatrixSetID: "GoogleMapsCompatible"}));
})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

4.2.3 天地图影像底图效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'// 天地图的应用key
const webKey = "修改为自己的key"onMounted(() => {// 设置Cesium的Token// https://ion.cesium.com/tokens?page=1Cesium.Ion.defaultAccessToken = "修改为自己的token"// 设置cesium默认视角,设置到中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{terrain: Cesium.Terrain.fromWorldTerrain(),//用于启用全球地形数据/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})//影像底图viewer.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({// url: "http://t0.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=" + webKey,url: "http://t0.tianditu.gov.cn/img_w/wmts" + webKey,layer: "tdtBasicLayer",style: "default",format: "image/jpeg",tileMatrixSetID: "GoogleMapsCompatible",show: false}));})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

4.2.4 天地图影像底图叠加影像注记效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'// 天地图的应用key
const webKey = "修改为自己的key"onMounted(() => {// 设置Cesium的Token// https://ion.cesium.com/tokens?page=1Cesium.Ion.defaultAccessToken = "修改为自己的token"// 设置cesium默认视角,设置到中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{terrain: Cesium.Terrain.fromWorldTerrain(),//用于启用全球地形数据/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})//影像底图viewer.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({// url: "http://t0.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=" + webKey,url: "http://t0.tianditu.gov.cn/img_w/wmts" + webKey,layer: "tdtBasicLayer",style: "default",format: "image/jpeg",tileMatrixSetID: "GoogleMapsCompatible",show: false}));
//影像注记viewer.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({//  url: "http://t0.tianditu.com/cia_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cia&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default.jpg&tk=" + webKey,url: "http://t0.tianditu.gov.cn/cia_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cia&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default.jpg&tk=" + webKey,layer: "tdtAnnoLayer",style: "default",format: "image/jpeg",tileMatrixSetID: "GoogleMapsCompatible",show: false}));})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

五、使用OSM地图进行渲染

5.1 渲染效果

Humanitarian OpenStreetMap Team (HOT) 瓦片
标准 OpenStreetMap 瓦片

5.2 代码实现

5.2.1 HOT瓦片效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'onMounted(() => {// 设置Cesium的Token// https://ion.cesium.com/tokens?page=1Cesium.Ion.defaultAccessToken = "替换成自己的token"// 设置cesium默认视角,设置到中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{terrain: Cesium.Terrain.fromWorldTerrain(),//用于启用全球地形数据/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})// OSM地图viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({url: 'https://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png',subdomains: ["a", "b", "c", "d"],}));
})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

5.2.2 标准 OpenStreetMap 瓦片效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'onMounted(() => {// 设置Cesium的Token// https://ion.cesium.com/tokens?page=1Cesium.Ion.defaultAccessToken = "修改为自己的token"// 设置cesium默认视角,设置到中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{terrain: Cesium.Terrain.fromWorldTerrain(),//用于启用全球地形数据/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})// OSM地图viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",subdomains: ["a", "b", "c", "d"],}));
})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

六、使用高德地图进行渲染

6.1 渲染效果

高德矢量地图
高德影像底图+影像注记

6.2 代码实现

6.2.1 矢量底图效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'onMounted(() => {// 设置Cesium的Token// https://ion.cesium.com/tokens?page=1Cesium.Ion.defaultAccessToken = "替换成自己的token"// 设置cesium默认视角,设置到中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{terrain: Cesium.Terrain.fromWorldTerrain(),//用于启用全球地形数据/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})// 高德矢量地图viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({url: "https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",subdomains: ["1", "2", "3", "4"],}))
})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

6.2.2 影像底图叠加影像注记效果代码

<template><div id="cesiumContainer"></div>
</template><script setup>
// 导入cesium
import { onMounted } from 'vue'
import * as Cesium from 'cesium'onMounted(() => {// 设置Cesium的Token// https://ion.cesium.com/tokens?page=1Cesium.Ion.defaultAccessToken = "设置为自己的token"// 设置cesium默认视角,设置到济南Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(89.5,// 西边经度20.0,// 南边纬度110.4,// 东边经度61.2 // 北边纬度)// 初始化cesiumconst viewer = new Cesium.Viewer('cesiumContainer',{terrain: Cesium.Terrain.fromWorldTerrain(),//用于启用全球地形数据/* 由于信息框是使用iframe实现的控制台会一直报错,关闭之后即可解决该报错Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow - scripts' permission is not set.*/infoBox: false,// 是否显示信息提示窗口geocoder: false,// 是否显示搜索框homeButton: false,// 是否显示home键fullscreenButton: false, // 是否显示全屏按钮animation: false,// 动画控件sceneModePicker: false,// 场景模式选择器,就是控制二三维的那个timeline: false,// 时间轴navigationHelpButton: false,// 导航帮助提示按钮baseLayerPicker: false,// 地图选择器})// 高德影像底图viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({url: "https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",subdomains: ["1", "2", "3", "4"],}))// 高德影像注记viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({url: "https://webst0{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}",subdomains: ["1", "2", "3", "4"],}))
})
</script><style lang="scss" scoped>
#cesiumContainer {width: 100%;height: 100vh;
}/* 隐藏底部logo部分 */
::v-deep(.cesium-widget-credits) {display: none !important;
}
</style>

文章中如有不足之处,还望各位大佬们批评指正!!!

如有更好的实现方式,欢迎评论分享!!!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/892819.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Uniapp-Vue3】使用defineExpose暴露子组件的属性及方法

如果我们想要让父组件访问到子组件中的变量和方法&#xff0c;就需要使用defineExpose暴露&#xff1a; defineExpose({ 变量 }) 子组件配置 父组件配置 父组件要通过onMounted获取到子组件的DOM 传递多个属性和方法 子组件 父组件

三小时深度学习PyTorch

【对新手非常友好】三小时深度学习PyTorch快速入门&#xff01;包教会你的&#xff01; --人工智能/深度学习/pytorch_哔哩哔哩_bilibili从头开始&#xff0c;把概率论、统计、信息论中零散的知识统一起来_哔哩哔哩_bilibili从编解码和词嵌入开始&#xff0c;一步一步理解Trans…

小米vela系统(基于开源nuttx内核)——openvela开源项目

前言 在 2024 年 12 月 27 日的小米「人车家全生态」合作伙伴大会上&#xff0c;小米宣布全面开源 Vela 操作系统。同时&#xff0c;OpenVela 项目正式上线 GitHub 和 Gitee&#xff0c;采用的是比较宽松的 Apache 2.0 协议&#xff0c;这意味着全球的开发者都可以参与到 Vela…

linux系统监视(centos 7)

一.系统监视 1.安装iostat&#xff0c;sar&#xff0c;sysstat&#xff08;默认没有&#xff0c;安装过可以跳跃&#xff09; iostat 和 sar&#xff1a; 同样&#xff0c;iostat 和 sar 是 sysstat 软件包的一部分。使用以下命令安装&#xff1a;sudo yum install sysstat解释…

C#与Vue2上传下载Excel文件

1、上传文件流程&#xff1a;先上传文件&#xff0c;上传成功&#xff0c;返回文件名与url&#xff0c;然后再次发起请求保存文件名和url到数据库 前端Vue2代码&#xff1a; 使用element的el-upload组件&#xff0c;action值为后端接收文件接口&#xff0c;headers携带session信…

1.15寒假作业

web&#xff1a;nss靶场ez_ez_php 打开环境&#xff0c;理解代码 使用个体传参的方法&#xff0c;首先代码会检查file参数的前三个字符是不是php&#xff0c;如果是就输出nice&#xff0c;然后用include函数包含file&#xff0c;绕过不是则输出hacker&#xff0c;如果没有file…

正则表达式先入门,精不精通看修行

1.元字符 元字符是构造正则表达式的一种基本元素&#xff0c;可以匹配一个或多个字符&#xff0c;或者根据特定的规则进行匹配。 元字符 说明 .匹配除换行符以外的任意字符\w匹配字母或数字或下划线或汉字\s匹配任意的空白符\d匹配数字\b匹配单词的开始或结束^匹配字符串的开…

AWS设计和实现无人机图形显示和控制系统

设计 无人机图形显示和控制系统 涉及多个组件&#xff0c;这些组件组合在一起以确保实时监控和精确控制。 要使用 AWS 实施 无人机图形显示和控制系统&#xff0c;您需要通过云基础设施将实时视频流、遥测监控和远程控制相结合。AWS 提供了 IoT Core、Kinesis 和 Lambda 等强大…

openharmony display

https://github.com/openharmony/drivers_peripheral/blob/master/display/README_zh.md 源码路径&#xff0c;这里是对rk3588的display层适配 device/soc/rockchip/rk3588/hardware/display ├── include └── src ├── display_device &#xff08;代码量最大的部分&…

如何在linux系统上完成定时任务

任务背景 1.需要每小时更新一次github的host端口&#xff1b; 2.需要每天早上七点半准时启动电脑。 更新github的host端口 在/past/to/路径里新建一个host_update.sh文件&#xff0c;运行以下命令获得访问&#xff0c;运行和修改这个文件路径的权限&#xff1a; sudo chmod…

react中hooks之useRef 用法总结

1. 基本概念 useRef 是 React 的一个 Hook&#xff0c;返回一个可变的 ref 对象&#xff0c;其 .current 属性被初始化为传入的参数。这个对象在组件的整个生命周期内保持不变。 2. 主要用途和特性 2.1 获取 DOM 元素实例 function TextInputWithFocusButton() {const inpu…

用Guiguider生成的字体代替LVGL默认字体

Guiguider版本&#xff1a;1.8.1 LVGL版本&#xff1a;8.3 最近使用LVGL时&#xff0c;由于flash不太够用了&#xff0c;观察编译的map图发现一直有一个LV_FONT_MONTSERRAT_14的字体被编译&#xff0c;占用了我十几KB的Flash&#xff0c;由于我是用guider生成的界面和字体&…

osg中实现模型的大小、颜色、透明度的动态变化

以博饼状模型为对象,实现了模型大小、颜色、透明度的动态变化。 需要注意的是一点: // 创建材质对象osg::ref_ptr<osg::Material> material = new osg::Material;material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0, 1.0, 0.0, 0.5));// 获取模型的…

golang之数据库操作

1.导入必要的包 import("database/sql"_ "github.com/go-sql-driver/mysql" //使用此作为数据库驱动 ) 2.相关操作 连接数据库 使用sql.Open()函数进行数据库的连接 db, err : sql.Open("mysql", "user:passwordtcp(127.0.0.1:3306)/db…

// Error: line 1: XGen: Candidate guides have not been associated!

Maya xgen 报错// Error: line 1: XGen: Candidate guides have not been associated! 复制下面粘贴到Maya脚本管理器python运行&#xff1a; import maya.cmds as cmds def connect_xgen_guides():guide_nodes cmds.ls(typexgmMakeGuide)for node in guide_nodes:downstream…

为ARM64架构移植Ubuntu20.04换源的发现

在为ARM64架构(RK3566)移植ubuntu20.04的时候发现在更换为国内源之后&#xff0c;无法正常完成apt update,报错为: Ign:25 http://mirrors.aliyun.com/ubuntu focal-updates/main arm64 Packages …

源码编译安装httpd 2.4,提供系统服务管理脚本并测试

总结需要安装的包 sudo yum groupinstall "Development Tools" -y #httpd的依赖包yum install tar -y #tar压缩包sudo yum install apr-devel apr-util-devel #APR库 提供跨平台接口的库sudo yum install pcre pcre-devel # PCRE库和 pcre-config工具--提供PCRE库…

【混合开发】CefSharp+Vue桌面应用程序开发

为什么选择CefSharpVue做桌面应用程序 CefSharp 基于 Chromium Embedded Framework (CEF) &#xff0c;它可以将 Chromium 浏览器的功能嵌入到 .NET 应用程序中。通过 CefSharp&#xff0c;开发者可以在桌面应用程序中集成 Web 技术&#xff0c;包括 HTML、JavaScript、CSS 等…

Zookeeper 核心知识深度解析:从选主到部署

1.请简述Zookeeper的选主流程 Zookeeper 是一个用于维护配置信息、命名、提供分布式同步和组服务的工具。它在分布式系统中提供了强一致性&#xff0c;这得益于它的内部实现机制&#xff0c;其中包括选主流程&#xff08;Leader Election&#xff09;。以下是 Zookeeper 的选主…

从0开始学习搭网站第二天

前言&#xff1a;今天比较惭愧&#xff0c;中午打铲吃了一把&#xff0c;看着也到钻二了&#xff0c;干脆顺手把这个赛季的大师上了&#xff0c;于是乎一直到网上才开始工作&#xff0c;同样&#xff0c;今天的学习内容大多来自mdn社区mdn 目录 怎么把文件上传到web服务器采用S…