ArcEngine 图层标注 (根据字段、角度)

转自chanyinhelv原文 ArcEngine 图层标注 (根据字段、角度)

今天做了一个用AE来控制图层是否显示标注,以及已哪一个字段作为标注的字段,以哪一个字段作为标注的角度,现将代码写下来,以备以后差用。

public void EnableFeatureLayerLabel(IFeatureLayer pFeaturelayer, string sLableField, IRgbColor pRGB, int size, string angleField)  
{  
    //判断图层是否为空  
    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; //标注大小  
  
    IBasicOverposterLayerProperties4 pBasicOverposterlayerProps4 = new BasicOverposterLayerPropertiesClass();  
    switch (pFeaturelayer.FeatureClass.ShapeType)//判断图层类型  
    {  
        case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:  
            pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;  
            break;  
        case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:  
            pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;  
            break;  
        case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:  
            pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;  
            break;  
    }   
    pBasicOverposterlayerProps4.PointPlacementMethod = esriOverposterPointPlacementMethod.esriRotationField;  
    pBasicOverposterlayerProps4.RotationField = angleField;  
  
    ILabelEngineLayerProperties pLabelEnginelayerProps = new LabelEngineLayerPropertiesClass();   
    pLabelEnginelayerProps.Expression = "[" + sLableField + "]";  
    pLabelEnginelayerProps.Symbol = pTextSymbol;  
    pLabelEnginelayerProps.BasicOverposterLayerProperties = pBasicOverposterlayerProps4 as IBasicOverposterLayerProperties;  
    pAnnoLayerPropsCollection.Add((IAnnotateLayerProperties)pLabelEnginelayerProps);  
    pGeoFeaturelayer.DisplayAnnotation = true;//很重要,必须设置   
    //axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); }  
}  

 

posted @ 2017-01-08 18:13  wenglabs  阅读(395)  评论(0编辑  收藏  举报