Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger a rendering when a data source becomes ready #11934

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
##### Fixes :wrench:

- Fixed a bug that Label position height may not be correctly updated when its HeightReference is relative. [#11929](https://github.com/CesiumGS/cesium/pull/11929)
- Fixed a bug where a data source was not automatically rendered after is was added in request render mode. [#11934](https://github.com/CesiumGS/cesium/pull/11934)

### 1.116 - 2024-04-01

Expand Down
5 changes: 5 additions & 0 deletions packages/engine/Source/DataSources/DataSourceDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ DataSourceDisplay.prototype.update = function (time) {
result = visualizers[x].update(time) && result;
}

// Request a rendering of the scene when the data source
// becomes 'ready' for the first time
if (!this._ready && result) {
this._scene.requestRender();
}
this._ready = result;

return result;
Expand Down
39 changes: 39 additions & 0 deletions packages/engine/Specs/DataSources/DataSourceDisplaySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,45 @@ describe(
});
});

it("triggers a rendering when the data source becomes ready", function () {
scene.requestRenderMode = true;
scene.maximumRenderTimeChange = undefined;

// When the scene is constructed, then a listener that will be added via
// RequestScheduler.requestCompletedEvent.addEventListener
// that requests a single render (by putting a call to scene.requestRender()
// into the scene._frameState.afterRender list). The requestCompletedEvent
// is triggered when the request for the terrain heights completes that
// is initiated via GroundPolylinePrimitive.initializeTerrainHeights()
// in beforeAll of this suite.
// Consume this render request here
scene.renderForSpecs();

const source = new MockDataSource();
display = new DataSourceDisplay({
scene: scene,
dataSourceCollection: dataSourceCollection,
visualizersCallback: visualizersCallback,
});
expect(display.ready).toBe(false);

return dataSourceCollection.add(source).then(function () {
// When the source becomes ready, a render should
// be requested
display.update(Iso8601.MINIMUM_VALUE);
expect(display.ready).toBe(true);
expect(scene._renderRequested).toBe(true);

scene.renderForSpecs();

// The source should remain ready during subsequent updates,
// and no further renders should be requested
display.update(Iso8601.MINIMUM_VALUE);
expect(display.ready).toBe(true);
expect(scene._renderRequested).toBe(false);
});
});

it("constructor throws if scene undefined", function () {
expect(function () {
return new DataSourceDisplay({
Expand Down