I’m attempting to add labels to each entity via a GeoJSON.
dataSource.load(geojson).then(function() {
// Get array of entities
var entities = dataSource["_entityCollection"]["_entities"]["_array"];
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var id = entity.id;
var material;
var outline;
var label;
if (entity.properties.vinculado === 0){
material = Cesium.Color.RED.withAlpha(0.5);
outline = Cesium.Color.BLACK;
entity.polygon.material = new Cesium.ColorMaterialProperty(material);
entity.polygon.outlineColor = new Cesium.ColorMaterialProperty(outline);
entity.polygon.outline = true;
var center = Cesium.BoundingSphere.fromPoints(entity.polygon.hierarchy.value.positions.getValue()).center;
Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(center, center);
entity.position = new Cesium.ConstantPositionProperty(center);
label = new Cesium.LabelGraphics({
text: entity.properties.id,
font : '24px Helvetica',
fillColor : Cesium.Color.SKYBLUE,
outlineColor : Cesium.Color.BLACK,
outlineWidth : 2,
style : Cesium.LabelStyle.FILL_AND_OUTLINE,
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
pixelOffset : new Cesium.Cartesian2(0, -9),
show: true
});
entity.label = label;
} else {
material = Cesium.Color.GREEN.withAlpha(0.5);
outline = Cesium.Color.BLACK.withAlpha(0.9);
entity.polygon.material = new Cesium.ColorMaterialProperty(material);
entity.polygon.outlineColor = new Cesium.ColorMaterialProperty(outline);
entity.polygon.outline = true;
var center = Cesium.BoundingSphere.fromPoints(entity.polygon.hierarchy.value.positions.getValue()).center;
Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(center, center);
entity.position = new Cesium.ConstantPositionProperty(center);
label = new Cesium.LabelGraphics({
text: entity.properties.id,
font : '24px Helvetica',
fillColor : Cesium.Color.SKYBLUE,
outlineColor : Cesium.Color.BLACK,
outlineWidth : 2,
style : Cesium.LabelStyle.FILL_AND_OUTLINE,
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
pixelOffset : new Cesium.Cartesian2(0, -9),
show: true
});
entity.label = label;
}
}
});
``
Unfortunately, it’s not adding labels or coloring all of the polygons as specified:
I assume it has to do with the
entity.polygon.hierarchy
``
&
entity.label & entity.position
``
Any thoughts on why this would be happening?