arcgis中可以在同一个图层中定义不同的标注方式。
在ArcgisEngine中实现起来如下(以按OID为条件区分为例):
/// <summary> /// 标注特定图层 /// </summary> /// <param name="IN_Layer">要标注的图层</param> /// <param name="IN_AxmapControl">要标注的地图控件</param> public void PUB_ShowTargetFeature(ILayer IN_Layer,AxMapControl IN_AxmapControl) { //设定地图标注引擎 IAnnotateMap Temp_AnnotateMap = new AnnotateMapClass(); IN_AxmapControl.Map.AnnotationEngine = Temp_AnnotateMap; //获取GeoFeaturelayer IGeoFeatureLayer Temp_AnnotationLayer = IN_Layer as IGeoFeatureLayer; //标注集合 IAnnotateLayerPropertiesCollection Temp_AllAnnoProps; Temp_AllAnnoProps = Temp_AnnotationLayer.AnnotationProperties; Temp_AllAnnoProps.Clear();//清理已有标注属性 //定义两种标注类并添加 IAnnotateLayerProperties Temp_Anno1 = PRV_SetProperties(Temp_AnnotationLayer, PRV_SetSymbol(null, 8, "Arial"), IN_AxmapControl, "DefaultClass", " OBJECTID >100 ", "[Shape_Length] & vbnewline &\"———\" &vbnewline& [Shape_Area]"); Temp_AllAnnoProps.Add(Temp_Anno1); IAnnotateLayerProperties Temp_Anno2 = PRV_SetProperties(Temp_AnnotationLayer, PRV_SetSymbol(null, 8, "Arial"), IN_AxmapControl, "Class1", " OBJECTID < 100 ", "[OBJECTID]"); Temp_AllAnnoProps.Add(Temp_Anno2); }
下面是该函数的辅助函数:
/// <summary> /// 设定标注 /// </summary> /// <param name="IN_FeatureLayer">要设定标注的图层</param> /// <param name="IN_Symbol">标注表达式</param> /// <param name="IN_AxmapControl">显示控件</param> /// <param name="IN_ClassName">定义该种标注类型</param> /// <param name="IN_ClassQuery">该种筛选方式</param> /// <param name="IN_ClassExpression">标注表达式</param> /// <returns>标注参数</returns> private IAnnotateLayerProperties PRV_SetProperties(IFeatureLayer IN_FeatureLayer, ITextSymbol IN_Symbol, AxMapControl IN_AxmapControl, string IN_ClassName, string IN_ClassQuery, string IN_ClassExpression) { //标注表达式 ILabelEngineLayerProperties Temp_LabelEngine2 = new LabelEngineLayerPropertiesClass(); Temp_LabelEngine2.Expression = IN_ClassExpression; //文字符号设定 Temp_LabelEngine2.Symbol = IN_Symbol; //用来控制标注和要素的相对位置关系 ILineLabelPosition Temp_LineLpos = new LineLabelPositionClass(); Temp_LineLpos.Parallel = false;//修改标注的属性 Temp_LineLpos.Perpendicular = false; Temp_LineLpos.InLine = true; Temp_LineLpos.Above = false; //用优先级来控制标注冲突 ILineLabelPlacementPriorities Temp_LinePlace = new LineLabelPlacementPrioritiesClass(); Temp_LinePlace.AboveStart = 1; Temp_LinePlace.BelowAfter = 1; //用来实现对ILineLabelPosition 和 ILineLabelPlacementPriorities以及更高级属性的控制 IBasicOverposterLayerProperties Temp_BasicOverPoster = new BasicOverposterLayerPropertiesClass(); Temp_BasicOverPoster.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon; Temp_BasicOverPoster.LineLabelPlacementPriorities = Temp_LinePlace; Temp_BasicOverPoster.LineLabelPosition = Temp_LineLpos; Temp_LabelEngine2.BasicOverposterLayerProperties = Temp_BasicOverPoster; //设定标注 IMapOverposter Temp_MapPos = IN_AxmapControl.Map as IMapOverposter; IOverposterProperties Temp_OverPoster = Temp_MapPos.OverposterProperties; IAnnotateLayerProperties Temp_AnnoPClass = Temp_LabelEngine2 as IAnnotateLayerProperties; //设定名称与筛选方式 Temp_AnnoPClass.Class = IN_ClassName; Temp_AnnoPClass.WhereClause = IN_ClassQuery; (IN_FeatureLayer as IGeoFeatureLayer).DisplayAnnotation = true; return Temp_AnnoPClass; } /// <summary> /// 设定标注符号 /// </summary> /// <param name="IN_TextColor">字体颜色</param> /// <param name="IN_TextSize">字体大小</param> /// <param name="IN_FontName">字体名称</param> /// <returns></returns> private ITextSymbol PRV_SetSymbol(IRgbColor IN_TextColor,int IN_TextSize,string IN_FontName) { ITextSymbol Temp_TextSymbol = new TextSymbolClass(); ; //文字颜色 if (IN_TextColor == null) { IN_TextColor = new RgbColorClass(); IN_TextColor.Red = 0; IN_TextColor.Green = 0; IN_TextColor.Blue = 0; Temp_TextSymbol.Color = (IColor)IN_TextColor; } //文字字体与字号 Temp_TextSymbol.Size = IN_TextSize; stdole.IFontDisp Temp_Font = new stdole.StdFontClass() as stdole.IFontDisp; Temp_Font.Name = IN_FontName; Temp_TextSymbol.Font = Temp_Font; return Temp_TextSymbol; }
时间: 2024-10-05 04:07:34