How to use swipe tools and transparency commands


Summary
This topic shows how to use the out-of-the-box 2D and 3D swipe tools and transparency commands with ArcGIS Engine controls.

In this topic


Using the 2D swipe tool and transparency commands

To successfully utilize the ControlsMapSwipeTool and ControlsLayerTransparencyCommand on a ToolbarControl buddied to a MapControl or PageLayoutControl, use the commands in conjunction with the CommandsEnvironment singleton object and the ControlsLayerListToolControl.
When a user selects a layer from the ControlsLayerListToolControl, this layer is set to the ILayerEffectProperties.setSwipeLayerByRef() and ILayerEffectProperties.setTransparencyLayerByRef() methods on the CommandsEnvironment singleton object. The ControlsMapSwipeTool and ControlsLayerTransparencyCommand use the ILayerEffectProperties.getSwipeLayer() and ILayerEffectProperties.getTransparencyLayer() methods to determine the layer to swipe or make transparent. 
Failure to instantiate the CommandsEnvironment singleton object, results in the ControlsMapSwipeTool and ControlsLayerTransparencyCommand internally using their instance of the CommandsEnvironment object and appearing disabled to the user. The following code example assumes a MapBean has been initialized in an ArcGIS visual Java bean application:
[Java]
/* Create the CommandsEnvironment singleton object 
 * to support the swipe and transparency tool.
 * The singleton object must be a class member to prevent it from going out of scope;
 * otherwise, the CommandsEnvironment singleton will be garbage collected and the tool will be disabled.
 */

private CommandsEnvironment commandsEnv;


private ToolbarBean getToolbarBean(){
    if (toolbarBean == null){
        toolbarBean = new ToolbarBean();
        try{
            toolbarBean.setBuddyControl(mapBean);
            commandsEnv = new CommandsEnvironment();
            toolbarBean.addItem(ControlsOpenDocCommand.getClsid(), 0,  - 1, false, 0,
                esriCommandStyles.esriCommandStyleIconOnly); //open
            toolbarBean.addItem(ControlsMapNavigationToolbar.getClsid(), 0,  - 1,
                false, 0, esriCommandStyles.esriCommandStyleIconOnly); //open
            /*
             * To set the transparency and swipe layer interactively at runtime,
             *  add the ControlsLayerListToolControl item to the toolbar. 
             */
            toolbarBean.addItem(ControlsLayerListToolControl.getClsid(), 0,  - 1,
                false, 0, esriCommandStyles.esriCommandStyleIconOnly); //open
            toolbarBean.addItem(ControlsMapSwipeTool.getClsid(), 0,  - 1, false, 0,
                esriCommandStyles.esriCommandStyleIconOnly); //open
            toolbarBean.addItem(ControlsLayerTransparencyCommand.getClsid(), 0,  - 1,
                false, 0, esriCommandStyles.esriCommandStyleIconOnly); //open
        }
        catch (IOException e){
            e.printStackTrace();
        }
    }
    return toolbarBean;
}

Using the 3D swipe tool

To successfully utilize the ControlsGlobeSwipeTool on a ToolbarControl buddied to a GlobeControl, use the command in conjunction with the CommandsEnvironment singleton object and the ControlsGlobeLayerListToolControl.
When an end user selects a layer from the ControlsGlobeLayerListToolControl, this layer is set to the ILayerEffectProperties.setSwipeLayerByRef() method on the CommandsEnvironment singleton object. The ControlsGlobeSwipeTool uses the ILayerEffectProperties.getSwipeLayer() method to determine the layer to swipe.
Failure to instantiate the CommandsEnvironment singleton object results in the ControlsGlobeSwipeTool internally using its instance of the CommandsEnvironment object and appearing disabled to the user.
The following code example assumes GlobeBean has been initialized in the ArcGIS Engine visual Java bean application:
[Java]
//Create a member variable CommandsEnvironment singleton object.
private CommandsEnvironment commandsEnv;

private ToolbarBean getToolbarBean(){
    if (toolbarBean == null){
        toolbarBean = new ToolbarBean();
        try{
            toolbarBean.setBuddyControl(globeBean());
            commandsEnv = new CommandsEnvironment();
            toolbarBean.addItem(ControlsGlobeOpenDocCommand.getClsid(), 0,  - 1,
                false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            toolbarBean.addItem(ControlsMapNavigationToolbar.getClsid(), 0,  - 1,
                false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            /*
             * To set the transparency and swipe layer interactively at runtime,
             *  add the ControlsGlobeLayerListToolControl item to the toolbar. 
             */
            toolbarBean.addItem(ControlsGlobeLayerListToolControl.getClsid(), 0,  -
                1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            toolbarBean.addItem(ControlsGlobeSwipeTool.getClsid(), 0,  - 1, false, 0,
                esriCommandStyles.esriCommandStyleIconOnly);
        }
        catch (IOException e){
            e.printStackTrace();
        }
    }
    return toolbarBean;
}
The ControlsLayerTransparencyCommand works only with 2D MapControl and PageLayoutControl, and not with 3D GlobeControl or SceneControl.


See Also:

Sample: Swipe and transparency commands
How to use the Roam tool
How to use Flicker and NearbyPlaces command
CommandsEnvironment class
ILayerEffectProperties interface
ControlsMapSwipeTool class
ControlsGlobeSwipeTool class
ControlsLayerTransparencyCommand class
ControlsLayerListToolControl class
ControlsGlobeLayerListToolControl class
Singleton objects




Development licensingDeployment licensing
Engine Developer KitEngine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced