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)
{
}
}
}
}