Domanda

Sto usando questo codice per creare testo in ArcMap. Ma io non riesco a farlo in scala come testo di annotazione quando si ingrandisce.

Qualcuno sa come fare questo?

//'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;
È stato utile?

Soluzione

molto bene aggiungere del testo che cambia è formato secondo la scala. per questo, abbiamo bisogno di usare l'IElementProperties3.ReferenceScale Proprietà.

Non ho il codice C #, ma allego qualche codice VBA di esempio che è possibile modificare.

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

Altri suggerimenti

A mia conoscenza, non è possibile ottenere un TextSymbol in scala con la mappa. Questo perché il TextElement non è modificabile in base alla misura della mappa, ma, invece, utilizza la dimensione del carattere per determinare quanto grande sta andando a comparire sullo schermo.

Il modo migliore che posso pensare di farlo pur utilizzando un TextSymbol è quello di cambiare la dimensione del punto (e, se la misura è abbastanza grande, nascondere / mostrare l'elemento) al variare della misura. Non so di un "controllo di testo che presta attenzione alla misura", che è quello che sarebbe davvero bisogno.

In alternativa, potrebbe non basta usare un layer di annotazioni o etichettare il livello in cui si desidera la dimensione del testo per cambiare?

Il ITextElement ha un ITextElement.ScaleText proprietà. Impostare questo per true e la dimensione del testo si adatterà automaticamente.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top