Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

This is what I do, there's no leader

public static void DrawHoverStatic(IPoint p, string text = "hello\nthis is working!")
{
    if (pBalloonCalloutContainer == null) pBalloonCalloutContainer = MapKernel.Get().ActiveView as IGraphicsContainer;

    if (pTextElement == null) pTextElement = new TextElementClass();
    pTextElement.Text = text;

    if (pCallout == null)
    {
        pCallout = new BalloonCalloutClass();
        pCallout.Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle;
    }

    pCallout.AnchorPoint = p;

    if (pTextSymbol == null)
    {
        pTextSymbol = new TextSymbolClass();
        pTextSymbol.Background = pCallout as ITextBackground;
    }
    pTextElement.Symbol = pTextSymbol;

    pElement = pTextElement as IElement;
    pElement.Geometry = p;

    try
    {
        pBalloonCalloutContainer.AddElement(pElement, 0);
        pElement.Activate(MapKernel.Get().ActiveView.ScreenDisplay);
        MapKernel.Get().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null);
    }
    catch (Exception ex)
    {
        string message = ex.Message;
    }

}
share|improve this answer
    
Yeah, I left out the Activate() but even with it there is no leader. (My code basically boils down (or up) to yours.) Is ArcEngine awesome or what? Is this just another poorly documented 'bug' that I can pay ESRI to tell me about? –  Chaz Dec 22 '11 at 21:43
    
Oh I'm sorry I misread your question I thought you wanted no leader. –  patrick Dec 29 '11 at 16:29
add comment
up vote 0 down vote accepted

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;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.