VS2010--AE10.2--------------Annotation标注

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Controls;
using txtAnnotation标注.Label;
using ESRI.ArcGIS.Animation;
using ESRI.ArcGIS.esriSystem;
using txtAnnotation标注.Class;
using stdole;
using ESRI.ArcGIS.SystemUI;




namespace txtAnnotation标注
{
    public partial class Form1 : Form
    {
        private OperateMap m_OperateMap = null;
        private frmAnnotation frmAnnotation = null;  // 注记
        public Form1()
        {
            InitializeComponent();
            m_OperateMap = new OperateMap();
        }


        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ICommand Cmd = new ControlsOpenDocCommandClass();
            Cmd.OnCreate(mainMapControl.Object);
            Cmd.OnClick();
        }


        private void txtAnnotation_Click(object sender, EventArgs e)
        {
            try
            {
                if (frmAnnotation == null || frmAnnotation.IsDisposed)
                {
                    frmAnnotation = new frmAnnotation();
                    frmAnnotation.Annotation += new frmAnnotation.AnnotationEventHandler(frmAnnotation_Annotation);
                }
                frmAnnotation.Map = mainMapControl.Map;
                frmAnnotation.InitUI();
                frmAnnotation.ShowDialog();
            }
            catch (Exception ex)
            {
            }
        }
        void frmAnnotation_Annotation(string sFeatClsName, string sFieldName)
        {
            IFeatureLayer pFeatLyr = m_OperateMap.GetFeatLyrByName(mainMapControl.Map, sFeatClsName);
            Annotation(pFeatLyr, sFieldName);
        }
        /// <summary>
        /// 注记
        /// </summary>
        /// <param name="pFeatLyr">注记图层名称</param>
        /// <param name="sFieldName">注记字段</param>
        private void Annotation(IFeatureLayer pFeatLyr, string sFieldName)
        {
            try
            {
                IGeoFeatureLayer pGeoFeatLyer = pFeatLyr as IGeoFeatureLayer;
                IAnnotateLayerPropertiesCollection pAnnoProps = pGeoFeatLyer.AnnotationProperties;
                pAnnoProps.Clear();
                //设置标注记体格式                                                                     
                ITextSymbol pTextSymbol = new TextSymbolClass();
                stdole.StdFont pFont = new stdole.StdFontClass();
                pFont.Name = "verdana";
                pFont.Size = 10;
                pTextSymbol.Font = pFont as stdole.IFontDisp;
                //设置注记放置格式
                ILineLabelPosition pPosition = new LineLabelPositionClass();
                pPosition.Parallel = false;
                pPosition.Perpendicular = true;
                ILineLabelPlacementPriorities pPlacement = new LineLabelPlacementPrioritiesClass();
                IBasicOverposterLayerProperties pBasic = new BasicOverposterLayerPropertiesClass();
                pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
                pBasic.LineLabelPlacementPriorities = pPlacement;//设置标注文本摆设路径权重
                pBasic.LineLabelPosition = pPosition;//控制文本的排放位置
                ILabelEngineLayerProperties pLableEngine = new LabelEngineLayerPropertiesClass();
                pLableEngine.Symbol = pTextSymbol;
                pLableEngine.BasicOverposterLayerProperties = pBasic;//设置标注文本的放置方式,以及处理文字间冲突的处理方式等
                pLableEngine.Expression = "[" + sFieldName + "]";//输入VBScript或JavaScript语言,设置要标注的字段
                IAnnotateLayerProperties pAnnoLayerProps = pLableEngine as IAnnotateLayerProperties;
                pAnnoProps.Add(pAnnoLayerProps);
                pGeoFeatLyer.DisplayAnnotation = true;
                mainMapControl.Refresh(esriViewDrawPhase.esriViewBackground, null, null);
                mainMapControl.Update();
            }
            catch (Exception ex)
            {


            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/sinat_25006091/article/details/79834413
AE