/// <summary>
/// 自动标注图层
/// </summary>
/// <param name="pGeoFlyr">矢量图层对象</param>
/// <param name="pAutoLbl">动态标注对象</param>
public void SetLayerAutoLabel(IGeoFeatureLayer pGeoFlyr)
{
try
{
if (pGeoFlyr == null)
return;
IAnnotateLayerPropertiesCollection pAnnoProps = pGeoFlyr.AnnotationProperties;
pAnnoProps.Clear();
IAnnotateLayerProperties pAnnoLayerProps;
ILineLabelPosition pPosition;
ILineLabelPlacementPriorities pPlacement;
IBasicOverposterLayerProperties pBasic;
ILabelEngineLayerProperties pLabelEngine;
ITextSymbol pTextSymbol = new TextSymbolClass();
IRgbColor pColor = new RgbColorClass() { Red = 250, Blue = 0, Green = 0 };
stdole.StdFont pFont = new StdFontClass();
pFont.Name = "文鼎CS细等线";
pFont.Size = 50;
pTextSymbol.Font = pFont as stdole.IFontDisp;
pTextSymbol.Color = pColor;
pPosition = new LineLabelPositionClass();
pPosition.Parallel = true ;
pPosition.InLine = false ;
pPosition.Perpendicular = false ;
pPosition.Above = true;
pPlacement = new LineLabelPlacementPrioritiesClass();
pPlacement.AboveStart = 5;
pPlacement.BelowAfter = 4;
pBasic = new BasicOverposterLayerPropertiesClass();
pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
pBasic.LineLabelPlacementPriorities = pPlacement;
pBasic.LineLabelPosition = pPosition;
pBasic.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;
pLabelEngine = new LabelEngineLayerPropertiesClass();
pLabelEngine.Symbol = pTextSymbol;
pLabelEngine.BasicOverposterLayerProperties = pBasic;
string annoField = "[Shape_Length]";
pLabelEngine.Expression = annoField;
pAnnoLayerProps = pLabelEngine as IAnnotateLayerProperties;
pAnnoLayerProps.LabelWhichFeatures = esriLabelWhichFeatures.esriSelectedFeatures;
pAnnoLayerProps.WhereClause = "Shape_Length>40";
pAnnoProps.Add(pAnnoLayerProps);
pGeoFlyr.AnnotationProperties = pAnnoProps;
pGeoFlyr.DisplayAnnotation = true;
}
catch (Exception Err)
{
MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
注意红色部分字段格式以及条件的书写方式