How to create a feature action
A custom feature action is a class in an add-in that implements the ESRI.ArcGIS.OperationsCenter.IFeatureAction interface. It must have an Export attribute with the value ESRI.ArcGIS.OperationsDashboard.FeatureAction. It should also have ExportMetadata attributes to set DisplayName, Description and ImagePath attributes.
The simplest way to create a new custom feature action is to use the Feature Action item template in Visual Studio for Operations Dashboard for ArcGIS.
Creating a new feature action
- Open an existing add-in project or create a new one by following the steps in the Getting started topic.
- Click
Project -> Add New Item.
The New Item dialog box appears with the list of installed templates.
- Navigate to Visual C# or Visual Basic > WPF > ArcGIS.
- Select the Operations Dashboard for ArcGIS Feature Action template, enter a Name, and click OK.
The following items are added to the project:
- A FeatureAction.cs/.vb code file. This item defines the custom feature action and provides a default implementation of the IFeaureAction interface.
- An Images folder containing an image file. This item defines the icon for the custom feature action.
Essential elements of a feature action
The following essential elements of a feature action are automatically generated by the item template, with default values and implementation. Edits to these elements may be required when the default implementation is adapted.
- IFeatureAction interface: The IFeatureAction interface must be implemented on a feature action class. This provides the minimum contract for a feature action to be hosted inside a context menu on a widget in the application, defining essential activation and configuration members for custom feature actions. See the API Reference help for information on implementing each member of this interface.
- Export attribute: An Export attribute with the value ESRI.ArcGIS.OperationsDashboard.FeatureAction is required on the feature action class. This attribute is defined in the System.ComponentModel.Composition namespace, part of the .NET Framework that provides the Managed Extensibility Framework (MEF). The application uses MEF to find and load custom add-ins and the types they contain.
- Serializing attributes: A DataContract attribute is required on the feature action class, and DataMember attributes are required on any members which must be serialized to the operation view when the operation view containing the feature action is saved. These attributes are defined in the System.Runtime. Serialization namespace, part of the .NET Framework providing serialization and deserialization support. See the Serializing add-in properties topic for more information.
- Metadata attributes: Three ExportMetadata attributes are required on the feature action class to define information shown about the action before the assembly is loaded, in the Manage Add-Ins dialog box and Capabilities or Feature Actions tabs in configuration dialog boxes. The names of these attributes should be DisplayName, Description, and ImagePath, all with appropriate values. The item template, and sample feature actions, that are part of the SDK demonstrate appropriate values. This attribute is again defined in the System.ComponentModel.Composition namespace.
Optional elements of a feature action
The additional areas of functionality can be implemented on a feature action, if the workflow being developed requires them.
Configuration
Some out-of-the-box feature actions are configurable–they allow the operation view author to alter how the feature action operations. For example, the highlight feature action allows the author to choose whether to zoom or pan to the feature in addition to highlighting it. However, configuration is optional.
To make a feature action configurable, return true from the IFeatureAction.CanConfigure method–the application will then show a configuration button next to the feature action in the list, allowing the author to change settings. If the CanConfigure method returns false, no configuration button is shown. See the API Reference help for other information on implementing the CanConfigure and Configure members of IFeatureAction.
Sending a feature to a widget
Some feature actions are used to send the geometry and attributes of a feature to a widget, to use as input to an operation the widget performs. For example, the Send to chat feature action sends the feature to the chat widget so it can be send to other users in a chat room.
A custom widget and feature action can work together in this way. The feature action can identify instances of the widget it works with by using the Widgets property of the OperationsDashboard class. If no instances are available, the feature action should return false from the CanExecute method. The widget can provide a public member to allow the feature action to pass the feature to the widget.
See the How to find a widget topic for more information on how to find a specific widget in the application.