008:cesium中 viewer.scene.globe知识详解,示例代码

在这里插入图片描述

查看本专栏目录 - 本文是第 007个API内容详解

vue+cesium 示例教程200+目录


在 Cesium 中,viewer.scene.globe 是一个非常重要的属性,用于表示地球的球体模型。它提供了对地形、光照、阴影以及纹理贴图等功能的访问和控制。通过操作 viewer.scene.globe,你可以实现许多与地球相关的功能,例如加载自定义地形、启用光照效果、调整材质等。

以下是关于 viewer.scene.globe 的详细介绍,包括其常用属性、方法以及使用示例。


1. 基本概念

view

Uncaught (in promise) SyntaxError: Unexpected token '<', "<!doctype "... is not valid JSON at JSON.parse (<anonymous>) at Resource.js:1180:17 localhost/:1 Uncaught (in promise) SyntaxError: Unexpected token '<', "<!doctype "... is not valid JSON at JSON.parse (<anonymous>) at Resource.js:1180:17 CesiumWidget.js:962 An error occurred while rendering. Rendering has stopped. InvalidStateError: The source image could not be decoded. InvalidStateError: The source image could not be decoded. CesiumWidget.showErrorPanel @ CesiumWidget.js:962 localhost/:1 Uncaught (in promise) Event 如上所示报错修改下面代码:<template> <div id="cesium-container" ref="cesiumContainer"></div> </template> <script setup lang="ts"> import { ref, onMounted, onUnmounted } from 'vue'; import * as Cesium from 'cesium'; import 'cesium/Build/Cesium/Widgets/widgets.css'; // 使用你自己的有效 Cesium 访问令牌 Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0ZTdiZDBhZS0xNzBhLTRjZGUtOTY4NC1kYzA5ZDEyNGEyNjUiLCJpZCI6MzE2OTI5LCJpYXQiOjE3NTEzMzg2Mzh9.9QHGIwaWkUOX0NOSre5369rrf1k6bGhZu7xUQia4JmE'; const cesiumContainer = ref<HTMLDivElement | null>(null); let viewer: Cesium.Viewer | null = null; onMounted(async () => { // 改为异步函数 if (!cesiumContainer.value) return; try { // 异步创建世界地形 - 最新版 Cesium 的用法 const worldTerrain = await Cesium.createWorldTerrainAsync({ requestVertexNormals: true, requestWaterMask: true }); // 初始化Cesium地球 viewer = new Cesium.Viewer(cesiumContainer.value, { animation: false, baseLayerPicker: false, fullscreenButton: false, vrButton: false, geocoder: false, homeButton: false, infoBox: false, sceneModePicker: false, selectionIndicator: false, timeline: false, navigationHelpButton: false, navigationInstructionsInitiallyVisible: false, terrainProvider: worldTerrain, // 使用异步创建的地形 imageryProvider: new Cesium.ArcGisMapServerImageryProvider({ url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer' }) }); // 设置初始视图位置(株洲市) viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(113.13, 27.83, 10000000), orientation: { heading: Cesium.Math.toRadians(0), pitch: Cesium.Math.toRadians(-90), roll: 0.0 }, duration: 2 }); // 添加水面效果 addWaterEffect(); // 添加光照效果 addLightingEffect(); } catch (error) { console.error('Failed to initialize Cesium:', error); } }); onUnmounted(() => { if (viewer) { viewer.destroy(); viewer = null; } }); // 添加水面效果 function addWaterEffect() { if (viewer) { viewer.scene.globe.enableLighting = true; viewer.scene.globe.dynamicAtmosphereLighting = true; viewer.scene.globe.dynamicAtmosphereLightingFromSun = true; } } // 添加光照效果 function addLightingEffect() { if (viewer) { viewer.scene.globe.showGroundAtmosphere = true; viewer.scene.fog.enabled = true; viewer.scene.skyAtmosphere.show = true; } } </script> <style scoped> #cesium-container { position: absolute; top: 0; left: 0; height: 100%; width: 100%; margin: 0; padding: 0; overflow: hidden; } /* 覆盖Cesium默认的logo */ :deep(.cesium-viewer-bottom) { display: none !important; } </style>
最新发布
07-10
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

还是大剑师兰特

打赏一杯可口可乐

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值