我正在使用此代码在ArcMap中创建文本。但是当你放大时,我似乎无法像注释文本那样进行缩放。
有谁知道怎么做?
//'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;
答案 0 :(得分:1)
据我所知,你不能让TextSymbol随地图一起缩放。这是因为TextElement不能根据地图的范围进行更改,而是使用字体大小来确定它在屏幕上显示的大小。
在我仍然使用TextSymbol时,我能想到的最好的方法是更改点大小(如果范围足够大,则隐藏/显示元素)随着范围的变化。我不知道“注意程度的文本控件”,这是你真正需要的。
或者,您是否只能使用注释图层或标记要更改文本大小的图层?
答案 1 :(得分:1)
我们可以很好地添加根据比例改变大小的文本。为此,我们需要使用IElementProperties3.ReferenceScale属性。
我没有C#代码,但我附上了一些您可以修改的示例VBA代码。
'--------------------------------
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
'--------------------------------
答案 2 :(得分:0)
ITextElement
有一个属性ITextElement.ScaleText
。将其设置为true
,文本大小将自动调整。