YouTube | Facebook | X(Twitter) | RSS

アノテーション フィーチャの追加

2016/9/1 (木)

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();// マップの再描画
}

関連記事

  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

-プログラミング, ArcGIS
-,

WINGFIELD since1981をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む