Does anyone have an example of using either Entity definitionChanged or one of the graphic object’s definitionChanged? We’re loading in some AAR kml and we want to trigger some notification information when a certain Entity is shown(show property set to true or false). We are able to search through the entities created, and we’ve attempted to add the Event but the callback is never called. We’ve successfully adding several other Cesium.Events so we’re a little confused why this one isn’t working.
TIA, Scott
<?xml version="1.0" encoding="utf-8"?>
<kml>
<GroundOverlay>
<name>Exercise Paused Overlay</name>
<color>53ffffff</color>
<description>
<![CDATA[Event Time:2021-01-20T15:18:00.333Z<table border="1" padding="3" width="600"><tr><td><b>Event</b></td><td><b>Type</b></td></tr><tr><td>system</td><td>stop freeze</td></tr><tr><td><b>Begin</b></td><td><b>End</b></td></tr><tr><td>2021-01-20T15:18:00.333Z</td><td>2021-01-20T15:20:30.333Z</td></tr></table>]]> </description>
<Icon>
<href>kml/images/icons/EXPause.png</href>
<viewBoundScale>1.0</viewBoundScale>
</Icon>
<LatLonBox>
<north>70</north>
<south>-70</south>
<east>179.99</east>
<west>-179.99</west>
</LatLonBox>
<TimeSpan>
<begin>2021-01-20T15:18:00.333Z</begin>
<end>2021-01-20T15:20:30.333Z</end>
</TimeSpan>
</GroundOverlay>
</kml>
This kml generates an entity and I’ve gone through all of the KmlDataSource and I’m trying to catch when the generated rectangle’s show property is set to true and false. Is that possible? Or is there a better way to get this event. Here’s what I tried below.
if (entity.name.includes(“Exercise Paused Overlay”) && entity.rectangle) {
if ( entity.parent ) {
entity.parent.definitionChanged.addEventListener(this.eventFunction(5), this);
}
entity.definitionChanged.addEventListener(this.eventFunction(4), this);
entity.rectangle &&
entity.rectangle.definitionChanged.addEventListener(this.eventFunction(3), this);
}
eventFunction(index: number) {
console.log(index + “. entity or rectangle changed”);
}
TIA,
Scott
You’re invoking eventFunction
immediately and passing its return value (undefined
) to addEventListener
as a callback. I think what you meant was definitionChanged.addEventListener(() => this.eventFunction(5));
. You could alternately write definitionChanged.addEventListener(this.eventFunction, this);
but it will get invoked with arguments based on the callback signature for the definitionChanged
event.
Cesium doesn’t document callback signatures for some events, unfortunately, but I’m working on them. It looks like definitionChanged
invokes the callback with ent: Entity, propName: string, newValue, oldValue
, if I’m reading the code correctly.
Duh, haha, thanks for the reply. I added the parameter later on to try to find which item was getting show set.
I cannot get definitionChanged to work at all(after loading kml). Can someone please post an example of this event working? We’re trying to find the Cesium.Entity which is visible so we can flyTo that entity. We’d also like to hide all units by affiliation, which means I have to add the definitionChanged event after the KmlDataSource is loaded.
// recursively processing all unit entities loading
entity.definitionChanged.addEventListener( (a,b,c,d) => {
debugger
}, this ).bind(this);
entity.definitionChanged.addEventListener( this.entityChanged, this );
entity.definitionChanged.addEventListener( function( a,b,c,d ) {
debugger
}, this );
}
// angular directive scope
entityChanged( a,b,c,d ) {
debugger
}
We’ve got 250 children of one kml folder changing the ‘show’ property and the ‘debugger’ statement is never hit. ???
Scott
Hello @Scott_Haynes,
Maybe, You can play with function return value