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

Tile load event #5628

Merged
merged 4 commits into from
Jul 28, 2017
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 @@ -5,6 +5,7 @@ Change Log

* Added ability to show tile urls in the 3D Tiles Inspector. [#5592](https://github.com/AnalyticalGraphicsInc/cesium/pull/5592)
* Added behavior to `Cesium3DTilesInspector` that selects the first tileset hovered over if no tilest is specified. [#5139](https://github.com/AnalyticalGraphicsInc/cesium/issues/5139)
* Added `tileLoad` event to `Cesium3DTileset`. [#5628](https://github.com/AnalyticalGraphicsInc/cesium/pull/5628)
* Added ability to provide a `width` and `height` to `scene.pick`. [#5602](https://github.com/AnalyticalGraphicsInc/cesium/pull/5602)

### 1.35.2 - 2017-07-11
Expand Down
26 changes: 25 additions & 1 deletion Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,27 @@ define([
*/
this.allTilesLoaded = new Event();

/**
* The event fired to indicate that a tile's content was loaded.
* <p>
* The loaded {@link Cesium3DTile} is passed to the event listener.
* </p>
* <p>
* This event is fired during the tileset traversal while the frame is being rendered
* so that updates to the tile take effect in the same frame. Do not create or modify
* Cesium entities or primitives during the event listener.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* tileset.tileLoad.addEventListener(function(tile) {
* console.log('A tile was loaded.');
* });
*/
this.tileLoad = new Event();

/**
* The event fired to indicate that a tile's content was unloaded.
* <p>
Expand Down Expand Up @@ -1223,7 +1244,10 @@ define([

var removeFunction = removeFromProcessingQueue(tileset, tile);
tile.contentReadyToProcessPromise.then(addToProcessingQueue(tileset, tile));
tile.contentReadyPromise.then(removeFunction).otherwise(removeFunction);
tile.contentReadyPromise.then(function() {
removeFunction();
tileset.tileLoad.raiseEvent(tile);
}).otherwise(removeFunction);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it looks like this can fail, would it be worth passing an error to the event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would probably add a tileFailed event instead, a little more detail here: #5158

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense!

}

function requestTiles(tileset, outOfCore) {
Expand Down
28 changes: 28 additions & 0 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,34 @@ defineSuite([
});
});

it('tile load event is raised', function() {
viewNothing();
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) {
var spyUpdate = jasmine.createSpy('listener');
tileset.tileLoad.addEventListener(spyUpdate);
tileset.maximumMemoryUsage = 0;
viewRootOnly();
return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() {
// Root is loaded
expect(spyUpdate.calls.count()).toEqual(1);
expect(spyUpdate.calls.argsFor(0)[0]).toBe(tileset._root);
spyUpdate.calls.reset();

// Unload from cache
viewNothing();
scene.renderForSpecs();
expect(tileset.statistics.numberOfTilesWithContentReady).toEqual(0);

// Look at root again
viewRootOnly();
return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() {
expect(spyUpdate.calls.count()).toEqual(1);
expect(spyUpdate.calls.argsFor(0)[0]).toBe(tileset._root);
});
});
});
});

it('destroys', function() {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) {
var root = tileset._root;
Expand Down