What is a propertyBag

Ive read the documentation and seen people ask for help with them on this forum and they got redirected to use something else.

From the places I found it mentioned in Cesium’s github issues it sounds like it was created to help out us typescript users but I can’t find enough general stuff on the web about propertybags to really get a grasp for it. Can you pass a propertyBag to an entity instead of newing a bunch of ConstantProperty’s?

So… why, when, and how Cesium’s propertybags? example?

A property bag is just a way to pass a key/value map. You can see in ModelGraphics for example, the nodeTransformations is a property bag: https://cesium.com/docs/cesiumjs-ref-doc/ModelGraphics.html?classFilter=ModelGr#nodeTransformations. The keys are the names of the nodes, and the values are translation/orientation objects.

It’s used in this code example: https://sandcastle.cesium.com/index.html?src=Time%20Dynamic%20Wheels.html. But here it’s created as just an object:

var nodeTransformations = {
  Wheels: wheelTransformation,
  Wheels_mid: wheelTransformation,
  Wheels_rear: wheelTransformation,
};

For this to be correct with strict type checking, this should instead be:

var nodeTransformations = new Cesium.PropertyBag();
nodeTransformations.addProperty('Wheels', wheelTransformation);
nodeTransformations.addProperty('Wheels_mid', wheelTransformation);
nodeTransformations.addProperty('Wheels_rear', wheelTransformation);

Great! thank you. That brings it full circle for me and I figure it out from there. Just needed a quick leg up.

1 Like

Omar is of course correct that you can think of it as a key/value map, but the important difference from a plain object is that a PropertyBag is a Property, i.e. it has a getValue(time) method, which allows the value to vary based on simulation time.

It also adds a property (lower-case P) to the PropertyBag that contains the “raw” (not Property-wrapped) value that corresponds to each key:

const pb = new PropertyBag({position: Cartesian3.fromDegrees(10,20)});
const {position} = pb.getValue(JulianDate.now());
position.equals(pb.position); // true

IMHO, this is also kind of confusing, because if you pass a Property to the constructor, the bag’s getValue method evaluates the Property, but the “index operator” (pb.position or pb["position"]) returns the unevaluated Property and you have to call its getValue method:

const pb = new PropertyBag({position: new ConstantPositionProperty(Cartesian3.fromDegrees(10,20))});
const now = JulianDate.now();
const {position} = pb.getValue(now);
position.equals(pb.position.getValue(now)); // true
1 Like