- Create a ColorMaterialProperty and assign it’s color value to a CallbackProperty. Here’s an example (warning this demo may cause seizures)
var viewer = new Cesium.Viewer(‘cesiumContainer’);
//New color every time it’s called
var randomColor = new Cesium.CallbackProperty(function(time, result){
return Cesium.Color.fromRandom({alpha: 1.0}, result);
}, false);
viewer.entities.add({
name : 'Red box with black outline',
position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
box : {
dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
material : new Cesium.ColorMaterialProperty(randomColor)
}
});
viewer.zoomTo(viewer.entities);
- I thought I we handled this already, but we don’t. Good news is it’s trivial to add and I’ll put it in 1.8, even better you can use the below class to add this functionality yourself until then:
var PolylineArrowMaterialProperty = function(colorProperty) {
this._definitionChanged = new Cesium.Event();
this._color = undefined;
this._colorSubscription = undefined;
this.color = colorProperty;
};
Cesium.defineProperties(PolylineArrowMaterialProperty.prototype, {
isConstant : {
get : function() {
return Cesium.Property.isConstant(this._color);
}
},
definitionChanged : {
get : function() {
return this._definitionChanged;
}
},
color : Cesium.createPropertyDescriptor('color')
});
PolylineArrowMaterialProperty.prototype.getType = function(time) {
return 'PolylineArrow';
};
PolylineArrowMaterialProperty.prototype.getValue = function(time, result) {
if (!Cesium.defined(result)) {
result = {};
}
result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
return result;
};
PolylineArrowMaterialProperty.prototype.equals = function(other) {
return this === other || (other instanceof PolylineArrowMaterialProperty && Cesium.Property.equals(this._color, other._color));
};
And here’s an example using it:
var viewer = new Cesium.Viewer(‘cesiumContainer’);
viewer.entities.add({
name : 'Red line on the surface',
polyline : {
positions : Cesium.Cartesian3.fromDegreesArray([-126, 35, -125, 35]),
width : 15,
material : new PolylineArrowMaterialProperty(Cesium.Color.RED)
}
});
viewer.zoomTo(viewer.entities);