ツールの作成

ツールを使用すると、ArcGIS Viewer for Silverlight で、ユーザによる操作から開始するロジックを簡単に実装できます。ツールバーのボタンをクリックして開始させるのが適した機能を実装する場合は、その機能をツール内にカプセル化する必要があります。

詳細については、「ベスト プラクティス: はじめに」および「ArcGIS Viewer for Silverlight の拡張」をご参照ください。

ビューアでは、ICommand インタフェースをツールとして実装したオブジェクトを呼び出すことができます。このインタフェースはいくつかの単純なメンバーで構成されます。ビューアでは、これらのメンバーは次のように使用されます。

これらのメンバーの実装に加え、ICommand を実装するクラスに 2 つの属性を追加する必要があります。1 つめに追加する属性は System.ComponentModel.Composition.ExportAttribute で、これは、Microsoft の Managed Extensibility Framework(MEF)の一部として提供される System.ComponentModel.Composition アセンブリに含まれています。この属性は、ツールバーに追加するツールが使用可能かどうかをビューアに伝えます。実装するツールにこの属性を含める場合は、常に次のような形式になります。

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

追加する必要があるもう 1 つの属性は、ESRI.ArcGIS.Client.Extensibility.DisplayNameAttribute です。この属性は、ツールをビューアに追加するときに設計者に対して表示される、ツール名を決めるものです。ESRI.ArcGIS.Client.Extensibility アセンブリから指定できる追加のオプション属性には、CategoryAttribute、DefaultIconAttribute、DescriptionAttribute などがあります。この属性は次のように指定します。

[Export(typeof(ICommand))]
[DisplayName("Simple Command")]
[Category("My Tools")]
[Description("Simple tool with MessageBox")]
[DefaultIcon("Path to icon, ex: "/Viewer.Addins;component/Images/SimpleTool.png"")]
public class MyCommand : ICommand

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

[Export(typeof(ICommand))]
[DisplayName("Simple Command")]
[Category("My Tools")]
[Description("Simple tool with MessageBox")]
[DefaultIcon("Path to icon, ex: "/Viewer.Addins;component/Images/SimpleTool.png"")]
public class MyCommand : ICommand
{
     public void Execute(object parameter)
     {
          // Show a message box when the tool's button is clicked.
          MessageBox.Show("Simple tool executed");
     } 
 
     public bool CanExecute(object parameter)
     {
          // Show as executable (i.e., enable the button on the toolbar) unless the map is null.
          return MapApplication.Current.Map != null;
     }
 
     public event EventHandler CanExecuteChanged;
}

1/23/2014