Layer features in this layer set, ArcEngine图层标注源码

using System;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
 
/// <summary>
/// (重载)图层标注
/// </summary>
/// <param name="pFeaturelayer">标注图层</param>
/// <param name="sLableField">标注字段</param>
/// <param name="pRGB">颜色</param>
/// <param name="size">大小</param>
public static void FunLabelFeatureLayer(IFeatureLayer pFeaturelayer, string sLableField, IRgbColor pRGB, int size)
{
//判断图层是否为空
if (pFeaturelayer == null)
return;
IGeoFeatureLayer pGeoFeaturelayer = (IGeoFeatureLayer)pFeaturelayer;
IAnnotateLayerPropertiesCollection pAnnoLayerPropsCollection;
pAnnoLayerPropsCollection = pGeoFeaturelayer.AnnotationProperties;
pAnnoLayerPropsCollection.Clear();

//stdole.IFontDisp pFont; //字体
ITextSymbol pTextSymbol;

//pFont.Name = "新宋体";
//pFont.Size = 9;
//未指定字体颜色则默认为黑色
if (pRGB == null)
{
pRGB = new RgbColorClass();
pRGB.Red = 0;
pRGB.Green = 0;
pRGB.Blue = 0;
}

pTextSymbol = new TextSymbolClass();
pTextSymbol.Color = (IColor)pRGB;
pTextSymbol.Size = size; //标注大小

IBasicOverposterLayerProperties pBasicOverposterlayerProps = new BasicOverposterLayerPropertiesClass();
switch (pFeaturelayer.FeatureClass.ShapeType)//判断图层类型
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
pBasicOverposterlayerProps.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
pBasicOverposterlayerProps.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
pBasicOverposterlayerProps.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
break;
}

ILabelEngineLayerProperties pLabelEnginelayerProps = new LabelEngineLayerPropertiesClass();
pLabelEnginelayerProps.Expression = "[" + sLableField + "]";
pLabelEnginelayerProps.Symbol = pTextSymbol;
pLabelEnginelayerProps.BasicOverposterLayerProperties = pBasicOverposterlayerProps;

pAnnoLayerPropsCollection.Add((IAnnotateLayerProperties)pLabelEnginelayerProps);
pGeoFeaturelayer.DisplayAnnotation = true;//很重要,必须设置
//axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
}

你可能感兴趣的:(ArcEngine)