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 clustering in 2D/CV #5136

Merged
merged 3 commits into from
Mar 24, 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 @@ -23,6 +23,7 @@ Change Log
* Added support for an orthographic projection in 3D and Columbus view.
* Set `projectionPicker` to `true` in the options when creating a `Viewer` to add a widget that will switch projections. [#5021](https://github.com/AnalyticalGraphicsInc/cesium/pull/5021)
* Call `switchToOrthographicFrustum` or `switchToPerspectiveFrustum` on `Camera` to change projections.
* Fix billboard, point and label clustering in 2D and Columbus view. [#5136](https://github.com/AnalyticalGraphicsInc/cesium/pull/5136)

### 1.31 - 2017-03-01

Expand Down
4 changes: 3 additions & 1 deletion Source/DataSources/EntityCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ define([
'../Scene/LabelCollection',
'../Scene/PointPrimitive',
'../Scene/PointPrimitiveCollection',
'../Scene/SceneMode',
'../ThirdParty/kdbush'
], function(
BoundingRectangle,
Expand All @@ -32,6 +33,7 @@ define([
LabelCollection,
PointPrimitive,
PointPrimitiveCollection,
SceneMode,
kdbush) {
'use strict';

Expand Down Expand Up @@ -166,7 +168,7 @@ define([
var item = collection.get(i);
item.clusterShow = false;

if (!item.show || !occluder.isPointVisible(item.position)) {
if (!item.show || (entityCluster._scene.mode === SceneMode.SCENE3D && !occluder.isPointVisible(item.position))) {
continue;
}

Expand Down
19 changes: 15 additions & 4 deletions Source/Scene/Billboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,26 @@ define([
}
//>>includeEnd('debug');

// pixel offset for screenspace computation is the pixelOffset + screenspace translate
// pixel offset for screen space computation is the pixelOffset + screen space translate
Cartesian2.clone(this._pixelOffset, scratchPixelOffset);
Cartesian2.add(scratchPixelOffset, this._translate, scratchPixelOffset);

var modelMatrix = billboardCollection.modelMatrix;
var actualPosition = this._getActualPosition();
var position = this._position;
if (defined(this._clampedPosition)) {
position = this._clampedPosition;
if (scene.mode !== SceneMode.SCENE3D) {
// position needs to be in world coordinates
var projection = scene.mapProjection;
var ellipsoid = projection.ellipsoid;
var cart = projection.unproject(position, scratchCartographic);
position = ellipsoid.cartographicToCartesian(cart, scratchCartesian3);
modelMatrix = Matrix4.IDENTITY;
}
}

var windowCoordinates = Billboard._computeScreenSpacePosition(modelMatrix, actualPosition,
this._eyeOffset, scratchPixelOffset, scene, result);
var windowCoordinates = Billboard._computeScreenSpacePosition(modelMatrix, position,
this._eyeOffset, scratchPixelOffset, scene, result);
return windowCoordinates;
};

Expand Down
22 changes: 22 additions & 0 deletions Specs/Scene/BillboardCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defineSuite([
'Scene/PerspectiveFrustum',
'Scene/TextureAtlas',
'Scene/VerticalOrigin',
'Specs/createCanvas',
'Specs/createGlobe',
'Specs/createScene',
'Specs/pollToPromise',
Expand All @@ -45,6 +46,7 @@ defineSuite([
PerspectiveFrustum,
TextureAtlas,
VerticalOrigin,
createCanvas,
createGlobe,
createScene,
pollToPromise,
Expand Down Expand Up @@ -1100,6 +1102,26 @@ defineSuite([
expect(b.computeScreenSpacePosition(scene)).toEqualEpsilon(new Cartesian2(0.5, 0.5), CesiumMath.EPSILON1);
});

it('computes screen space position in Columbus view', function() {
var b = billboards.add({
position : Cartesian3.fromDegrees(0.0, 0.0, 10.0)
});
scene.morphToColumbusView(0.0);
scene.camera.setView({ destination : Rectangle.MAX_VALUE });
scene.renderForSpecs();
expect(b.computeScreenSpacePosition(scene)).toEqualEpsilon(new Cartesian2(0.5, 0.5), CesiumMath.EPSILON1);
});

it('computes screen space position in 2D', function() {
var b = billboards.add({
position : Cartesian3.fromDegrees(0.0, 0.0, 10.0)
});
scene.morphTo2D(0.0);
scene.camera.setView({ destination : Rectangle.MAX_VALUE });
scene.renderForSpecs();
expect(b.computeScreenSpacePosition(scene)).toEqualEpsilon(new Cartesian2(0.5, 0.5), CesiumMath.EPSILON1);
});

it('throws when computing screen space position when not in a collection', function() {
var b = billboards.add({
position : Cartesian3.ZERO
Expand Down