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

Fix billboards not initially clustering. #5208

Merged
merged 3 commits into from
Apr 18, 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 @@ -7,6 +7,7 @@ Change Log
* Fixed issue with displaying `MapboxImageryProvider` default token error message [#5191](https://github.com/AnalyticalGraphicsInc/cesium/pull/5191)
* Added a `depthFailMaterial` property to line entities, which is the material used to render the line when it fails the depth test. [#5160](https://github.com/AnalyticalGraphicsInc/cesium/pull/5160)
* Upgrade FXAA to version 3.11. [#5200](https://github.com/AnalyticalGraphicsInc/cesium/pull/5200)
* Fix billboards not initially clustering. [#5208](https://github.com/AnalyticalGraphicsInc/cesium/pull/5208)

### 1.32 - 2017-04-03

Expand Down
13 changes: 12 additions & 1 deletion Source/DataSources/EntityCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,24 @@ define([
// If clustering is enabled before the label collection is updated,
// the glyphs haven't been created so the screen space bounding boxes
// are incorrect.
var commandList;
if (defined(this._labelCollection) && this._labelCollection.length > 0 && this._labelCollection.get(0)._glyphs.length === 0) {
var commandList = frameState.commandList;
commandList = frameState.commandList;
frameState.commandList = [];
this._labelCollection.update(frameState);
frameState.commandList = commandList;
}

// If clustering is enabled before the billboard collection is updated,
// the images haven't been added to the image atlas so the screen space bounding boxes
// are incorrect.
if (defined(this._billboardCollection) && this._billboardCollection.length > 0 && !defined(this._billboardCollection.get(0).width)) {
commandList = frameState.commandList;
frameState.commandList = [];
this._billboardCollection.update(frameState);
frameState.commandList = commandList;
}

if (this._enabledDirty) {
this._enabledDirty = false;
updateEnable(this);
Expand Down
69 changes: 69 additions & 0 deletions Specs/DataSources/EntityClusterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,29 @@ defineSuite([
expect(cluster._clusterLabelCollection).not.toBeDefined();
});

it('clusters billboards on first update', function() {
cluster = new EntityCluster();
cluster._initialize(scene);

var entity = new Entity();
var billboard = cluster.getBillboard(entity);
billboard.id = entity;
billboard.image = createBillboardImage();
billboard.position = SceneTransforms.drawingBufferToWgs84Coordinates(scene, new Cartesian2(0.0, 0.0), 0.5);

entity = new Entity();
billboard = cluster.getBillboard(entity);
billboard.id = entity;
billboard.image = createBillboardImage();
billboard.position = SceneTransforms.drawingBufferToWgs84Coordinates(scene, new Cartesian2(scene.canvas.clientWidth, scene.canvas.clientHeight), 0.5);

cluster.enabled = true;
cluster.update(scene.frameState);

expect(cluster._clusterLabelCollection).toBeDefined();
expect(cluster._clusterLabelCollection.length).toEqual(1);
});

it('clusters labels', function() {
cluster = new EntityCluster();
cluster._initialize(scene);
Expand Down Expand Up @@ -208,6 +231,29 @@ defineSuite([
expect(cluster._clusterLabelCollection).not.toBeDefined();
});

it('clusters labels on first update', function() {
cluster = new EntityCluster();
cluster._initialize(scene);

var entity = new Entity();
var label = cluster.getLabel(entity);
label.id = entity;
label.text = 'a';
label.position = SceneTransforms.drawingBufferToWgs84Coordinates(scene, new Cartesian2(0.0, 0.0), 0.5);

entity = new Entity();
label = cluster.getLabel(entity);
label.id = entity;
label.text = 'b';
label.position = SceneTransforms.drawingBufferToWgs84Coordinates(scene, new Cartesian2(scene.canvas.clientWidth, scene.canvas.clientHeight), 0.5);

cluster.enabled = true;
cluster.update(scene.frameState);

expect(cluster._clusterLabelCollection).toBeDefined();
expect(cluster._clusterLabelCollection.length).toEqual(1);
});

it('clusters points', function() {
cluster = new EntityCluster();
cluster._initialize(scene);
Expand Down Expand Up @@ -241,6 +287,29 @@ defineSuite([
expect(cluster._clusterLabelCollection).not.toBeDefined();
});

it('clusters points on first update', function() {
cluster = new EntityCluster();
cluster._initialize(scene);

var entity = new Entity();
var point = cluster.getPoint(entity);
point.id = entity;
point.pixelSize = 1;
point.position = SceneTransforms.drawingBufferToWgs84Coordinates(scene, new Cartesian2(0.0, 0.0), 0.5);

entity = new Entity();
point = cluster.getPoint(entity);
point.id = entity;
point.pixelSize = 1;
point.position = SceneTransforms.drawingBufferToWgs84Coordinates(scene, new Cartesian2(scene.canvas.clientWidth, scene.canvas.clientHeight), 0.5);

cluster.enabled = true;
cluster.update(scene.frameState);

expect(cluster._clusterLabelCollection).toBeDefined();
expect(cluster._clusterLabelCollection.length).toEqual(1);
});

it('clusters points that have labels', function() {
cluster = new EntityCluster();
cluster._initialize(scene);
Expand Down