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

Label backgrounds #4715

Merged
merged 40 commits into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
53e5284
Label backgrounds WIP
emackey Nov 18, 2016
2e10d53
Merge branch 'billboards-dont-wiggle' into label-backgrounds
emackey Nov 23, 2016
f90a819
Fix some issues
emackey Nov 23, 2016
113acae
Fix maxHeight.
emackey Nov 23, 2016
6babe4f
Use an imageSubRegion to avoid the fringes.
emackey Nov 23, 2016
000ac25
Remove debugging info.
emackey Nov 23, 2016
bce6efa
Started work on label background settings.
emackey Nov 23, 2016
6f42315
Merge remote-tracking branch 'origin/master' into label-backgrounds
emackey Nov 23, 2016
83a5e1b
Unused requires
emackey Nov 23, 2016
b54ccd5
Convert backgroundPadding to Cartesian2, add showBackground bool.
emackey Nov 23, 2016
829439d
Fix vertical position of background with bottom and center alignments.
emackey Nov 24, 2016
3173059
Hook up showBackground flag.
emackey Nov 25, 2016
1e94844
Add CZML support for label backgrounds.
emackey Nov 27, 2016
fdb3ddf
Update Terrain demo to use label backgrounds.
emackey Nov 27, 2016
ed5f911
Remove poor assumptions from label tests.
emackey Nov 30, 2016
39016dc
Make label.backgroundPadding count towards alignment.
emackey Dec 1, 2016
f0f3a1b
Add VerticalOrigin.BASELINE
emackey Dec 1, 2016
3c6a76f
Fix various issues with value updates.
emackey Dec 1, 2016
10045f6
Mostly fix getScreenSpaceBoundingBox.
emackey Dec 1, 2016
77710be
Merge remote-tracking branch 'origin/master' into label-backgrounds
emackey Dec 2, 2016
e3010ad
More fixes to getScreenSpacePosition.
emackey Dec 2, 2016
a48848b
Scene parameter not needed, can get resolutionScale from collection.
emackey Dec 2, 2016
c21d922
Add tests.
emackey Dec 3, 2016
981138f
Documentation update
emackey Dec 3, 2016
ac8e0d2
More doc updates, change default label primitive origin to BASELINE.
emackey Dec 4, 2016
178d712
Add label to Ground Clamping example.
emackey Dec 4, 2016
f330bf3
Update default padding to be larger.
emackey Dec 6, 2016
4b8c256
Add defaults to documentation.
emackey Dec 6, 2016
854ee56
Code style change
emackey Dec 6, 2016
53b4d35
Remove spare background billboard array.
emackey Dec 6, 2016
3eb09e4
Disable background on empty labels.
emackey Dec 6, 2016
05d680e
Use backgrounds a bit more in Sandcastle demos.
emackey Dec 6, 2016
7b7e262
Fix typo.
emackey Dec 7, 2016
85ae743
Merge remote-tracking branch 'origin/master' into label-backgrounds
emackey Dec 7, 2016
82391da
CHANGES.md
emackey Dec 7, 2016
a36cf20
Don't test a function by copying its logic into the test.
emackey Dec 7, 2016
0eb64e7
Make background color less harsh on clamping demo.
emackey Dec 8, 2016
b9b2104
Merge remote-tracking branch 'origin/master' into label-backgrounds
pjcozzi Dec 8, 2016
caa3eec
Merge remote-tracking branch 'origin/master' into label-backgrounds
emackey Dec 8, 2016
e76e693
Make label tests more robust, fix vertical center test.
emackey Dec 8, 2016
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
20 changes: 10 additions & 10 deletions Apps/Sandcastle/gallery/CZML Billboard and Label.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@
},
"label" : {
"fillColor" : {
"rgba" : [0, 255, 255, 255]
"rgba" : [255, 255, 255, 255]
},
"font" : "11pt Lucida Console",
"font" : "12pt Lucida Console",
"horizontalOrigin" : "LEFT",
"outlineColor" : {
"rgba":[0, 0, 0, 255]
},
"outlineWidth" : 2,
"pixelOffset" : {
"cartesian2" : [12, 0]
"cartesian2" : [8, 0]
},
"style" : "FILL_AND_OUTLINE",
"text" : "AGI"
"style" : "FILL",
"text" : "AGI",
"showBackground" : true,
"backgroundColor" : {
"rgba" : [112, 89, 57, 200]
}
},
"position" : {
"cartesian":[
Expand All @@ -65,7 +65,7 @@

var viewer = new Cesium.Viewer('cesiumContainer');
viewer.dataSources.add(Cesium.CzmlDataSource.load(czml));
//Sandcastle_End
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
Expand Down
39 changes: 25 additions & 14 deletions Apps/Sandcastle/gallery/Ground Clamping.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
Expand All @@ -29,8 +29,8 @@
<div id="sampleButtons"></div>
</div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer');
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
Expand All @@ -44,7 +44,7 @@
//
// To clamp points or billboards set the heightReference to CLAMP_TO_GROUND or RELATIVE_TO_GROUND
//
text : 'Draw Points',
text : 'Draw Point with Label',
onselect : function() {
var e = viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(-122.1958, 46.1915),
Expand All @@ -54,6 +54,17 @@
outlineColor : Cesium.Color.YELLOW,
outlineWidth : 3,
heightReference : Cesium.HeightReference.CLAMP_TO_GROUND
},
label : {
text : 'Clamped to ground',
font : '14pt sans-serif',
heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
horizontalOrigin : Cesium.HorizontalOrigin.LEFT,
verticalOrigin : Cesium.VerticalOrigin.BASELINE,
fillColor : Cesium.Color.BLACK,
showBackground : true,
backgroundColor : new Cesium.Color(1, 1, 1, 0.7),
backgroundPadding : new Cesium.Cartesian2(8, 4)
}
});

