Common Add graphics


Purpose
This sample demonstrates how to add and use custom graphic layers with a Map control. There are two types of Web Application Developer Framework (ADF) graphics: client and server.
 
The Web ADF includes client-side graphic components as part of the public Web ADF JavaScript Library. The client-side graphics layer (GraphicsFeatureGroup) can be constructed via custom JavaScript or generated by the server if a server-side graphics layer is rendered on the client (GraphicsLayer.RenderOnClient property).
 
On the server side, a Web ADF graphics resource is essentially a spatially enabled .NET DataSet, managed "in memory" on the server (Web tier). As a dataset, a graphics resource can consist of one or more data tables. A graphics layer, created programmatically using the Web ADF, is a spatially enabled .NET DataTable. There are two types of graphics layers: Element and Feature. An ElementGraphicsLayer stores graphic elements for simple display in a map. A single ElementGraphicsLayer can store graphics that reference different geometry types where each piece of geometry is associated with a default, selected, and highlight symbol. A FeatureGraphicsLayer is designed to store feature geometry with custom attributes. A single FeatureGraphicsLayer can store features with the same type of geometry, and apply simple and complex renderers for display.
 
This sample demonstrates how to create GraphicElements and manage them in an ElementGraphicLayer, as well as create feature geometry with custom attributes and manage them in a FeatureGraphicsLayer.
 
In this sample, it is assumed that a map service has been created from the USA and California datasets 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 and <Your ArcGIS Developer Kit Install directory>/Samples/data/California/California.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 the Common_AddGraphics containing CSharp and VBNet folders.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the Common_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 Common_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 and open the Common_AddGraphics_<language> solution (for example, Common_AddGraphics_CSharp2008.sln) located in c:\inetpub\wwwroot\Common_AddGraphics_<language><vs_version>. The <vs_version> references the Visual Studio version of the solution, either 2008 or 2010.
  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. A graphics resource has already been added. Confirm that it is on top of the other resources. Most functionality in this sample is not dependent on the specific data available in the non-ADF map resource. The ability to render Web ADF graphics labels (ADFGraphicsResource) relies on the sample data in the USA map document. See the AddGraphicsLabels() method for specific properties in the code.
  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. Optionally, open the Default.aspx.cs file, navigate to the AddGraphicData method, and change the extent values associated with the envelope variable to reference an extent within the bounds of the data sources in the Map control. This method creates a red box using the extent parameters specified. If unchanged, the following coordinates are used: -100.0, 20.0 and -80.0, 40.0.
  15. Save the project.
  16. 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_AddGraphics_CSharp). A graphic polygon may be visible in the graphics layer when the application is loaded. By default, the box is displayed using the following coordinates: -100.0, 20.0 and -80.0, 40.0.
  2. On the toolbar above the map, click Add Graphic Point.
  3. Click the map. A point graphic is added to the map. The point is a GraphicElement added to an ElementGraphicsLayer.
  4. On the toolbar below the map, click Add Feature Point.
  5. Click the map. A red or blue point is added to the map. The point is stored as geometry in a FeatureGraphicsLayer. The color of the point is associated with the value of the CustomValue custom attribute field added to the FeatureGraphicsLayer. When a point is added to the data table, a random value of 0 or 1 is assigned to the CustomValue field. The colors are assigned using a unique value renderer.
  6. Select a color combination from the Colors drop-down box. The Color property of the symbols in the unique value renderer is used to change how the points are rendered.
  7. Select a symbol type from the Symbol Type drop-down box. The Type property of the symbols in the unique value renderer is used to change how the points are rendered.

Common_AddGraphics_CSharp\Default.aspx Default page containing a set of custom tools to create server and client-side graphics.
Common_AddGraphics_CSharp\Default.aspx.cs Code behind the user interface.
Common_AddGraphics_CSharp\Default_JavaScriptMapTips.aspx Page containing a resizable map and client-side graphics and MapTips generated via a server-side Web ADF graphics layer.
Common_AddGraphics_CSharp\Default_JavaScriptMapTips.aspx.cs Code behind the user interface.
Common_AddGraphics_CSharp\App_Code\GraphicPointTools.cs Class library containing implementation of custom tools.
Common_AddGraphics_CSharp\App_Code\Utility.cs Class library containing helper code.
Download the C# files
Common_AddGraphics_VBNet\Default.aspx Default page containing a set of custom tools to create server and client-side graphics.
Common_AddGraphics_VBNet\Default.aspx.vb Code behind the user interface.
Common_AddGraphics_VBNet\Default_JavaScriptMapTips.aspx Page containing a resizable map and client-side graphics and MapTips generated via a server-side Web ADF graphics layer.
Common_AddGraphics_VBNet\Default_JavaScriptMapTips.aspx.vb Code behind the user interface.
Common_AddGraphics_VBNet\App_Code\GraphicPointTools.vb Class library containing implementation of custom tools.
Common_AddGraphics_VBNet\App_Code\Utility.vb Class library containing helper code.
Download the VB.NET files

Download the files for all languages