首页 / Cesium / API 文档
ConstantProperty
先看结论
永远返回同一个值的属性。给实体赋字面量时 Cesium 自动包成它,
isConstant 为 true,渲染端只求值一次。
new Cesium.ConstantProperty(value)
构造参数
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
value | any | undefined | 固定值,可以是 Cartesian3、Color、number、boolean 或对象 |
成员与方法
| 成员 | 类型 / 返回 | 说明 |
|---|---|---|
isConstant | boolean | 恒为 true |
definitionChanged | Event | 替换 value 时触发 |
getValue(time, result) | any | 忽略 time,直接返回构造时的值 |
equals(other) | boolean | 值相等则返回 true |
示例
var color = new Cesium.ConstantProperty(Cesium.Color.RED);
console.log(color.isConstant); // true
console.log(color.getValue(viewer.clock.currentTime)); // Color.RED
// 赋值也可以用 setValue,内部同样触发 definitionChanged
color.setValue(Cesium.Color.BLUE);
// 显式包装:与直接赋字面量等价
viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(116.391, 39.907, 0),
point: {
pixelSize: 10,
color: new Cesium.ConstantProperty(Cesium.Color.ORANGE)
}
});
注意事项
setValue修改的是同一个属性对象,所有引用它的实体一起变色;想独立控制要各自 new。- 构造时传入
undefined后getValue返回undefined,渲染端会当作属性缺失而不是 0。 - 复杂对象(如数组、颜色)不会深拷贝,外部改了传入对象,属性值也跟着变。
经纬志(2026)。《ConstantProperty》。https://www.jingweizhi.com/cesium/api/constant-property.html(访问日期 2026-11-03)。