Here is a code snippet to create an overlay with text. This code is from a sample Map Tool:
internal class AddOverlayWithText : MapTool
{
private IDisposable _graphic = null;
private CIMPolygonSymbol _polygonSymbol = null;
public AddOverlayWithText()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Polygon;
SketchOutputMode = SketchOutputMode.Map;
}
protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
_polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Null, SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid));
_graphic = await this.AddOverlayAsync(geometry, _polygonSymbol.MakeSymbolReference());
var textSymbol = new CIMTextSymbol();
var textGraphic = new CIMTextGraphic();
await QueuedTask.Run(() =>
{
textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular");
textGraphic.Shape = geometry;
textGraphic.Text = "This is my polygon";
textGraphic.Symbol = textSymbol.MakeSymbolReference();
_graphic = this.ActiveMapView.AddOverlay(textGraphic);
});
return true;
}
}
This code creates an overlay like this: