ツールの作成

ツールを使用すると、ユーザによって開始されるロジックを ArcGIS Map Web パーツへ容易に実装できます。リボンのボタンをユーザがクリックしたときに特定の機能が開始されるようにする場合は、その機能をツールとしてカプセル化します。

Map Web パーツでは、ICommand インタフェースを使用してコマンド(ツール)を実装します。このインタフェースはいくつかの単純なメンバーで構成されます。Map Web パーツでは、これらのメンバーを次のように使用します。

これらのメンバーの実装に加え、ICommand を実装するクラスに 2 つの属性を追加する必要があります。その 1 つは System.ComponentModel.Composition.ExportAttribute です。この属性は、Managed Extensibility Framework(MEF)を構成する System.ComponentModel.Composition アセンブリに含まれています。この属性は、対象コマンドをリボンに追加する必要があることを Map Web パーツに通知します。実装するコマンドにこの属性を追加するときは、必ず次の形式を使用します。

[Export(typeof(ICommand))]
public class MyCommand : ICommand

追加するもう 1 つの属性は ESRI.ArcGIS.Client.Extensibility.DisplayNameAttribute です。この属性は、デザイン担当者が対象コマンドを Map Web パーツへ追加するときに表示されるコマンド名を指定します。この属性は次のように指定します。

[Export(typeof(ICommand))]
[DisplayName("<Name to display>")]
public class MyCommand : ICommand

次に、単純なコマンドのコード例を示します。このコマンドはメッセージ ボックスを表示し、マップが NULL でない場合に有効になります。その場合、CanExecuteChanged イベントは使用されません。

[Export(typeof(ICommand))]
[DisplayName("Simple Command")]
public class SimpleCommand : ICommand
{
     public void Execute(object parameter)
     {
          // Show a message box when the command's ribbon button is clicked.
          MessageBox.Show("Simple command executed");
     } 
 
     public bool CanExecute(object parameter)
     {
          // Show as executable (i.e., enable the button on the ribbon) unless the map is null.
          return MapApplication.Current.Map != null;
     }
 
     public event EventHandler CanExecuteChanged;
}

6/8/2012