3

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.

2

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:

    entity.label = label;

Should be a LabelGraphics instance, like this:

    entity.label = new Cesium.LabelGraphics(label);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.