ArcEngine设置有牵引线的标注

在ArcGIs中很容易就能设置带有牵引线的标注。

ArcEngine设置有牵引线的标注_第1张图片

在ArcEngine中实现方法也很简单。如下:

        /// <summary>
        /// 设置有引线的标注
        /// </summary>
        /// <param name="IN_FeatureLayer">要标注的图层</param>
        /// <param name="IN_Axmapcontrol">显示控件</param>
        private void PRV_SetLabelWithCallout(IFeatureLayer IN_FeatureLayer,AxMapControl IN_Axmapcontrol)
        {
            //设定地图标注引擎
            IAnnotateMap Temp_AnnotateMap = new AnnotateMapClass();
            IN_Axmapcontrol.Map.AnnotationEngine = Temp_AnnotateMap;
            //标注集合
            IGeoFeatureLayer Temp_AnnotationLayer = IN_FeatureLayer as IGeoFeatureLayer;
            IAnnotateLayerPropertiesCollection Temp_AllAnnoProps;
            Temp_AllAnnoProps = Temp_AnnotationLayer.AnnotationProperties;
            Temp_AllAnnoProps.Clear();//清理已有标注属性
            IAnnotateLayerProperties Temp_Anno = PRV_SetPropertiesWithCallout(IN_FeatureLayer, "[OBJECTID]", IN_Axmapcontrol);
            Temp_AllAnnoProps.Add(Temp_Anno);
            IN_Axmapcontrol.AddLayer(IN_FeatureLayer as ILayer);
        }

用到的函数:

        /// <summary>
        /// 设有引线的标注参数
        /// </summary>
        /// <param name="IN_FeatureLayer">要标注的图层</param>
        /// <param name="IN_ClassExpression">标注表达式</param>
        /// <param name="IN_Axmapcontrol">显示控件</param>
        /// <returns>标注参数</returns>
        private IAnnotateLayerProperties PRV_SetPropertiesWithCallout(IFeatureLayer IN_FeatureLayer, string IN_ClassExpression,AxMapControl IN_Axmapcontrol)
        {
            //标注引擎
            ILabelEngineLayerProperties2 Temp_LabelEngine2 = new LabelEngineLayerPropertiesClass();
            IBasicOverposterLayerProperties4 Temp_BasicOverPoster = new BasicOverposterLayerPropertiesClass();
            //表达式
            Temp_LabelEngine2.Expression = IN_ClassExpression;
            //引线
            ILineCallout Temp_Callout = new LineCalloutClass();
            //引线样式
            Temp_Callout.Style = esriLineCalloutStyle.esriLCSMidpoint;
            Temp_Callout.LeaderTolerance = 1;
            //将外框都设为null,这样就只有引线了
            Temp_Callout.Border = null;
            Temp_Callout.AccentBar = null;
            Temp_Callout.Gap = 10;
            //引线类型,这里为点状线
            ISimpleLineSymbol Temp_LineSymbol = new SimpleLineSymbolClass();
            Temp_LineSymbol.Style = esriSimpleLineStyle.esriSLSDot;
            Temp_Callout.LeaderLine = Temp_LineSymbol;
            //文字符号设定
            IFormattedTextSymbol Temp_TextSymbol = new TextSymbolClass();
            //文字颜色
            IRgbColor Temp_RGB = new RgbColorClass();
            Temp_RGB.Red = 0;
            Temp_RGB.Green = 0;
            Temp_RGB.Blue = 0;
            //文字字体与字号
            Temp_TextSymbol = new TextSymbolClass();
            Temp_TextSymbol.Color = (IColor)Temp_RGB;
            Temp_TextSymbol.Size = 18;
            //需要引用stdole.dll
            stdole.IFontDisp Temp_Font = new stdole.StdFontClass() as stdole.IFontDisp;
            Temp_Font.Name = "Arial";
            Temp_TextSymbol.Background = Temp_Callout as ITextBackground;
            Temp_TextSymbol.Font = Temp_Font;
            Temp_LabelEngine2.Symbol = Temp_TextSymbol as ITextSymbol;
            //标注放置方式
            switch (IN_FeatureLayer.FeatureClass.ShapeType)//判断图层类型
            {
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                    Temp_BasicOverPoster.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
                    Temp_BasicOverPoster.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriAlwaysHorizontal;
                    break;
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                    Temp_BasicOverPoster.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
                    Temp_BasicOverPoster.PointPlacementMethod = esriOverposterPointPlacementMethod.esriAroundPoint;
                    break;
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                    Temp_BasicOverPoster.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
                    break;
            }
            Temp_LabelEngine2.BasicOverposterLayerProperties = Temp_BasicOverPoster as IBasicOverposterLayerProperties;
            //设定标注
            IMapOverposter Temp_MapPos = IN_Axmapcontrol.Map as IMapOverposter;
            IOverposterProperties Temp_OverPoster = Temp_MapPos.OverposterProperties;
            IAnnotateLayerProperties Temp_AnnoPClass = Temp_LabelEngine2 as IAnnotateLayerProperties;
            (IN_FeatureLayer as IGeoFeatureLayer).DisplayAnnotation = true;
            return Temp_AnnoPClass;
        }

效果如图:

ArcEngine设置有牵引线的标注_第2张图片

你可能感兴趣的:(绘图,输出,标注,ArcEngine,ArcgisEngine)