Est-il un moyen d'obtenir un texte graphique à l'échelle dans ArcMap?
-
23-08-2019 - |
Question
J'utilise ce code pour créer du texte dans ArcMap. Mais je ne peux pas sembler l'obtenir à l'échelle comme texte d'annotation lorsque vous effectuez un zoom.
Quelqu'un sait comment faire cela?
//'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;
La solution
On peut très bien ajouter du texte qui modifie sa taille en fonction de l'échelle. pour cela, nous devons utiliser la propriété IElementProperties3.ReferenceScale.
Je n'ai pas du code C #, mais je joins un certain exemple de code VBA que vous pouvez modifier.
'--------------------------------
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
'--------------------------------
Autres conseils
A ma connaissance, vous ne pouvez pas obtenir un TextSymbol à l'échelle avec la carte. En effet, le TextElement n'est pas modifiable en fonction de l'étendue de la carte, mais, au contraire, utilise la taille de la police pour déterminer la taille, il va apparaître à l'écran.
La meilleure façon que je peux penser à le faire tout en utilisant un TextSymbol est de changer la taille du point (et, si la mesure est assez grand, cacher / montrer l'élément) que les changements de mesure. Je ne sais pas d'un « contrôle de texte qui accorde une attention dans la mesure où, » qui est ce que vous avez vraiment besoin.
Sinon, vous ne pourriez pas utiliser juste une couche d'annotation ou étiqueter la couche où vous voulez la taille du texte pour changer?
Le ITextElement
a un ITextElement.ScaleText
de propriété. Réglez ce paramètre pour true
et la taille du texte adaptera automatiquement.