Using HookActions in custom commands


Purpose
This sample demonstrates how to use the IHookActions interface in custom commands to zoom, pan, flash and create graphics, labels, and callouts of selected features. The sample uses the MapControl, GlobeControl, and ToolbarControl in conjunction with the control commands.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Add data and select some features.
  2. Right-click the display to zoom, pan, flash or create graphics, labels, or callouts of selected features.

Additional information

Each custom command uses the HookHelper and GlobeHookHelper object to manage the hook passed to the ICommand.OnCreate event. In the ICommand.OnClick event, the IBasicMap.FeatureSelection method is used to return the feature selection of the IHookHelper.FocusMap or the IGlobeHookHelper.Globe. The geometry of each feature in the feature selection is added to an IArray.
 
The IHookActions.ActionSupportedOnMultiple property is used to determine whether the specified action (zoom, pan, flash, graphic, label, or callout) is supported with the geometries in the array. If the action is supported, the IHookActions.DoActionOnMultiple or IHookActions.DoActionWithNameOnMultiple method is called to perform the specific action. The DoActionWithNameOnMultiple method is used when performing a label or callout action. In addition to passing an array of geometries, an array of strings for labeling is also passed. In this case, that string array contains the value from the first field of each feature.
 
The custom commands are added to a ToolbarMenu using the IToolbarMenu.AddItem method and the ToolbarMenu's hook property is set to the ToolbarControl. In the MapControl and GlobeControl OnMouseDown event, the IToolbarMenu.PopupMenu method is used to display the menu when the right mouse button is clicked.


HookActions.cs Form file.
hookActionsCallout.cs Class file.
hookActionsFlash.cs Class file.
hookActionsGraphic.cs Class file.
hookActionsLabel.cs Class file.
hookActionsPan.cs Class file.
hookActionsZoom.cs Class file.
Download the C# files
HookActions.vb Form file.
hookActionsCallout.vb Class file.
hookActionsFlash.vb Class file.
hookActionsGraphic.vb Class file.
hookActionsLabel.vb Class file.
hookActionsPan.vb Class file.
hookActionsZoom.vb Class file.
Download the VB.NET files

Download the files for all languages

See Also:

HookHelper
GlobeHookHelper
IHookActions




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime: 3D
ArcView: 3D Analyst
ArcEditor: 3D Analyst
ArcInfo: 3D Analyst