点
// 假设 viewer 已经初始化
var viewer = new Cesium.Viewer('cesiumContainer');
// 添加一个红色的点实体,并记住它的 ID
var redPointId = viewer.entities.add({
id: 'redPoint', // 为实体指定一个唯一的 ID
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
point: {
pixelSize: 10,
color: Cesium.Color.RED.withAlpha(0.5),
outlineColor: Cesium.Color.WHITE,
outlineWidth: 2
}
});
// 定义一个函数来更改点的颜色
const changeColorPoint = (id) => {
const entity = viewer.entities.getById(id); // 通过 ID 获取实体
if (entity && entity.point) { // 确保实体存在且是一个点实体
entity.point.color = Cesium.Color.BLUE.withAlpha(0.5); // 将颜色更改为蓝色,并设置透明度为 0.5
}
};
// 在某个时刻,调用这个函数来更改点的颜色
// 例如,在按钮点击事件中,或者在一段时间后
changeColorPoint(redPointId);
使用getByID获取指定实体,直接修改颜色
线
const changeColorLine = (key,color,num) => {
linePoly.value[key].forEach(v => {
// 当报错找不到材质的时候可加 new Cesium.ColorMaterialProperty
v.polyline.material = new Cesium.ColorMaterialProperty(Cesium.Color.fromBytes(...color));
});
}
// 假设 linePoly.value 是一个对象,它包含了一个或多个线条集合
// 线条集合的 key 是 'lines1',你想要将这些线条的颜色更改为黄色(RGB: 255, 255, 0)
changeColorLine('lines1', [255, 255, 0, 1])
这里面案例是使用多线段,所以遍历。
线是修改材质颜色