1. 程式人生 > >ArcEngine 圖層標註 (根據欄位、角度)

ArcEngine 圖層標註 (根據欄位、角度)

用AE來控制圖層是否顯示標註,以及已哪一個欄位作為標註的欄位,以哪一個欄位作為標註的角度,現將程式碼寫下來,以備以後差用。

  1. publicvoid EnableFeatureLayerLabel(IFeatureLayer pFeaturelayer, string sLableField, IRgbColor pRGB, int size, string angleField)  
  2. {  
  3.     //判斷圖層是否為空
  4.     if (pFeaturelayer == null)  
  5.         return;  
  6.     IGeoFeatureLayer pGeoFeaturelayer = (IGeoFeatureLayer)pFeaturelayer;  
  7.     IAnnotateLayerPropertiesCollection pAnnoLayerPropsCollection;  
  8.     pAnnoLayerPropsCollection = pGeoFeaturelayer.AnnotationProperties;  
  9.     pAnnoLayerPropsCollection.Clear();  
  10.     //stdole.IFontDisp  pFont; //字型
  11.     ITextSymbol pTextSymbol;  
  12.     //pFont.Name = "新宋體";
  13.     //pFont.Size = 9;
  14.     //未指定字型顏色則預設為黑色
  15.     if (pRGB == null)  
  16.     {  
  17.         pRGB = new RgbColorClass();  
  18.         pRGB.Red = 0;  
  19.         pRGB.Green = 0;  
  20.         pRGB.Blue = 0;  
  21.     }  
  22.     pTextSymbol = new TextSymbolClass();  
  23.     pTextSymbol.Color = (IColor)pRGB;  
  24.     pTextSymbol.Size = size; //標註大小
  25.     IBasicOverposterLayerProperties4 pBasicOverposterlayerProps4 = new
     BasicOverposterLayerPropertiesClass();  
  26.     switch (pFeaturelayer.FeatureClass.ShapeType)//判斷圖層型別
  27.     {  
  28.         case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:  
  29.             pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;  
  30.             break;  
  31.         case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:  
  32.             pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;  
  33.             break;  
  34.         case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:  
  35.             pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;  
  36.             break;  
  37.     }   
  38.     pBasicOverposterlayerProps4.PointPlacementMethod = esriOverposterPointPlacementMethod.esriRotationField;  
  39.     pBasicOverposterlayerProps4.RotationField = angleField;  
  40.     ILabelEngineLayerProperties pLabelEnginelayerProps = new LabelEngineLayerPropertiesClass();   
  41.     pLabelEnginelayerProps.Expression = "[" + sLableField + "]";  
  42.     pLabelEnginelayerProps.Symbol = pTextSymbol;  
  43.     pLabelEnginelayerProps.BasicOverposterLayerProperties = pBasicOverposterlayerProps4 as IBasicOverposterLayerProperties;  
  44.     pAnnoLayerPropsCollection.Add((IAnnotateLayerProperties)pLabelEnginelayerProps);  
  45.     pGeoFeaturelayer.DisplayAnnotation = true;//很重要,必須設定 
  46.     //axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); }
  47. }