Commit 70b4fa84 by jlc

update:地球坐标系案例代码结构的修改

parent 0b630c3d
export function addearthCoordinate() {
const script = document.createElement('script');
script.src = 'https://cesium.com/downloads/cesiumjs/releases/1.99/Build/Cesium/Cesium.js';
script.onload = () => {
window.Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3Njg4ZWU5Yi1iZDhiLTRhYmUtOTRiYS04YjM5NmUwNjVmMDMiLCJpZCI6MjI3MzQ3LCJpYXQiOjE3MjA1MjA4Mjh9.E5XW4LnwgfVAaBC-znaYr61m4yK0-j2qEQhi9qwFFPE'
export function addearthCoordinate(viewer) {
const scene = viewer.scene;
// 获取地球globe实例
const globe = scene.globe;
const baseLayer = viewer.scene.imageryLayers.get(0);
scene.screenSpaceCameraController.enableCollisionDetection = false;
function reset() {
globe.showGroundAtmosphere = true;
globe.baseColor = Cesium.Color.BLUE;
globe.translucency.enabled = false;
globe.translucency.frontFaceAlpha = 1.0;
globe.undergroundColor = Cesium.Color.BLACK;
globe.translucency.rectangle = undefined;
baseLayer.colorToAlpha = undefined;
}
function useTranslucencyMask() {
globe.showGroundAtmosphere = false;
globe.baseColor = Cesium.Color.TRANSPARENT;
globe.translucency.enabled = true;
globe.undergroundColor = undefined;
baseLayer.colorToAlpha = new Cesium.Color(0.0, 0.016, 0.059);
baseLayer.colorToAlphaThreshold = 0.2;
}
reset();
useTranslucencyMask();
const viewer = new window.Cesium.Viewer('cesiumContainer', {
infoBox: false,
orderIndependentTranslucency: false,
});
// 创建一个以地球球心为起点的坐标系
const center = new Cesium.Cartesian3(0, 0, 0); // 地球球心的坐标
const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
const scene = viewer.scene;
// 获取地球globe实例
const globe = scene.globe;
const baseLayer = viewer.scene.imageryLayers.get(0);
scene.screenSpaceCameraController.enableCollisionDetection = false;
function reset() {
globe.showGroundAtmosphere = true;
globe.baseColor = Cesium.Color.BLUE;
globe.translucency.enabled = false;
globe.translucency.frontFaceAlpha = 1.0;
globe.undergroundColor = Cesium.Color.BLACK;
globe.translucency.rectangle = undefined;
baseLayer.colorToAlpha = undefined;
}
function useTranslucencyMask() {
globe.showGroundAtmosphere = false;
globe.baseColor = Cesium.Color.TRANSPARENT;
globe.translucency.enabled = true;
globe.undergroundColor = undefined;
baseLayer.colorToAlpha = new Cesium.Color(0.0, 0.016, 0.059);
baseLayer.colorToAlphaThreshold = 0.2;
}
reset();
useTranslucencyMask();
// 创建一个以地球球心为起点的坐标系
const center = new Cesium.Cartesian3(0, 0, 0); // 地球球心的坐标
const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
// 添加坐标轴图元
viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
modelMatrix: modelMatrix,
length: 10000000, // 坐标轴的长度
width: 2.0 // 坐标轴的宽度
}));
};
document.head.appendChild(script);
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://cesium.com/downloads/cesiumjs/releases/1.119/Build/Cesium/Widgets/widgets.css';
document.head.appendChild(link);
// 添加坐标轴图元
viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
modelMatrix: modelMatrix,
length: 10000000, // 坐标轴的长度
width: 2.0 // 坐标轴的宽度
}));
}
<template>
<div id="cesiumContainer" class="cesium-container"></div>
</template>
<script setup>
import { onMounted } from 'vue';
import { addearthCoordinate } from './function';
let viewer;
onMounted(() => {
addearthCoordinate()
const script = document.createElement('script');
script.src = 'https://cesium.com/downloads/cesiumjs/releases/1.99/Build/Cesium/Cesium.js';
script.onload = () => {
window.Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3Njg4ZWU5Yi1iZDhiLTRhYmUtOTRiYS04YjM5NmUwNjVmMDMiLCJpZCI6MjI3MzQ3LCJpYXQiOjE3MjA1MjA4Mjh9.E5XW4LnwgfVAaBC-znaYr61m4yK0-j2qEQhi9qwFFPE'
viewer = new window.Cesium.Viewer('cesiumContainer', {
infoBox: false,
orderIndependentTranslucency: false,
});
addearthCoordinate(viewer)
};
document.head.appendChild(script);
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://cesium.com/downloads/cesiumjs/releases/1.119/Build/Cesium/Widgets/widgets.css';
document.head.appendChild(link);
});
</script>
<style>
.cesium-container {
width: 100%;
height: 100vh;
width: 100%;
height: 100vh;
}
</style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment