Select to view content in your preferred language

Display Balloon Callout with text

1698
6
02-10-2020 08:52 AM
BobTaylor
Emerging Contributor

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

6 Replies
UmaHarano
Esri Regular Contributor

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.

 private Task ApplyLabelFeatureLayerAsync()
        {          
            return QueuedTask.Run(() =>
            {
                //Get the layer's definition
                var lyrDefn = SelectedLayer.GetDefinition() as CIMFeatureLayer;
                //Get the label classes - we need the first one
                var listLabelClasses = lyrDefn.LabelClasses.ToList();
                var theLabelClass = listLabelClasses.FirstOrDefault();
                //Place all labels horizontally
                theLabelClass.StandardLabelPlacementProperties.LineLabelPosition.Horizontal = true;
                //Set the label classes' symbol to the custom text symbol
                theLabelClass.TextSymbol.Symbol = SelectedTextStyle.Symbol;
                lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
                SelectedLayer.SetDefinition(lyrDefn);

                //set the label's visiblity
                if (IsLabelVisible)
                    (SelectedLayer as FeatureLayer).SetLabelVisibility(true);
            });
        }

Thanks

Uma

0 Kudos
BobTaylor
Emerging Contributor

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

{

return mapView.AddOverlay(point, callOut.MakeSymbolReference());

});

}

0 Kudos
BobTaylor
Emerging Contributor

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());

                     });         

                 

              }

0 Kudos
UmaHarano
Esri Regular Contributor

You can use the "Text" property on the CIMTextGraphic:

var textGraphic = new CIMTextGraphic();
textGraphic.Text = "MyText";

0 Kudos
BobTaylor
Emerging Contributor

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 ) 

0 Kudos
UmaHarano
Esri Regular Contributor

To use graphics as overlays, here is a snippet:

Add overlay graphic with text

0 Kudos