views:

769

answers:

2

I'm using this code to create text in ArcMap. But I can't seem to get it to scale like annotation text when you zoom in.

Does anyone know how to do this?

//'First setup a color.  We'll use RGB red    
                IRgbColor pRGBcolor = new RgbColor();
                pRGBcolor.Blue = 0;
                pRGBcolor.Red = 255;
                pRGBcolor.Green = 0;

                //'Next, cocreate a new TextElement    
                ITextElement pTextElement = new TextElementClass();

                //'Query Interface (QI) to an IElement pointer and set    
                //'the geometry that was passed in    
                IElement pElement = pTextElement as IElement;
                pElement.Geometry = Point;

                //'Next, setup a font
                stdole.IFontDisp pFontDisp = new stdole.StdFont() as stdole.IFontDisp;
                pFontDisp.Name = "Arial";
                pFontDisp.Bold = true;

                //'Next, setup a TextSymbol that the TextElement will draw with    
                ITextSymbol pTextSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();
                pTextSymbol.Font = pFontDisp;
                pTextSymbol.Color = pRGBcolor;
                pTextSymbol.Size = Size;
                pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
                pTextSymbol.Angle = Angle;
                pTextSymbol.Text = Text;

                //'set the size of the text symbol here, rather than on the font        
                //'Next, Give the TextSymbol and text string to the TextElement    
                pTextElement.Symbol = pTextSymbol;
                pTextElement.Text = pTextSymbol.Text;
                pTextElement.ScaleText = true;

                ESRI.ArcGIS.Carto.IElementProperties3 aoElementPro = pTextElement as ESRI.ArcGIS.Carto.IElementProperties3;
                aoElementPro.ReferenceScale = cGISHelpers.MapDomain.Map.MapScale;
+1  A: 

To my knowledge, you can't get a TextSymbol to scale along with the map. That's because the TextElement isn't changeable based upon the map's extent but, instead, uses the font size to determine how large it's going to appear on the screen.

The best way that I can think of to do it while still using a TextSymbol is to change the point size (and, if the extent is large enough, hide/show the element) as the extent changes. I don't know of a "text control that pays attention to the extent," which is what you would really need.

Alternately, couldn't you just use an annotation layer or label the layer where you want the text size to change?

Michael Todd
I'm building a tool to put dimensions on parcels. We need to make it very easy for the client so I'm trying to use graphic text to position and set the size of the text and then the tool will save it in a annotation layer after the user is happy where the text is.
Donny V.
I talked to our "GIS guy" (my boss) and the best we could come up with is to an annotation layer from parcel labels, and then allow your client to manually move the labels inside the annotation layer. That way you preserve extent/text-size changes and also allow for moving the text around.
Michael Todd
"to an annotation layer" = "to create an annotation layer"
Michael Todd
+1  A: 

We can very well add text which changes it size according to the scale. for this, we need to use the IElementProperties3.ReferenceScale Property.

I do not have C# code, but am attaching some sample VBA code that you can modify.

'--------------------------------
Sub ChangeTextElemRefScale()
    Dim pDoc As IMxDocument
    Dim pContainer As IGraphicsContainer
    Dim pElement As IElement
    Dim pTextElement As ITextElement
    Dim pActiveView As IActiveView

    Set pDoc = ThisDocument
    Set pActiveView = pDoc.ActiveView
    Set pContainer = pActiveView

    'Loop through the graphics container
    pContainer.Reset
    Set pElement = pContainer.Next
    While not pElement Is Nothing
        'Get the specific text element
        If TypeOf pElement Is ITextElement Then
           Set pTextElement = pElement
           If pTextElement.Text = "oregon" Then  'change this to your text element's text
                Dim pElemProp As IElementProperties3
                Set pElemProp = pTextElement
                pElemProp.ReferenceScale = 15000000
            End If
        End If
        Set pElement = pContainer.Next
    Wend

    pDoc.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
End Sub
'--------------------------------
dev