I tried adding labels to my cesium application using the below code
var entities3 = dataSource3.entities.values;
var colorHash = {};
for (var i = 0; i < entities3.length; i++) {
var entity = entities3[i];
var label;
var name = entity.properties.Height;
var color = colorHash[name];
if (!color) {
color = Cesium.Color.BROWN;
colorHash[name] = color;
}
entity.polygon.extrudedHeight = entity.properties.Height;
label = {
text: entity.properties.Name,
font : '12px Helvetica',
fillColor : Cesium.Color.WHITE,
outlineColor : Cesium.Color.BLACK,
outlineWidth : 4,
style : Cesium.LabelStyle.FILL_AND_OUTLINE,
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
pixelOffset : new Cesium.Cartesian2(0, -9)
};
entity.label = label;
}
But there is no labels appearing.
Best Answer
Firstly, there's no
entity.properties
on a constructed Cesium.Entity. If you're looking for raw data that you injected into your CZML somehow, you'll have to grab that data out before turning the CZML into real Entities.Beyond that, your main problem seems to be this line:
Should be a LabelGraphics instance, like this: