ArcGIS Add graphics


Purpose
This sample demonstrates how to add custom graphics to an ArcGIS Server service and display the results in a Web Application Developer Framework (ADF) Map control. In a Web ADF application, graphics can be drawn in the client tier (browser), web tier (Web application), or server tier (map service). In this sample, graphics are drawn in the server tier using data source specific capabilities of an ArcGIS Server map service exposed via the ArcGIS Server SOAP application programming interface (API).
 
This sample contains a Web ADF toolbar, tools, and a command. The tools illustrate how to add text and geometry (point, line, and polygon) to an ArcGIS Server data source, both local and Internet. The ArcGIS Server SOAP API is utilized via a set of value objects and a Web service (Internet data source) and Distributed Component Object Model (DCOM) proxy (local data source) to the ArcGIS Server service.
 
The value objects provide a set of native .NET classes to create and define properties of graphic elements on the client. The ArcGIS Server MapFunctionality object provides a MapDescription property to access the Web ADF-managed MapDescription value object. Graphic elements can be added to the ArcGIS Server service via the MapDescription.CustomGraphics property. Modifications to the MapDescription are maintained in session state by the Web ADF. Custom graphic elements that are added are retained across requests to the server.

How to use

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 ArcGIS_AddGraphics CSharp and VBNet folders.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the ArcGIS_AddGraphics_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  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 ArcGIS_AddGraphics_<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). Open the solution for the version of Visual Studio you're using. The Visual Studio version is appended to the solution file name. For example, the Visual Studio 2008 solution file is ArcGIS_AddGraphics_CSharp2008.sln and is located in the c:\inetpub\wwwroot\ArcGIS_AddGraphics_CSharp folder.
  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 of 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 an ArcGIS Server map service.
  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 is 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.

At run time
  1. Browse to the viewer uniform resource locator (URL) (for example, http://localhost/ArcGIS_AddGraphics_CSharp).
  2. In the toolbar above the map, click Add Text Tool, and click the map. The Text tool is added to the map.
  3. Click Add Text Command. The Text command is drawn on the map image at the image pixel location 200,200 (from the upper left corner of the image).
  4. Click Add Point Tool and click the map. A green diamond point graphic is added to the map.
  5. Click Add Polyline Tool, click the map, and digitize a line. Double-click to finish digitizing. A green line graphic is added to the map.
  6. Click Add Polygon Tool, click the map, and digitize a polygon. Double-click to finish digitizing. A solid green polygon graphic is added to the map.
  7. Click the Clear Graphics button to clear all ArcGIS Server graphics from the map.

ArcGIS_AddGraphics_CSharp\Default.aspx Contains the Web user interface (UI) to interact with server-side code.
ArcGIS_AddGraphics_CSharp\Default.aspx.cs Code behind the .aspx file. References Web ADF libraries and functionality.
ArcGIS_AddGraphics_CSharp\App_Code\TextTool.cs Implementation class for custom tool to create a text graphic element.
ArcGIS_AddGraphics_CSharp\App_Code\PointTool.cs Implementation class for custom tool to create a point graphic element.
ArcGIS_AddGraphics_CSharp\App_Code\PolylineTool.cs Implementation class for custom tool to create a polyline graphic element.
ArcGIS_AddGraphics_CSharp\App_Code\PolygonTool.cs Implementation class for custom tool to create a polygon graphic element.
Download the C# files
ArcGIS_AddGraphics_VBNet\Default.aspx Contains the Web user interface (UI) to interact with server-side code.
ArcGIS_AddGraphics_VBNet\Default.aspx.vb Code behind the .aspx file. References Web ADF libraries and functionality.
ArcGIS_AddGraphics_VBNet\App_Code\TextTool.vb Implementation class for custom tool to create a text graphic element.
ArcGIS_AddGraphics_VBNet\App_Code\PointTool.vb Implementation class for custom tool to create a point graphic element.
ArcGIS_AddGraphics_VBNet\App_Code\PolylineTool.vb Implementation class for custom tool to create a polyline graphic element.
ArcGIS_AddGraphics_VBNet\App_Code\PolygonTool.vb Implementation class for custom tool to create a polygon graphic element.
Download the VB.NET files

Download the files for all languages