Create a feature action in your widget

In this topic

A feature action is a piece of code that is requested to execute on one feature or a set of features. Web AppBuilder for ArcGIS provides some out-of-the-box feature actions, such as Zoom To, Export to CSV File, and View in Attribute Table. Additionally, you can create your custom feature action by extending the BaseFeatureAction class. The following steps demonstrate how to create a feature action in the Demo widget that shows the count of vertexes for a selected feature set.

Note:

The complete code is available in the Demo widget. Access the following URL to play the feature action in the Demo widget:

There are two important methods regarding a feature action: isFeatureSupported() and onExecute(). Both of them accept a feature set parameter and an optional layer parameter. The former is invoked to test whether the feature action is supported for the given feature set. Make sure it is returned true or a promise that resolves true if the feature action is supported. The latter is invoked when the feature action is executed. The type of feature set parameter is the FeatureSet class. See FeatureSet class for details. In this example, the feature action does not support point feature sets.

If a feature action in a widget intends to open another widget, for example, the Directions to here feature action in the Select widget is to invoke the Directions widget, use the WidgetManager.getInstance().triggerWidgetOpen(this.widgetId) method.

Declare the feature action in the widget manifest

Label the feature action

Open the string.js file in the Demo/nls folder, and add the following string:

_featureAction_ShowVertex: "Show Vertex Count",

Note:

The pattern of the string key is _featureAction_<feature action name>.

Provide an icon for the feature action

There are two states associated with each feature action: the normal state and the mouse over state. As a result, two images are required for each action.

Copy your image files into the Demo/images folder and name them ShowVertex_default.png and ShowVertex_hover.png.

The name pattern for the image file is <feature action name>_<state>.<image format>. The default image is for the normal state, and hover is for the mouse over state. In addition to PNG, the image format can be JPG or SVG.

Use the feature action

You can use the feature action as an out-of-the-box function or by making calls to the FeatureActionManager API.

For out-of-the-box functions, the feature actions are available in the Select widget, map pop-up, and the result of the Query widget. Using the Select widget as an example, after selecting features, you can click the ellipsis button to see the list of feature actions.

The most important method in the FeatureActionManager API is getSupportedActions(). When you get a feature or feature set, call this method to get all supported feature actions as shown in the following code snippet. You can display them in various formats , such as a link, button, or menu.

FeatureActionManager.getInstance().getSupportedActions(myFeatureSet).then(lang.hitch(this, function(actions){
//create some DOMs to show the actions
}));