Monday, 7 October 2019

arcgis 10.0 - Is it possible to create a Balloon Callout with a leader?


Is it possible to create a Balloon Callout with a leader? I am using the following code:


public void DrawText( IActiveView view, BalloonParms balloonParms ) {
ITextElement textElement = new TextElementClass();

textElement.Text = balloonParms.TextString;
textElement.ScaleText = true; // ???
textElement.Symbol = GetTextBalloon( balloonParms );
IElement element = textElement as IElement;
element.Geometry = balloonParms.AnchorPoint;
view.GraphicsContainer.AddElement( element, 0 );
view.PartialRefresh( esriViewDrawPhase.esriViewGraphics, element, null );
}

(Ignore the details of GetTextBalloon() it is just standard dance of formatted text, balloon callout, simple fill, and simple line. BalloonParms is just struct with all the settings bundled.) I'm clicking on a polygon feature, getting the point location, and then calling this code. It works like a charm. But there is no leader line!



The IElement interface allows me to set an anchor point and I can fiddle with various settings for the IBalloonCallout.LeaderTolerance but nothing will cause the leader line to appear. I can offset the anchor but still no leader. Is there a way to set both the anchor and another point that will determine where the balloon is drawn? I can't find that prooperty. Am I missing it?



Answer



If you set the IElement.Geometry to the result of this function and set the IBalloonCallout.AnchorPoint to the user selected location then the leader appears.


private IPoint OffsetAnchor( IActiveView view, IPoint anchor ) {
IPoint point = new PointClass();
point.PutCoords( anchor.X, anchor.Y );
double bumpX = view.Extent.Width / 20d;
double bumpY = view.Extent.Height / 20d;
IEnvelope2 envelope = point.Envelope as IEnvelope2;
envelope.Offset( bumpX, bumpY );

point.PutCoords( envelope.XMin, envelope.YMin );
return point;
}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...