Cesium 加载czml时序数据
示例代码
vue
<script setup lang="ts">
import * as Cesium from 'cesium'
import "../styles/Widgets/widgets.css"
import { onMounted } from 'vue';
onMounted(async () => {
// https://cesium.com/learn/cesiumjs/ref-doc/Viewer.html#.ConstructorOptions
const viewer = new Cesium.Viewer('cesiumContainer', {
// 隐藏 logo
creditContainer: document.createElement('div'),
// 隐藏右上角的帮助按钮
navigationHelpButton: false,
// 去除第一次加载后控制台报错
infoBox: false,
// 右上角搜索框
geocoder: false,
// // 底部时间线
// timeline: false,
// // 左下角动画控件
// animation: false,
// 右上角主页按钮
homeButton: false,
// 右上角显示模式
sceneModePicker: false,
// 右上角投影切换按钮
baseLayerPicker: false,
// 加载后就运动
shouldAnimate: true,
})
// 加载kml数据
const czml = [
{
id: "document",
name: "CZML Point - Time Dynamic",
version: "1.0",
},
{
id: "point",
// 物体在什么时间范围可用
availability: "2012-08-04T16:00:00Z/2012-08-04T16:05:00Z",
position: {
// 设置物体的起始时间
epoch: "2012-08-04T16:00:00Z",
// 设置了四个维度,1维是时间,2维是经度,3维是纬度,4维是高度
cartographicDegrees: [
0, // 0秒钟
89.5, // 经度
20, // 纬度
150000, // 高度
100, 120, 44, 150000, 200, 210, 18, 150000, 300,
300, 52, 150000,
],
},
point: {
color: {
rgba: [255, 255, 255, 128],
},
outlineColor: {
rgba: [255, 0, 0, 128],
},
outlineWidth: 3,
pixelSize: 15,
},
},
];
// 加载czml数据
let promiseData = Cesium.CzmlDataSource.load(czml);
promiseData.then((dataSource) => {
console.log(dataSource);
viewer.dataSources.add(dataSource);
// viewer.flyTo(dataSource);
});
})
</script>
<template>
<div id="cesiumContainer" ref="cesiumContainer" />
</template>
<style scoped>
#cesiumContainer {
height: 100%;
width: 100%;
}
</style>