Polygon Displaying Past Dynamic Distance Display Condition

Hello fellow Cesium enthusiasts!

I hope to tap into the wealth of knowledge that exists these forums :slight_smile: I’m not sure if I’m doing something wrong with dynamic distance display conditions? There seems to be some finickiness. Anyway, here’s the story.

I added a custom click handler some camera flyTos to an informal test for pull request 4403: https://github.com/AnalyticalGraphicsInc/cesium/pull/4403#issuecomment-251746113.

The click handler simply does some distance calculations and plops the distance from the camera and the distance display condition’s far property into the entity’s description.

When clicking on an entity, this click handler will display the polygon’s distance from the camera in the entity’s description field.

If (TOO FAR) is displayed, then the polygon is outside of its distance display condition. This is unexpected only in the case where the polygon is also visible on the globe. This is happening in some cases.

// CUSTOM CLICK HANDLER
var originalClickHandler = viewer.screenSpaceEventHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
viewer.screenSpaceEventHandler.setInputAction(clickHandler, Cesium.ScreenSpaceEventType.LEFT_CLICK);

function clickHandler(payload) {

var picked = viewer.scene.drillPick(payload.position)[0];

if (picked) {
   
    var pickedPos;
    if (!picked.primitive.id) {
        pickedPos = picked.id.position._value;
    } else {
        pickedPos = picked.primitive.id.position._value;
    }
   
    var cameraPos = viewer.scene.camera.position;
    var distance = Cesium.Cartesian3.distance(cameraPos, pickedPos);
   
    var far = picked.id.polygon.distanceDisplayCondition._callback()._far;
     
    var tooFar = far - distance <= 0 ? '  (TOO FAR, ' + far + ')' : '';
           
    if (picked.primitive.id) {
        picked.primitive.id.description = "Distance: " + distance + tooFar;      
    } else {
        picked.id.description = "Distance: " + distance + tooFar;
    }      
}    

originalClickHandler(payload);

}

``

// CAMERY FLY FUNCTIONS
function flyStart () {
var start = {
destination: Cesium.Cartesian3.fromDegrees(-121, 35, 800000.0)
};
viewer.camera.flyTo(start);
}

function flyHome () {
var home = {
destination: Cesium.Cartesian3.fromRadians(-1.6843483301420932, 0.47487287505729037, 4195873.061330347)
};
viewer.camera.flyTo(home);
}

function flyAway() {
var away = {
destination: Cesium.Cartesian3.fromDegrees(0.0, 0.0, 1000.0)
};
viewer.camera.flyTo(away);
}

setTimeout(flyStart, 300);
setTimeout(flyAway, 2000);
setTimeout(flyHome, 3500);

``

I can get the map into a state where the polygon is showing up as well as the name. I would not expect this is because the distance between the polygon and the camera is outside of the range allowed by the distance display condition. I would expect the polygons not to be displayed in that case.

I found this easier to reproduce when the camera first moved out of view of the polygons and then comes back.

Do I have a logic error in my thought process?

I still don’t fully understand the point of using BoundingSphere. This DataSourceDisplay makes it seem like it tells us whether they are fully rendered or not. Like in this postRender callback, it sets up the promise to wait on entities to be fully rendered. When they are all fully rendered, only then can we safely set up the distance display condition. Is that it? I’m curious if changing the distance display condition in at postRender time might be troublesome. Perhaps the data source display change isn’t getting registered somehow at the right time, and the new function isn’t getting run?

I was also surprised to see two labels for Texas display in the top picture.

Any help would be appreciated! Thanks in advance!

Sandcastle: http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=ce5ece6a95fe500cfcf22dd8910d4f35

The below snips are from FF (top) and IE (bottom) :

Looks like this has been fixed (see here) and will be available with the next Cesium release (1.48)!