creating balloon callout on graphics layer

1819
12
Jump to solution
10-26-2021 09:06 AM
LeLuong
New Contributor III

All,

Has anyone successfully created a balloon callout on graphics layer by codes ?  I asked this question before with previous version of arcgis Pro.  I was under the impression with version 2.8 I should be able to do it but no luck so far.  Below is my codes.  I got all other properties correct but NO callout arrow.   Thanks in advance for your help.

Not a calloutNot a callout

 

 _subjectTextSymbol = await CreateBalloonCalloutAsync(ColorFactory.Instance.RedRGB);
.
.
.
 subjectLabelGraphic.Text = "Subject";
                            subjectLabelGraphic.Symbol = _subjectTextSymbol.MakeSymbolReference();
                            //Add the graphic label
                            graphicsLayer.AddElement(subjectLabelGraphic);
.
.
.


private static Task<CIMTextSymbol> CreateBalloonCalloutAsync(CIMColor textColor)
        {
            return QueuedTask.Run<CIMTextSymbol>(() =>
            {
                //create a text symbol
                var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(textColor, 11, "Corbel", "Regular");
                //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.GreyRGB, 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;
            });
        }

 

0 Kudos
12 Replies
JeremyWiles
New Contributor III

Thanks for the reply @LeLuong.  That is very interesting that it is possible through the SDK but on the UI.  Also that it allows that in the first place.

I can only hope that these types of features that are not available in the UI will be available in the SDK in the future.

0 Kudos
LeLuong
New Contributor III

Yayyyy! I got it.  Thank yo very much @CharlesMacleod .

0 Kudos
CharlesMacleod
Esri Regular Contributor

to coin a phrase: just do it. this is possible through the api and, apparently, not the ui.

callout2.png

var textGraphic = new CIMTextGraphic() {
  Text = "Callout Text",
  Placement = Anchor.CenterPoint,
  Symbol = textSymbol.MakeSymbolReference(),
  Shape = MapView.Active.Extent.Center,
  //Leaders is an array of CIMLeader - add a Leader point to show
  //the leader, remove Leaders to hide the leader.
  Leaders = new CIMLeader[] { 
    new CIMLeaderPoint(){
      Point = MapPointBuilderEx.CreateMapPoint(
          MapView.Active.Extent.Center.X - 5000,																						 
          MapView.Active.Extent.Center.Y - 1500)
    },
    new CIMLeaderPoint(){
      Point = MapPointBuilderEx.CreateMapPoint(
          MapView.Active.Extent.Center.X - 3500,																						 
          MapView.Active.Extent.Center.Y - 2500)
    },
    new CIMLeaderPoint(){
      Point = MapPointBuilderEx.CreateMapPoint(
          MapView.Active.Extent.Center.X - 500,																						 
          MapView.Active.Extent.Center.Y - 5000)
    }
  }
};

 

0 Kudos