For accessing a primitive by id, try these helper functions. You could expand getPrimitive() to have more features like jQuery selectors.
var viewer = new Cesium.Viewer(‘cesiumContainer’);
/////////////////////////
var primitives = viewer.scene.primitives;
var primitivesById = {};
function addPrimitive(primitive) {
if (!Cesium.defined(primitive)) {
throw new Cesium.DeveloperError(‘primitive is required.’);
}
var id = primitive.id;
if (!Cesium.defined(id)) {
throw new Cesium.DeveloperError(‘primitive.id is required so the primitive can be accessed by id.’);
}
if (Cesium.defined(primitivesById[id])) {
throw new Cesium.DeveloperError(‘A primitive with the same primitive.id already exists, remove it before adding a new one.’);
}
primitivesById[id] = primitive;
return primitives.add(primitive);
}
function getPrimitive(id) {
if (!Cesium.defined(id)) {
throw new Cesium.DeveloperError(‘id is required.’);
}
// Will return undefined if the id does not exist
return primitivesById[id];
}
function removePrimitive(id) {
if (!Cesium.defined(id)) {
return false;
}
var removed = primitives.remove(primitivesById[id]);
if (removed) {
primitivesById[id] = undefined;
}
return removed;
}
/////////////////////////
addPrimitive(new Cesium.EllipsoidPrimitive({
center : Cesium.Cartesian3.fromDegrees(-75.0, 40.0, 500000.0),
radii : new Cesium.Cartesian3(1.0, 1.0, 1.0),
id : ‘example id’
}));
getPrimitive(‘example id’).radii = new Cesium.Cartesian3(500000.0, 500000.0, 500000.0);
// removePrimitive(‘example id’);
Patrick