1、查看视角
const getInfo = (viewer) => {
let pos = viewer.camera.position;
let direction = viewer.camera.direction;
let up = viewer.camera.up;
let pitch = viewer.camera.pitch;
let roll = viewer.camera.roll;
let heading = viewer.camera.heading;
let obj =
{
"position": [pos.x, pos.y, pos.z],
"direction": [direction.x, direction.y, direction.z],
"up": [up.x, up.y, up.z],
"pitch": pitch,
"roll": roll,
"heading": heading
}
return JSON.stringify(obj)
}
getInfo(vieweryanshi)
2、切换到某个视角
vieweryanshi.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(130.78, 28.36, 19000000),
});
3、赋值cesium开始时间并且暂停
T_Viewer.clock.multiplier = 1;
T_Viewer.clock.currentTime = Cesium.JulianDate.fromIso8601(new Date(event.data.time).toISOString());
T_Viewer.clock.shouldAnimate = false;
4、查看所有实体
vieweryanshi.dataSources.get(0).entities.values
5、查看所有连线
vieweryanshi.entities.values
vieweryanshi.entities.getById("rightArea")
6、删除所有实体
entities.removeAll(true);
vieweryanshi.entities.removeAll(true);
7、添加区域
let leftPositionArray = ref([110.0, 30.0]);
vieweryanshi.entities.add({
id: 'leftArea',
polygon: {
show: true,
hierarchy: new Cesium.CallbackProperty(function () {
let arrPoint = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(leftPositionArray.value));
return arrPoint;
}, false),
material: Cesium.Color.CYAN.withAlpha(0.5),
fill: false,
perPositionHeight: true,
outline: true,
outlineColor: Cesium.Color.CYAN.withAlpha(0.5), // 边界线颜色
width: 5, // 边界线宽度
},
});
8、实时获取舰船实体经纬度
const setTabelDate = (arr) => {
return arr.map((item) => {
//QZJ6和 QZJ7信息不更新
if (item.id !== "Ship/QZJ6" && item.id !== "Ship/QZJ7") {
let entiy = entities.getById(item.id);
let position = entiy.position.getValue(vieweryanshi.clock.currentTime);
item.time = timeInfo.value;
let { longitude, latitude } = getLLH(position);
item.lon = longitude.toFixed(6);
item.lat = latitude.toFixed(6);
}
return item;
});
};
const getLLH = (position) => {
let llh = {
longitude: "",
latitude: "",
height: "",
};
let cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position); // 获取经度、纬度和高度
llh.longitude = Cesium.Math.toDegrees(cartographic.longitude);
llh.latitude = Cesium.Math.toDegrees(cartographic.latitude);
llh.height = cartographic.height; // console.log('经度: ' + llh.longitude); // console.log('纬度: ' + llh.latitude); // console.log('高度: ' + llh.height);
return llh;
};
9、判断演示时间是否在区间之内
/**
*
* @param {String} startTime 开始时间
* @param {String} endTime 结束时间
* @param {Boolean} flag 是否判断
*/
const isTimeRange = (startTime, endTime, flag = true) => {
if (
new Date(startTime).getTime() <=
Cesium.JulianDate.toDate(
vieweryanshi.clock.currentTime
).getTime() &&
new Date(endTime).getTime() >=
Cesium.JulianDate.toDate(
vieweryanshi.clock.currentTime
).getTime() &&
flag
) {
return true;
} else {
return false;
}
};
10、控制实体label显示隐藏
const setLabelStatus = (id, option) => {
// 获取刚刚加载的实体
let entity = entities.getById(id);
if (entity && entity.label) {
entity.label.show = option.show; // 设置标签的显示状态
}
}