Common Add custom tool


Purpose
This sample demonstrates how to add a custom tool, command, and drop-down list to a Web application using the Web Application Developer Framework (ADF). Custom tools include the following:
  • Identify
  • Zoom to point
  • Hyperlink
No specific data source type is required. This sample works with data sources (such as ArcGIS Server, ArcIMS, and OGC\WMS) that implement the IMapFunctionality Common Data Source application programming interface (API) (the Common API).
 
The Identify and Hyperlink tools work with data sources (such as ArcGIS Server, ArcIMS) that implement the IQueryFunctionality Common API interface.
 
The Previous and Next commands show how to manually manage extent history. The Web ADF also includes a set of out-of-the-box commands to manage extent history.
 
In this sample, it is assumed that a map service called "USA" has been created from the USA map document included with the sample data.

How to use

Data has been provided for your use with this sample. It can be found at <Your ArcGIS Developer Kit Install directory>/Samples/data/USA/USA.mxd.
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.

At design time
  1. Verify that the Web ADF for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNET. This folder contains Common_AddCustomTool CSharp and VBNet folders.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the Common_AddCustomTool_<language><vs_version> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet. The <vs_version> references the Visual Studio version of the solution , either 2008 or 2010.
  4. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
  5. In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site, expand Default Web Site, right-click the Common_AddCustomTool_<language> folder, and click Properties. The Properties dialog box opens.
  6. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  7. Start Microsoft Visual Studio 2008 or 2010 and open the Common_AddCustomTool_<language><vs_version> solution (for example, Common_AddCustomTool_CSharp2008.sln) located in c:\inetpub\wwwroot\Common_AddCustomTool_<language>.
  8. In Solution Explorer, right-click Default.aspx and select Set As Start Page.
  9. Open the Default.aspx page in Design view, open the properties window for the MapResourceManager control, and click the ellipsis next to the ResourceItems property. The ResourceItem Collection Editor dialog box opens.
  10. Add or change the MapResourceItem associated with a map service (ArcGIS Server, ArcIMS, and so on).
  11. If necessary, set the run time identity of the Web application by following one of the next two steps. If not necessary, proceed to step 14.
  12. At design time, the identity of the user running Visual Studio is used to connect to an ArcGIS Server local data source. At run time, that identity is established by the Web application. Only one identity can be used to define access to the ArcGIS Server local data sources in a single Web application. This identity can be explicitly defined when building the Web ADF application in Visual Studio by right-clicking the Web project in Solution Explorer and selecting the Add ArcGIS Identity option. Enter the identity credentials that will be used to access ArcGIS Server local resources at run time. This information is added to the web.config file in a standard ASP.NET identity tag. If the Encrypt identity in web.config check box is checked, the identity tag will be encrypted; otherwise, the username and password are stored as clear text.
  13. Open the web.config file, add an <identity> element in <system.web>, set the impersonate attribute to true, and add a username and password attribute and set them to a valid user account. If you're working with ArcGIS Server local data sources, ensure the account has access to the geographic information system (GIS) server resources referenced in the Map control.
  14. Save the project.
  15. Click the Debug drop-down menu and click Start Debugging.

At run time
  1. Browse to the viewer uniform resource locator (URL) (for example, http://localhost/Common_AddCustomTool_CSharp).
  2. On the toolbar above the map, click Identify All.
  3. Click an area of the map where features in more than one layer are present. All feature attributes in each layer (a single MapResourceItem can contain multiple layers) that intersect the location of the click event are returned in a GridView below the map. One GridView is returned for each layer. The title of the table consists of the MapResourceInfo item name, the layer ID, and the layer name.
  4. Click the Zoom to Point tool and click the map. The map centers on the click and zooms in.
  5. Click the Hyperlink tool and click a U.S. state on the map. A new browser window opens to perform a search using Google.
  6. Click the Extent Command button on the toolbar. As a command, the action occurs when the button is clicked. In this case, the extent of the map changes to include the southwest U.S. in decimal degrees. If the map is not associated with a geographic coordinate system, this command might not function as expected. To change the extent, open the CustomToolLibrary code file and modify the ExtentCommand class.
  7. Click the drop-down list to select a direction to pan the map. Four directions are provided: NorthWest, NorthEast, SouthWest, and SouthEast.
  8. Click the PreviousExtent and NextExtent commands below the map to traverse the array of extents viewed.

Common_AddCustomTool_CSharp\Default.aspx User interface for the Web application.
Common_AddCustomTool_CSharp\Default.aspx.cs Code behind the user interface.
Common_AddCustomTool_CSharp\App_Code\CustomToolLibrary.cs Class library containing implementation of custom tools, commands, and drop-down lists.
Common_AddCustomTool_CSharp\App_Code\IBaseToolbarRefresh.cs Interface implemented by the page for custom classes to interact with custom page content. In this case, it's used by custom classes in App_Code to refresh a toolbar in the page and synchronize the client (browser) with the Web application state.
Download the C# files
Common_AddCustomTool_VBNet\Default.aspx User interface for the Web application.
Common_AddCustomTool_VBNet\Default.aspx.vb Code behind the user interface.
Common_AddCustomTool_VBNet\App_Code\CustomToolLibrary.vb Class library containing implementation of custom tools, commands, and drop-down lists.
Common_AddCustomTool_VBNet\App_Code\IBaseToolbarRefresh.vb Interface implemented by the page for custom classes to interact with custom page content. In this case, it's used by custom classes in App_Code to refresh a toolbar in the page and synchronize the client (browser) with the Web application state.
Download the VB.NET files

Download the files for all languages