vue+Cesium示例中缺少要素以至于运行不起来

示例:

网址:

https://cesium.com/learn/cesiumjs-learn/cesiumjs-creating-entities/

缺少:

正确的代码:

复制代码
<template>
  <div id="cesiumContainer" ref="cesiumContainer"></div>
</template>

<script setup>

import * as Cesium from 'cesium'
import '../Widgets/widgets.css' //这是src下面的widgets.css文件
import { onMounted } from 'vue'

Cesium.Ion.defaultAccessToken = "*****";
window.CESIUM_BASE_URL = '/'  //这是根目录下的四个文件夹

/* eslint-disable no-unused-vars */

onMounted(() => {

const viewer = new Cesium.Viewer("cesiumContainer");

viewer.entities.add({
  name: "Blue box",
  position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0),
  box: {
    dimensions: new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
    material: Cesium.Color.BLUE,
  },
});

viewer.entities.add({
  name: "Red box with black outline",
  position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
  box: {
    dimensions: new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
    material: Cesium.Color.RED.withAlpha(0.5),
    outline: true,
    outlineColor: Cesium.Color.BLACK,
  },
});

 viewer.entities.add({
  name: "Yellow box outline",
  position: Cesium.Cartesian3.fromDegrees(-100.0, 40.0, 300000.0),
  box: {
    dimensions: new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
    fill: false,
    outline: true,
    outlineColor: Cesium.Color.YELLOW,
  },
});

viewer.zoomTo(viewer.entities);

})


</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
* {
  margin: 0;
  padding: 0
}

#cesiumContainer {
  width: 100%;
  height: 100vh;
}
</style>

展示:

相关推荐
小酒丸子1 小时前
AD学习笔记之异形焊盘
笔记·学习
似水明俊德5 小时前
01-C#.Net-泛型-学习笔记
java·笔记·学习·c#·.net
今儿敲了吗5 小时前
python基础学习笔记第三章
笔记·python·学习
91刘仁德6 小时前
C++ 内存管理
android·c语言·数据结构·c++·经验分享·笔记·算法
T700_6757 小时前
iPhone 16 Pro 语音笔记全攻略:高效捕捉灵感,智能记录生活
笔记·生活·iphone
试试勇气7 小时前
Linux学习笔记(十七)--线程概念
linux·笔记·学习
·醉挽清风·8 小时前
学习笔记—Linux—文件系统
linux·笔记·学习
AI视觉网奇8 小时前
动作迁移算法笔记 2026
人工智能·笔记
handler019 小时前
基础算法:分治
c语言·开发语言·c++·笔记·学习·算法·深度优先
不想看见4049 小时前
Implement Queue using Stacks栈和队列--力扣101算法题解笔记
笔记·算法·leetcode