初始化
package.json
json
"vite-plugin-cesium": "^1.2.23",
"cesium": "^1.120.0"
vite.config.js
js
import cesium from "vite-plugin-cesium";
...
plugins: [
...
cesium(),
],
app.vue
vue
<template>
<div id="cesiumContainer"></div>
</template>
<script setup>
import * as Cesium from "cesium";
onMounted(() => {
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(90, -20, 110, 90);
const terrain = Cesium.Terrain.fromWorldTerrain({
requestWaterMask: true,
requestVertexNormals: true,
});
viewer = new Cesium.Viewer("cesiumContainer", {
geocoder: false, //是否显示地名查找工具
homeButton: false, //是否显示首页位置工具
sceneModePicker: false, //是否显示视角模式切换工具
baseLayerPicker: false, //是否显示默认图层选择工具
navigationHelpButton: false, //是否显示导航帮助工具
animation: false, //是否显示动画工具
timeline: false, //是否显示时间轴工具
fullscreenButton: false, //是否显示全屏按钮工具
infoBox: false,
selectionIndicator: false,
shadows: true,
shouldAnimate: true,
terrainProvider: await Cesium.createWorldTerrainAsync(),
});
// 去掉logo
viewer.cesiumWidget.creditContainer.style.display = "none";
});
</script>