Hi,
I am working on cesium but now got stuck because i want to show name or description in the center of polygon but not able to do it.Please post your ideas for this.
thanks in advance.
Hi,
I am working on cesium but now got stuck because i want to show name or description in the center of polygon but not able to do it.Please post your ideas for this.
thanks in advance.
Hello,
You can add a label as a separate primitive. You will have to compute the position at the center of the polygon yourself though.
Here’s an exampe:
var polygon = viewer.entities.add({
name : ‘Polygon’,
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-115.0, 38.0,
-115.0, 32.0,
-105.0, 32.0,
-105.0, 37.0]),
material : Cesium.Color.RED
}
});
var label = viewer.entities.add({
label: {
text: polygon.name,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
eyeOffset: new Cesium.Cartesian3(0,0,-200)
},
position: Cesium.Cartesian3.fromDegrees(-110, 35)
});
``
The horizontalOrigin property centers the label over the point, and the verticalOrigin and eyeOffset properties help prevent the label from going under the polygon.
Best,
Hannah