Tuesday, 30 May 2017

arcgis engine - What are the main steps when building a balloon callout using ArcObjects in arcengine 10 in VS2010 with C#


I'm looking for a good BalloonCallout example / tutorial / sample. edit: Using C# with ArcEngine 10 edit #2:


What are the main steps when building a balloon callout using ArcObjects in arcengine 10?


Here's what I've tried so far:


This happens in a dynamic data layer


DynamicGlyphFactory dynamicGlyphFactory = (DynamicGlyphFactory)dynamicDisplay;

IDynamicSymbolProperties2 dynamicSymbolProps = dynamicDisplay as IDynamicSymbolProperties2;

IFillSymbol fillSymbol = new SimpleFillSymbolClass();
TextSymbolClass textSymbol = new TextSymbolClass();
IBalloonCallout balloonCallout = new BalloonCalloutClass();

simpleFillSymbol.Color = rgbColor;

dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolFill, fillSymbol as IDynamicGlyph);
dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolFill, 20f, 20f, 20f, 255);


IDynamicGlyph fillGlyph = dynamicGlyphFactory.CreateDynamicGlyph((ISymbol)fillSymbol);

balloonCallout.AnchorPoint = anchorPoint;
balloonCallout.Style = esriBalloonCalloutStyle.esriBCSOval;
balloonCallout.Symbol = fillSymbol;
balloonCallout.LeaderTolerance = 10;

textSymbol.Background = (ITextBackground)balloonCallout;
dynamicSymbolProps.TextBoxUseDynamicFillSymbol = true;

IDynamicGlyph glyph = dynamicGlyphFactory.CreateDynamicGlyph((ISymbol)textSymbol);
dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolText, glyph);

iDynamicDisplay.DrawText(point, someString);

Answer



There is a VBA sample in the ArcDesktop help How to add a balloon callout it should be possible to customize for ArcGIS Engine, Change so that you ues the ActiveView from your MapControl or PagelayoutControl.


Update, code that works in engine:


Private Sub AddBalloonCallout(ByVal activeView As IActiveView)
Dim pTextElement As ITextElement
Dim pElement As IElement

Dim pPoint As IPoint
Dim pCallout As ICallout
Dim pTextSymbol As IFormattedTextSymbol
Dim pGraphicsContainer As IGraphicsContainer
Dim midX As Double, midY As Double

'Create a new text element
pTextElement = New TextElement
pElement = CType(pTextElement, IElement) 'QI
pTextElement.Text = "Text callout" & vbCrLf & "In the middle of the screen"


'Position the new element on the active view's center point
midX = (activeView.Extent.XMax + activeView.Extent.XMin) / 2
midY = (activeView.Extent.YMax + activeView.Extent.YMin) / 2
pPoint = New Point
pPoint.PutCoords(midX, midY)
pElement.Geometry = pPoint

'Set the text element symbology to a default balloon callout
pTextSymbol = New TextSymbol

pCallout = New BalloonCallout
pTextSymbol.Background = CType(pCallout, ITextBackground)
'Use this formula to get a callout anchor point location
pPoint.PutCoords(midX - activeView.Extent.Width / 4, midY + activeView.Extent.Width / 20)
pCallout.AnchorPoint = pPoint
pTextElement.Symbol = pTextSymbol

'Add the element to the active view, either the focus Map or PageLayout
pGraphicsContainer = CType(activeView, IGraphicsContainer)
pGraphicsContainer.AddElement(pElement, 0)

pElement.Activate(activeView.ScreenDisplay)

'Flag the area of the new element for refreshing
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, Nothing)
End Sub

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...