Expand Down Expand Up @@ -130,13 +141,13 @@
};

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions Apps/Sandcastle/gallery/Labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
});

entity.label.scale = 2.0;
entity.label.showBackground = true;
}

function offsetByDistance() {
Expand All @@ -80,6 +81,7 @@
label : {
text : 'Label on top of scaling billboard',
font : '20px sans-serif',
showBackground : true,
horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
pixelOffset : new Cesium.Cartesian2(0.0, -image.height),
pixelOffsetScaleByDistance : new Cesium.NearFarScalar(1.5e2, 3.0, 1.5e7, 0.5)
Expand Down
9 changes: 6 additions & 3 deletions Apps/Sandcastle/gallery/Terrain.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@
},
label : {
text : position.height.toFixed(1),
font : '10pt monospace',
horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
scale : 0.3,
pixelOffset : new Cesium.Cartesian2(0, -14),
fillColor : Cesium.Color.RED,
outlineColor : Cesium.Color.WHITE
fillColor : Cesium.Color.BLACK,
outlineColor : Cesium.Color.BLACK,
showBackground : true,
backgroundColor : new Cesium.Color(0.9, 0.9, 0.9, 0.7),
backgroundPadding : new Cesium.Cartesian2(4, 3)
}
});
}
Expand Down
19 changes: 14 additions & 5 deletions Apps/Sandcastle/gallery/development/Labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,27 @@
labels.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
labels.add({
position : new Cesium.Cartesian3(0.0, 0.0, 0.0),
text : 'Center'
text : 'Center',
font : '13pt sans-serif',
showBackground : true
});
labels.add({
position : new Cesium.Cartesian3(1000000.0, 0.0, 0.0),
text : 'East'
text : 'East',
font : '13pt sans-serif',
showBackground : true
});
labels.add({
position : new Cesium.Cartesian3(0.0, 1000000.0, 0.0),
text : 'North'
text : 'North',
font : '13pt sans-serif',
showBackground : true
});
labels.add({
position : new Cesium.Cartesian3(0.0, 0.0, 1000000.0),
text : 'Up'
text : 'Up',
font : '13pt sans-serif',
showBackground : true
});
}

