Hi, I have been able to find great examples of creating a balloon callout but I don't see how to add text to it (ProSnippets TextSymbols ). If i just want to add the text "Hello World" to the Balloon Callout example, how would i do that?
Thanks,
Bob
To use graphics as overlays, here is a snippet:
Add overlay graphic with text
The example code does not use the CIMTextGraphic class, only the CIMTextSymbol class which does not have a Text property. ( Sorry for leaving the textGraphic declare line in the above code which is not used )
You can use the "Text" property on the CIMTextGraphic:
var textGraphic = new CIMTextGraphic();textGraphic.Text = "MyText";
Looks like the code sample was lost on the reply. See code below:
public virtual Task<CIMTextSymbol> CreateBalloonCalloutAsync()
{
return QueuedTask.Run<CIMTextSymbol>(() =>
//create a text symbol
var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 11, "Corbel", "Regular");
var textGraphic = new CIMTextGraphic();
//A balloon callout
var balloonCallout = new CIMBalloonCallout();
//set the callout's style
balloonCallout.BalloonStyle = BalloonCalloutStyle.RoundedRectangle;
//Create a solid fill polygon symbol for the callout.
var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid);
//Set the callout's background to be the black polygon symbol
balloonCallout.BackgroundSymbol = polySymbol;
//margin inside the callout to place the text
balloonCallout.Margin = new CIMTextMargin
Left = 5,
Right = 5,
Bottom = 5,
Top = 5
};
//assign the callout to the text symbol's callout property
textSymbol.Callout = balloonCallout;
return textSymbol;
});
}
private IDisposable _graphic = null;
public async void AddGraphicToMap(MapPoint point)
// get the current mapview and point
var mapView = MapView.Active;
if (mapView == null)
return;
var myextent = mapView.Extent;
var callOut = await CreateBalloonCalloutAsync();
// add point graphic to the overlay at the center of the mapView
_graphic = await QueuedTask.Run(() =>
return mapView.AddOverlay(point, callOut.MakeSymbolReference());
Thanks for your reply Uma. That’s not exactly what I am trying to accomplish though. Have a look at the following code snippets that I found on the esri site. When I call the AddGraphicToMap() it, of course, just adds a black dot the map at the specified point. I would like to add some text to the callout so that it looks like the below image.
public virtual Task
Hi Bob,
To label features of a layer, you have to use the SetLabelVisibility method.
Check out the TextSymbols sample. Specifically in the ApplyLabelFeatureLayerAsync method, notice how we get the layer's TextSymbol and change it to the Symbol we want (in your case the Balloon callout). You can simply call the SetLabelVisibility method and pass in true to label the layer.
<SPAN class="keyword token">private</SPAN> Task <SPAN class="token function">ApplyLabelFeatureLayerAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//Get the layer's definition</SPAN> <SPAN class="keyword token">var</SPAN> lyrDefn <SPAN class="operator token">=</SPAN> SelectedLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetDefinition</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> CIMFeatureLayer<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Get the label classes - we need the first one</SPAN> <SPAN class="keyword token">var</SPAN> listLabelClasses <SPAN class="operator token">=</SPAN> lyrDefn<SPAN class="punctuation token">.</SPAN>LabelClasses<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> theLabelClass <SPAN class="operator token">=</SPAN> listLabelClasses<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Place all labels horizontally</SPAN> theLabelClass<SPAN class="punctuation token">.</SPAN>StandardLabelPlacementProperties<SPAN class="punctuation token">.</SPAN>LineLabelPosition<SPAN class="punctuation token">.</SPAN>Horizontal <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Set the label classes' symbol to the custom text symbol</SPAN> theLabelClass<SPAN class="punctuation token">.</SPAN>TextSymbol<SPAN class="punctuation token">.</SPAN>Symbol <SPAN class="operator token">=</SPAN> SelectedTextStyle<SPAN class="punctuation token">.</SPAN>Symbol<SPAN class="punctuation token">;</SPAN> lyrDefn<SPAN class="punctuation token">.</SPAN>LabelClasses <SPAN class="operator token">=</SPAN> listLabelClasses<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToArray</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Set the labelClasses back</SPAN> SelectedLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetDefinition</SPAN><SPAN class="punctuation token">(</SPAN>lyrDefn<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//set the label's visiblity</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>IsLabelVisible<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">(</SPAN>SelectedLayer <SPAN class="keyword token">as</SPAN> FeatureLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetLabelVisibility</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks
Uma
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.