Add name/description in the center of polygon

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.

Below is a complete example that should do what you want that you can paste into Sandcastle. If you already know the center point, you can simplify the code further. I would also recommend checking out the Visualizing Spatial Data tutorial if you haven’t already.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,

-115.0, 32.0,

-107.0, 33.0,

-102.0, 31.0,

-102.0, 35.0]);

var bs = Cesium.BoundingSphere.fromPoints(positions);

var center = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(bs.center);

var redPolygon = viewer.entities.add({

position : center,

label : {

text : “I’m in the center!”

},

polygon : {

hierarchy : positions,

material : Cesium.Color.RED.withAlpha(0.5)

}

});

viewer.zoomTo(viewer.entities);