Extending Cesium classes

Just wondering if there is another way I haven't come across yet to easily extend the base Cesium classes to add new functionality. For instance, if I wanted to make a custom class called MyEntity that extends the base Entity class, can I do that?

I've tested doing this. I accept the object that would be used to create the entity as a parameter in my class and then pass it to the super() call to create the Cesium Entity. All that seems to work but when I attempt to add my new MyEntity object to the viewer I get an error that name is a reserved keyword.

I've gotten this to work with another class or two but Entity seems to be giving me trouble. Is there something stupid I'm missing?

Can you post some of your code?

I just tried this out with the examples described here https://kevhuang.com/subclasses-and-inheritance-in-javascript/ and this creates a “MyEntity” that will add a default red material to a rectangle:

var MyEntity = function(options) {
if (options && options.rectangle) {
options.rectangle.material = Cesium.Color.RED.withAlpha(0.5);
}

Cesium.Entity.call(this, options);

};
MyEntity.prototype = Object.create(Cesium.Entity.prototype);
MyEntity.prototype.constructor = MyEntity;

``

Here’s a full example on Sandcastle. Let me know if that helps!

I mean yeah, that can work. I was hoping to use the cleaner, class implementation where I could do..

class MyEntity extends Cesium.Entity {
   constructor() {
      super()
   }
}

And define things from there but I guess I could go ahead and just extend it using the prototype.

Thanks

That would definitely be nice, and in fact is on our roadmap, see https://github.com/AnalyticalGraphicsInc/cesium/issues/2524#issuecomment-363495391