ArcEngine 圖層標註 (根據欄位、角度)
阿新 • • 發佈:2019-01-23
用AE來控制圖層是否顯示標註,以及已哪一個欄位作為標註的欄位,以哪一個欄位作為標註的角度,現將程式碼寫下來,以備以後差用。
- publicvoid 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
- 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); }
- }