FAQ
ArcGIS Pro SDK: ギャラリーの追加

ナレッジ番号:3356 | 登録日:2023/05/29 | 更新日:2024/12/02

概要

ArcGIS Pro SDK では、ボタンだけでなくギャラリーを追加することができます。ギャラリーには複数のギャラリー アイテムを追加することができ、グループを設定して分類することができます。
ここでは、カレント プロジェクトに挿入されたマップを取得し、そのタイプ (マップあるいはシーン) に応じてグループ表示するためのギャラリーを追加します。

サンプル コード

コード内の<>は半角に置き換えてからサンプル コードをご利用ください。

config.daml

ギャラリーの外観を daml ファイルで定義します。「galleries」カテゴリで、ギャラリー内に表示するギャラリー アイテムの列数 (itemsInRow) や、グループを表示するか (showGroup) といったプロパティを設定します。

XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<groups>
  <!-- comment this out if you have no controls on the Addin tab to avoid
        an empty group-->
  <group appearsonaddintab="true" caption="ギャラリー" id="MapListGallery_Group1">
    <!-- host controls within groups -->
    <gallery inline="false" refid="MapListGallery_Gallery1" size="large">
  </gallery></group>
</groups>
<controls>
  <!-- add your controls here -->
</controls>
<galleries>
  <gallery caption="マップリスト" classname="Gallery1" datatemplatefile="pack://application:,,,/MapListGallery;component//Gallery1Template.xaml" id="MapListGallery_Gallery1" itemsinrow="5" itemwidth="50" largeimage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonOrange32.png" resizable="true" showgroup="true" templateid="Gallery1ItemTemplate">
    <tooltip heading="Tooltip Heading">Tooltip text</disabledtext></tooltip>
  </gallery>
</galleries>

Garally クラス

Garally クラスに、ギャラリーの処理を記述していきます。Initialize メソッドを実行した際に、ギャラリーにギャラリーアイテムを追加する処理を記述します。

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private void Initialize()
{
    if (_isInitialized)
        return;
 
    //プロジェクトのマップを取得
    var maps= Project.Current.GetItems<MapProjectItem>();
    //マップの数だけループ
    foreach (var map in maps)
    {
        //マップの名称を取得
        string mapname = map.Name;
        //マップ名のギャラリーアイテムを追加
        //グループ名はMap クラスの MapType プロパティから取得
        Add(new GalleryItem(mapname, this.LargeImage != null ? ((ImageSource)this.LargeImage).Clone() : null, mapname, map.MapType.ToString()));
 
    }
    _isInitialized = true;
 
}

OnClick イベント内で、クリックしたギャラリー アイテムをもとに処理を実装します。ここでは、クリックしたマップを開く処理を実装します。

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
protected async override void OnClick(GalleryItem item)
{
    //TODO - insert your code to manipulate the clicked gallery item here
    System.Diagnostics.Debug.WriteLine("Remove this line after adding your custom behavior.");
    base.OnClick(item);
    //クリックしたギャラリーアイテムからマップ アイテムを取得
    var mapItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(
                                        m => (m.Name ==  item.Text));
    await QueuedTask.Run(() =>
    {
     //マップアイテムから Map オブジェクトを取得
        Map map = mapItem.GetMap();
  //マップ ビューを開く
        ProApp.Panes.CreateMapPaneAsync(map);
    });
}

参考情報

メタデータ

種類

製品