Did anyone figure this thing out yet?I have balloon callouts that I just cannot get the shape for. I've tried everything and nothing works.
public void PerformTest() { double fromX = 0; double fromY = 0; ITextElement textElement = new TextElementClass(); IElement element = textElement as IElement; IElementProperties elementProperties = element as IElementProperties; textElement.Text = "Sample text to go in a callout to test getting the size. " + "This adds some text on a second line." + "This adds some text on a third line."; ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); double offSetX = 0; double offSetY = 0; if (ArcMap.Document.ActivatedView is IPageLayout) { // inches, page layout units offSetX = 0.5; offSetY = 1; } else { // feet. This worked for my test map's scale. offSetX = 800; offSetY = 1500; } // Set the location of the callout balloon (lower-left corner of text) point.PutCoords(fromX + offSetX, fromY + offSetY); element.Geometry = point; // Create text symbology IFormattedTextSymbol formattedTextSymbol = new TextSymbol() as IFormattedTextSymbol; stdole.IFontDisp fontFrom = formattedTextSymbol.Font; fontFrom.Size = 8; formattedTextSymbol.Font = fontFrom; formattedTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; ICallout callOut = new BalloonCalloutClass(); formattedTextSymbol.Background = (ITextBackground)callOut; textElement.Symbol = formattedTextSymbol; IGraphicsContainer graphicsContainer = ArcMap.Document.ActivatedView as IGraphicsContainer; // Add the callout element without a leader to an anchor point graphicsContainer.AddElement(element, 0); // Get the bounds of callout envelope for just the balloon IEnvelope elementEnvelope = new EnvelopeClass(); element.QueryBounds(ArcMap.Document.ActiveView.ScreenDisplay, elementEnvelope); System.Diagnostics.Debug.WriteLine("Element (Before Anchor): " + elementEnvelope.Width + ", " + elementEnvelope.Height); System.Diagnostics.Debug.WriteLine(" SpatialReference: " + (textElement as IGraphicElement).SpatialReference.Name); System.Diagnostics.Debug.WriteLine(" UpperLeft:" + elementEnvelope.UpperLeft.X + ", " + elementEnvelope.UpperLeft.Y); System.Diagnostics.Debug.WriteLine(" LowerLeft:" + elementEnvelope.LowerLeft.X + ", " + elementEnvelope.LowerLeft.Y); System.Diagnostics.Debug.WriteLine(" UpperRight:" + elementEnvelope.UpperRight.X + ", " + elementEnvelope.UpperRight.Y); System.Diagnostics.Debug.WriteLine(" LowerRight:" + elementEnvelope.LowerRight.X + ", " + elementEnvelope.LowerRight.Y); // Set the leader anchor point ESRI.ArcGIS.Geometry.Point anchorPTFrom = new ESRI.ArcGIS.Geometry.Point(); anchorPTFrom.PutCoords(fromX, fromY); callOut.AnchorPoint = anchorPTFrom; // Must re-assign this or leader to anchor is not created on map and querybounds // returns same value as before textElement.Symbol = formattedTextSymbol; // Get the bounds of the entire callout envelope surrounding balloon and leader element.QueryBounds(ArcMap.Document.ActiveView.ScreenDisplay, elementEnvelope); System.Diagnostics.Debug.WriteLine("Element (After Anchor): " + elementEnvelope.Width + ", " + elementEnvelope.Height); System.Diagnostics.Debug.WriteLine(" SpatialReference: " + (textElement as IGraphicElement).SpatialReference.Name); System.Diagnostics.Debug.WriteLine(" UpperLeft:" + elementEnvelope.UpperLeft.X + ", " + elementEnvelope.UpperLeft.Y); System.Diagnostics.Debug.WriteLine(" LowerLeft:" + elementEnvelope.LowerLeft.X + ", " + elementEnvelope.LowerLeft.Y); System.Diagnostics.Debug.WriteLine(" UpperRight:" + elementEnvelope.UpperRight.X + ", " + elementEnvelope.UpperRight.Y); System.Diagnostics.Debug.WriteLine(" LowerRight:" + elementEnvelope.LowerRight.X + ", " + elementEnvelope.LowerRight.Y); }
It seems like ITextBackground.QueryBoundary should work but I'm getting an empty geometry returned. I appreciate all the help by the way.
IPolygon poly = new PolygonClass(); textSymLeftAlign.Background.QueryBoundary(ArcMap.Document.ActiveView.ScreenDisplay.get_CacheMemDC(0), ArcMap.Document.ActiveView.ScreenDisplay.DisplayTransformation as ITransformation, poly); System.Diagnostics.Debug.WriteLine("Background: " + poly.Envelope.Width + ", " + poly.Envelope.Height);
Yeah, it looks like it returns the envelope surrounding the anchor and the balloon -- which makes sense since the element includes both.Have you tried ITextBackground.QueryBoundary? Since the background is the ballooncallout, it seems like that should work. I don't have time to test it at the moment...
Ok yes I agree the code you have works and is returning the 4 corners. However, try changing your offset value for Y on the leftFromElement.Geometry to something other then 0. This way the actual callout appears away from the anchor point and will show the tail of the callout. Then see if the returned coordinates match the corners of the box.
Running same test code as before. The corner location coordinates are correct in Layout View:Element Size: 2.85220000000118, 0.530399999999645 UpperLeft:-0.0694000000003143, 0.436700000000201 LowerLeft:-0.0694000000003143, -0.0936999999994441 UpperRight:2.78280000000086, 0.436700000000201 LowerRight:2.78280000000086, -0.0936999999994441I added this to get the spatial ref and corners: System.Diagnostics.Debug.WriteLine(" SpatialReference: " + (leftFromTextElement as IGraphicElement).SpatialReference.Name); System.Diagnostics.Debug.WriteLine(" UpperLeft:" + elementEnvelope.UpperLeft.X + ", " + elementEnvelope.UpperLeft.Y); System.Diagnostics.Debug.WriteLine(" LowerLeft:" + elementEnvelope.LowerLeft.X + ", " + elementEnvelope.LowerLeft.Y); System.Diagnostics.Debug.WriteLine(" UpperRight:" + elementEnvelope.UpperRight.X + ", " + elementEnvelope.UpperRight.Y); System.Diagnostics.Debug.WriteLine(" LowerRight:" + elementEnvelope.LowerRight.X + ", " + elementEnvelope.LowerRight.Y); In Data View :Element Size: 6608.73942823708, 1228.99884448946 SpatialReference: NAD_1983_StatePlane_California_VI_FIPS_0406_Feet UpperLeft:-160.905063271523, 1011.83200590312 LowerLeft:-160.905063271523, -217.16683858633 UpperRight:6447.83436496556, 1011.83200590312 LowerRight:6447.83436496556, -217.16683858633Using the Go To XY (set to Feet like the SR), and it located the corners correctly.
System.Diagnostics.Debug.WriteLine(" SpatialReference: " + (leftFromTextElement as IGraphicElement).SpatialReference.Name); System.Diagnostics.Debug.WriteLine(" UpperLeft:" + elementEnvelope.UpperLeft.X + ", " + elementEnvelope.UpperLeft.Y); System.Diagnostics.Debug.WriteLine(" LowerLeft:" + elementEnvelope.LowerLeft.X + ", " + elementEnvelope.LowerLeft.Y); System.Diagnostics.Debug.WriteLine(" UpperRight:" + elementEnvelope.UpperRight.X + ", " + elementEnvelope.UpperRight.Y); System.Diagnostics.Debug.WriteLine(" LowerRight:" + elementEnvelope.LowerRight.X + ", " + elementEnvelope.LowerRight.Y);
I put your code into a test Add-In and made as few modifications as needed to get it to run (just some constant values and document references): public void PerformTest() { double fromX = 0; double fromY = 0; ITextElement leftFromTextElement = new TextElementClass(); IElement leftFromElement = leftFromTextElement as IElement; IElementProperties leftFromProperties = leftFromElement as IElementProperties; leftFromProperties.Name = "LF:" + "TEST"; leftFromTextElement.Text = "Sample text to go in a callout to test gettting the size. " + "This adds some text on a second line." + "This adds some text on a third line."; ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(fromX, fromY + 0); leftFromElement.Geometry = point; // Create text symbology IFormattedTextSymbol textSymLeftAlign = new TextSymbol() as IFormattedTextSymbol; stdole.IFontDisp fontFrom = textSymLeftAlign.Font; fontFrom.Size = 8; textSymLeftAlign.Font = fontFrom; textSymLeftAlign.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; ICallout callOut = new BalloonCalloutClass(); textSymLeftAlign.Background = (ITextBackground)callOut; // Set anchor point ESRI.ArcGIS.Geometry.Point anchorPTFrom = new ESRI.ArcGIS.Geometry.Point(); anchorPTFrom.PutCoords(fromX, fromY); callOut.AnchorPoint = anchorPTFrom; leftFromTextElement.Symbol = textSymLeftAlign; IGraphicsContainer graphicsContainer = ArcMap.Document.ActivatedView as IGraphicsContainer; graphicsContainer.AddElement(leftFromElement, 0); leftFromElement.Activate(ArcMap.Document.ActivatedView.ScreenDisplay); //Testing to see if I can figure out extent of callout graphic IEnvelope elementEnvelope = new EnvelopeClass(); leftFromElement.QueryBounds(ArcMap.Document.ActiveView.ScreenDisplay, elementEnvelope); System.Diagnostics.Debug.WriteLine("Element: " + elementEnvelope.Width + ", " + elementEnvelope.Height); } The output in Page Layout is:Element: 2.85220000000118, 0.530399999999645The output in Data View is:Element: 6608.73942823708, 1228.99884448946These look to me to correspond to the width and height of the callout box. Isn't that what you are looking for?
public void PerformTest() { double fromX = 0; double fromY = 0; ITextElement leftFromTextElement = new TextElementClass(); IElement leftFromElement = leftFromTextElement as IElement; IElementProperties leftFromProperties = leftFromElement as IElementProperties; leftFromProperties.Name = "LF:" + "TEST"; leftFromTextElement.Text = "Sample text to go in a callout to test gettting the size. " + "This adds some text on a second line." + "This adds some text on a third line."; ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(fromX, fromY + 0); leftFromElement.Geometry = point; // Create text symbology IFormattedTextSymbol textSymLeftAlign = new TextSymbol() as IFormattedTextSymbol; stdole.IFontDisp fontFrom = textSymLeftAlign.Font; fontFrom.Size = 8; textSymLeftAlign.Font = fontFrom; textSymLeftAlign.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; ICallout callOut = new BalloonCalloutClass(); textSymLeftAlign.Background = (ITextBackground)callOut; // Set anchor point ESRI.ArcGIS.Geometry.Point anchorPTFrom = new ESRI.ArcGIS.Geometry.Point(); anchorPTFrom.PutCoords(fromX, fromY); callOut.AnchorPoint = anchorPTFrom; leftFromTextElement.Symbol = textSymLeftAlign; IGraphicsContainer graphicsContainer = ArcMap.Document.ActivatedView as IGraphicsContainer; graphicsContainer.AddElement(leftFromElement, 0); leftFromElement.Activate(ArcMap.Document.ActivatedView.ScreenDisplay); //Testing to see if I can figure out extent of callout graphic IEnvelope elementEnvelope = new EnvelopeClass(); leftFromElement.QueryBounds(ArcMap.Document.ActiveView.ScreenDisplay, elementEnvelope); System.Diagnostics.Debug.WriteLine("Element: " + elementEnvelope.Width + ", " + elementEnvelope.Height); }
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.