private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouset e)
{
//右クリック以外を除外
if (!(e.button == 2))
{
return;
}
// アノテーション レイヤーの取得
IFeatureLayer pFeatureLayer = (IFeatureLayer)axMapControl1.get_Layer(0);
IAnnotationLayer pAnnotaitonLayer = (IAnnotationLayer)pFeatureLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IAnnotationClassExtension annotationClassExtension = (IAnnotationClassExtenstureClass.Extension;
ISymbol pSymbol = annotationClassExtension.SymbolCollection.get_Symbol(0); lID:0
// テキスト エレメントの作成
IElement pElement = new TextElementClass();
ITextElement pTextElement = (ITextElement)pElement;
IGroupSymbolElement pGroupSymbolElement = (IGroupSymbolElement)pElement;
ISymbolCollectionElement pSymbolCollectionElement = (ISymbolCollectionElemenSymbolElement;
pSymbolCollectionElement.set_SharedSymbol(0, pSymbol); // SymbolID:0
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY); //テキスト エレメントの中心点
pElement.Geometry = pPoint;
pGroupSymbolElement.SymbolID = 0; // SymbolID:0
pTextElement.Text = "アノテーション テキスト";
// 設定の反映(シンボルを設定しないとExtentが同期しません)
ITextSymbol pTextSymbol = pTextElement.Symbol;
pTextElement.Symbol = pTextSymbol;
//アノテーション フィーチャの追加
pAnnotaitonLayer.BeginAddElements(); //エレメント追加の開始
pAnnotaitonLayer.DoAddFeature(null, pElement, 0, 0, esriAnnotationStatus.esrtusPlaced); // エレメント追加の開始
pAnnotaitonLayer.EndAddElements(); // エレメント追加の完了
// アノテーション フィーチャの更新
//IFeature pFeature = pFeatureClass.GetFeature(33);
//IAnnotationFeature pAnnotationFeature = (IAnnotationFeature)pFeature;
////IAnnotationElement pAnnotationElement = (IAnnotationElement)pAnnotationFnnotation; //既存のエレメント情報を取得する場合
//pAnnotationFeature.Annotation = pElement; // 作成したフィーチャ アノテート
//pFeature.Store(); // コミット
axMapControl1.Refresh();// マップの再描画
}
記事