Expand All @@ -108,8 +116,9 @@
var labels = scene.primitives.add(new Cesium.LabelCollection());
labels.add({
position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
text : 'Label on top of scaling billboard',
text : 'Label on top of scaling billboard',
font : '20px sans-serif',
showBackground : true,
horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
pixelOffset : new Cesium.Cartesian2(0.0, -image.height),
pixelOffsetScaleByDistance : new Cesium.NearFarScalar(1.5e2, 3.0, 1.5e7, 0.5)
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Change Log
### 1.29 - 2017-01-02

* Added the ability to blend a `Model` with a color/translucency. Added `color`, `colorBlendMode`, and `colorBlendAmount` properties to `Model`, `ModelGraphics`, and CZML. Added `ColorBlendMode` enum. [#4547](https://github.com/AnalyticalGraphicsInc/cesium/pull/4547)
* Added new `Label` properties `showBackground`, `backgroundColor`, and `backgroundPadding` to the primitive, Entity, and CZML layers.
* Added new enum `VerticalOrigin.BASELINE`. Previously, `VerticalOrigin.BOTTOM` would sometimes align to the baseline depending on the contents of a label.
* Fixed tooltips for gallery thumbnails in Sandcastle [#4702](https://github.com/AnalyticalGraphicsInc/cesium/pull/4702)
* Fixed `Rectangle.union` to correctly account for rectangles that cross the IDL [#4732](https://github.com/AnalyticalGraphicsInc/cesium/pull/4732).
* Fixed texture rotation for `RectangleGeometry` [#2737](https://github.com/AnalyticalGraphicsInc/cesium/issues/2737)
Expand Down
Binary file modified Documentation/Images/Billboard.setVerticalOrigin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Source/DataSources/CzmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,9 @@ define([
processPacketData(String, label, 'font', labelData.font, interval, sourceUri, entityCollection);
processPacketData(LabelStyle, label, 'style', labelData.style, interval, sourceUri, entityCollection);
processPacketData(Number, label, 'scale', labelData.scale, interval, sourceUri, entityCollection);
processPacketData(Boolean, label, 'showBackground', labelData.showBackground, interval, sourceUri, entityCollection);
processPacketData(Color, label, 'backgroundColor', labelData.backgroundColor, interval, sourceUri, entityCollection);
processPacketData(Cartesian2, label, 'backgroundPadding', labelData.backgroundPadding, interval, sourceUri, entityCollection);
processPacketData(Cartesian2, label, 'pixelOffset', labelData.pixelOffset, interval, sourceUri, entityCollection);
processPacketData(Cartesian3, label, 'eyeOffset', labelData.eyeOffset, interval, sourceUri, entityCollection);
processPacketData(HorizontalOrigin, label, 'horizontalOrigin', labelData.horizontalOrigin, interval, sourceUri, entityCollection);
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/EntityCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ define([
cluster.label.show = true;
cluster.label.text = numPoints.toLocaleString();
cluster.billboard.position = cluster.label.position = cluster.point.position = position;

entityCluster._clusterEvent.raiseEvent(ids, cluster);
}

Expand Down
40 changes: 40 additions & 0 deletions Source/DataSources/LabelGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ define([
* @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the outline {@link Color}.
* @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the outline width.
* @param {Property} [options.show=true] A boolean Property specifying the visibility of the label.
* @param {Property} [options.showBackground=true] A boolean Property specifying the visibility of the background behind the label.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong default is specified here, FYI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

* @param {Property} [options.backgroundColor=new Color(0.165, 0.165, 0.165, 0.8)] A Property specifying the background {@link Color}.
* @param {Property} [options.backgroundPadding=new Cartesian2(7, 5)] A {@link Cartesian2} Property specifying the horizontal and vertical background padding in pixels.
* @param {Property} [options.scale=1.0] A numeric Property specifying the scale to apply to the text.
* @param {Property} [options.horizontalOrigin=HorizontalOrigin.CENTER] A Property specifying the {@link HorizontalOrigin}.
* @param {Property} [options.verticalOrigin=VerticalOrigin.CENTER] A Property specifying the {@link VerticalOrigin}.
Expand Down Expand Up @@ -74,6 +77,12 @@ define([
this._scaleSubscription = undefined;
this._show = undefined;
this._showSubscription = undefined;
this._showBackground = undefined;
this._showBackgroundSubscription = undefined;
this._backgroundColor = undefined;
this._backgroundColorSubscription = undefined;
this._backgroundPadding = undefined;
this._backgroundPaddingSubscription = undefined;
this._translucencyByDistance = undefined;
this._translucencyByDistanceSubscription = undefined;
this._pixelOffsetScaleByDistance = undefined;
Expand Down Expand Up @@ -232,6 +241,31 @@ define([
*/
show : createPropertyDescriptor('show'),

/**
* Gets or sets the boolean Property specifying the visibility of the background behind the label.
* @memberof LabelGraphics.prototype
* @type {Property}
* @default false
*/
showBackground : createPropertyDescriptor('showBackground'),

/**
* Gets or sets the Property specifying the background {@link Color}.
* @memberof LabelGraphics.prototype
* @type {Property}
* @default new Color(0.165, 0.165, 0.165, 0.8)
*/
backgroundColor : createPropertyDescriptor('backgroundColor'),

/**
* Gets or sets the {@link Cartesian2} Property specifying the label's horizontal and vertical
* background padding in pixels.
* @memberof LabelGraphics.prototype
* @type {Property}
* @default new Cartesian2(7, 5)
*/
backgroundPadding : createPropertyDescriptor('backgroundPadding'),

/**
* Gets or sets {@link NearFarScalar} Property specifying the translucency of the label based on the distance from the camera.
* A label's translucency will interpolate between the {@link NearFarScalar#nearValue} and
Expand Down Expand Up @@ -279,6 +313,9 @@ define([
result.fillColor = this.fillColor;
result.outlineColor = this.outlineColor;
result.outlineWidth = this.outlineWidth;
result.showBackground = this.showBackground;
result.backgroundColor = this.backgroundColor;
result.backgroundPadding = this.backgroundPadding;
result.scale = this.scale;
result.horizontalOrigin = this.horizontalOrigin;
result.verticalOrigin = this.verticalOrigin;
Expand Down Expand Up @@ -311,6 +348,9 @@ define([
this.fillColor = defaultValue(this.fillColor, source.fillColor);
this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
this.showBackground = defaultValue(this.showBackground, source.showBackground);
this.backgroundColor = defaultValue(this.backgroundColor, source.backgroundColor);
this.backgroundPadding = defaultValue(this.backgroundPadding, source.backgroundPadding);
this.scale = defaultValue(this.scale, source.scale);
this.horizontalOrigin = defaultValue(this.horizontalOrigin, source.horizontalOrigin);
this.verticalOrigin = defaultValue(this.verticalOrigin, source.verticalOrigin);
Expand Down
8 changes: 8 additions & 0 deletions Source/DataSources/LabelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ define([
var defaultFillColor = Color.WHITE;
var defaultOutlineColor = Color.BLACK;
var defaultOutlineWidth = 1.0;
var defaultShowBackground = false;
var defaultBackgroundColor = new Color(0.165, 0.165, 0.165, 0.8);
var defaultBackgroundPadding = new Cartesian2(7, 5);
var defaultPixelOffset = Cartesian2.ZERO;
var defaultEyeOffset = Cartesian3.ZERO;
var defaultHeightReference = HeightReference.NONE;
Expand All @@ -50,6 +53,8 @@ define([
var position = new Cartesian3();
var fillColor = new Color();
var outlineColor = new Color();
var backgroundColor = new Color();
var backgroundPadding = new Cartesian2();
var eyeOffset = new Cartesian3();
var pixelOffset = new Cartesian2();
var translucencyByDistance = new NearFarScalar();
Expand Down Expand Up @@ -146,6 +151,9 @@ define([
label.fillColor = Property.getValueOrDefault(labelGraphics._fillColor, time, defaultFillColor, fillColor);
label.outlineColor = Property.getValueOrDefault(labelGraphics._outlineColor, time, defaultOutlineColor, outlineColor);
label.outlineWidth = Property.getValueOrDefault(labelGraphics._outlineWidth, time, defaultOutlineWidth);
label.showBackground = Property.getValueOrDefault(labelGraphics._showBackground, time, defaultShowBackground);
label.backgroundColor = Property.getValueOrDefault(labelGraphics._backgroundColor, time, defaultBackgroundColor, backgroundColor);
label.backgroundPadding = Property.getValueOrDefault(labelGraphics._backgroundPadding, time, defaultBackgroundPadding, backgroundPadding);
label.pixelOffset = Property.getValueOrDefault(labelGraphics._pixelOffset, time, defaultPixelOffset, pixelOffset);
label.eyeOffset = Property.getValueOrDefault(labelGraphics._eyeOffset, time, defaultEyeOffset, eyeOffset);
label.heightReference = Property.getValueOrDefault(labelGraphics._heightReference, time, defaultHeightReference);
Expand Down
16 changes: 6 additions & 10 deletions Source/Scene/Billboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ define([
* of removing it and re-adding it to the collection.
* @memberof Billboard.prototype
* @type {Boolean}
* @default true
*/
show : {
get : function() {
Expand Down Expand Up @@ -468,7 +469,7 @@ define([

/**
* Gets or sets the horizontal origin of this billboard, which determines if the billboard is
* to the left, center, or right of its position.
* to the left, center, or right of its anchor position.
* <br /><br />
* <div align='center'>
* <img src='images/Billboard.setHorizontalOrigin.png' width='400' height='300' /><br />
Expand Down Expand Up @@ -500,10 +501,10 @@ define([

/**
* Gets or sets the vertical origin of this billboard, which determines if the billboard is
* to the above, below, or at the center of its position.
* to the above, below, or at the center of its anchor position.
* <br /><br />
* <div align='center'>
* <img src='images/Billboard.setVerticalOrigin.png' width='400' height='300' /><br />
* <img src='images/Billboard.setVerticalOrigin.png' width='695' height='175' /><br />
* </div>
* @memberof Billboard.prototype
* @type {VerticalOrigin}
Expand Down Expand Up @@ -1132,9 +1133,7 @@ define([
return SceneTransforms.computeActualWgs84Position(frameState, tempCartesian3);
};

var scratchCartesian2 = new Cartesian2();
var scratchCartesian3 = new Cartesian3();
var scratchComputePixelOffset = new Cartesian2();

// This function is basically a stripped-down JavaScript version of BillboardCollectionVS.glsl
Billboard._computeScreenSpacePosition = function(modelMatrix, position, eyeOffset, pixelOffset, scene, result) {
Expand All @@ -1148,10 +1147,7 @@ define([
}

// Apply pixel offset
pixelOffset = Cartesian2.clone(pixelOffset, scratchComputePixelOffset);
var po = Cartesian2.multiplyByScalar(pixelOffset, scene.context.uniformState.resolutionScale, scratchCartesian2);
positionWC.x += po.x;
positionWC.y += po.y;
Cartesian2.add(positionWC, pixelOffset, positionWC);

return positionWC;
};
Expand Down Expand Up @@ -1227,7 +1223,7 @@ define([
}

var y = screenSpacePosition.y;
if (billboard.verticalOrigin === VerticalOrigin.TOP) {
if (billboard.verticalOrigin === VerticalOrigin.BOTTOM || billboard.verticalOrigin === VerticalOrigin.BASELINE) {
y -= height;
} else if (billboard.verticalOrigin === VerticalOrigin.CENTER) {
y -= height * 0.5;
Expand Down
Loading