用Label方式添加标注

来源:互联网 发布:阿里巴巴淘宝城规划 编辑:程序博客网 时间:2024/06/10 20:48

        /// <summary>
        /// 用Label方式添加标注
        /// </summary>
        /// <param name="pFeatureLayer">需要Label的Featurelayer</param>
        /// <param name="pFieldName">用于Label的字段名</param>
        public void LableFeature(IFeatureLayer pFeatureLayer, string pFieldName)
        {
            if ((pFeatureLayer == null) || (pFieldName.Equals("")))//传入参数不能为空
            {
                return;
            }
            // 获取MapControl中焦点地图的IActiveView对象
           
            if (activeView == null)
            {
                activeView = this.MapControl.ActiveView.FocusMap as IActiveView;
            }
            /**/
            //IGeoFeatureLayer 对象,要素图层对象
            IGeoFeatureLayer pLabels = new FeatureLayerClass();
            pLabels = pFeatureLayer as IGeoFeatureLayer;

            //IAnnotateLayerProperties 对象
            IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();
            //ILabelEngineLayerProperties 对象
            ILabelEngineLayerProperties pLblEngLyrProps = new LabelEngineLayerPropertiesClass();
           
            //element集合
            IElementCollection pElementColl = null;
            pLabels.AnnotationProperties.QueryItem(0, out pAnnoProps, out pElementColl, out pElementColl);

            pLblEngLyrProps = pAnnoProps as ILabelEngineLayerProperties;
            pLblEngLyrProps.IsExpressionSimple = true;
            pLblEngLyrProps.Expression = pFieldName;
            pLabels.DisplayAnnotation = true;

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

        }

原创粉丝点击