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.
Design time
- Verify the appropriate services are available (see the Additional information section for more details).
- Verify the Web Application Developer Framework (ADF) for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
- In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNET\ArcGIS_AddDynamicData.
- Open the folder of the language you are going to use, that is, CSharp or VBNet, and copy the ArcGIS_AddDynamicData_<language> folder to c:\inetpub\wwwroot. The <language> variable can be CSharp or VBNet.
- To start the IIS Manager, click Start, Control Panel, Administrative Tools, Internet Information Services (IIS) Manager or Internet Information Services.
- In the console tree view on the left, click Local Computer, Web Sites, and Default Web Site. Click to expand the Default Web Site node, right-click the ArcGIS_AddDynamicData_<language> folder, and click Properties. The Properties dialog box appears.
- Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
- Start Visual Studio 2010 and open the solution located in the c:\inetpub\wwwroot\ArcGIS_AddDynamicData_CSharp folder.
- In the Solution Explorer, right-click Default.aspx and select Set As Start Page.
- Open the Default.aspx.cs page. In the getServerContext() method, change the servername variable to the name of the machine on which the server object manager (SOM) is running. Change the mapserverobject variable to the name of the map server object running on the SOM. The sample uses LocalHost as the servername and USA as the map server object (map service).
- Open the layers.catalog file. This file contains a list of data layer names and paths to datasets that are added dynamically in Default.aspx. The path to the datasets (in this sample, shapefiles) must be valid from the perspective of the server object container (SOC) machine. The dynamic layers and data layers in the server object specified in the previous step must share the same geographic area to be concurrently visible. This sample references data in <ArcGIS install location>\DeveloperKit10.0\Samples\data\USAMajorHighways\us_lakes.shp.
- In the code file for Default_ADF.aspx (for example, Default_ADF.aspx.cs), search for the Create Layer region (the AddLayer method). Modify the dynamic layer properties to point to the location of a data layer on disk. By default, the us_lakes.shp shapefile, located in c:\temp\data, is the dynamic layer. Grant the SOC account permission to access this location.
- Open the Default_ADF.aspx page in Design view, select MapResourceManager, and click the ellipsis next to the ResourceItems property. The ResourceItem Collection Editor dialog box appears.
- Add or change the MapResourceItem associated with an ArcGIS for Server map service. In this sample, use the USA map service.
- If necessary, set the run time identity of the Web application by following either of the next two steps. If this is not necessary, proceed to Step 18.
- At design time, the identity of the user running Visual Studio is used to connect to an ArcGIS for 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 ArcGIS for 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 the Solution Explorer and selecting Add ArcGIS Identity. Add the identity credentials that will be used to access ArcGIS for 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 selected, the identity tag will be encrypted; otherwise, the username and password are stored as clear text.
- 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, then set them to a valid user account. If you are working with ArcGIS for Server local data sources, ensure the account has access to the geographic information system (GIS) server resources referenced in the Map control. Other pages in this sample do not require specific changes as long as the data referenced here is used.
- Make sure the web.config file has entries under the <httpHandlers> tag. This allows customMapHandler to function. The entries resemble the following in Step 19.
- <remove path="ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler.ashx" verb="*"/><add path="ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler.ashx" verb="*" type="MyHandler.CustomMapHandler" validate="false"/>
- Save the project.
- Click the Debug menu and click Start.
Running the application
- Browse to the viewer uniform resource locator (URL), for example, http://localhost/ArcGIS_AddDynamicData_CSharp.
- Or, start the Web application in Visual Studio 2010.
Using the Default.aspx page
- Select a layer to add dynamically from the drop-down list.
- Click the Add Layer button. The layer is added dynamically.
- Click the Change Extent button. The map extent shifts, but the dynamic layer remains visible.
- Select another layer from the drop-down list and click the Add Layer button. The new dynamic layer is drawn in the map and the original dynamic layer is removed. This sample adds one dynamic layer at a time.
Using the Default_ADF.aspx page
- Click the Add Layer button to add the Canada.shp shapefile to the map. The table of contents (TOC) shows the newly added layer. This layer remains visible in the map and TOC as you navigate the map.
- Click the Remove Layer button to remove the layer from the map and TOC.
Using the CustomMapHandler_ADF.aspx page
- Click the Add Layer button to add the us_lakes.shp shapefile to the map. The TOC shows the newly added layer. This layer remains visible in the map and TOC as you navigate the map. This sample page uses the custom MapHandler. The Map.EnableMapHandler property on all other pages is false, so all server-side operations iterate through the page life cycle.
- Click the Remove Layer button to remove the layer from the map and TOC.
Using the ChangeRenderer_ADF.aspx page
- Click the Change Renderer button to change the renderer for the states layer in the map.
- The TOC also shows changes to the renderer.
Using the MoveLayer_ADF.aspx page
- Click the Move Layer button to move the highways layer to the bottom of the layer list.
- The TOC shows the highways layer at the bottom of the layer list.
Using the RemoveLayer_ADF.aspx page
- Click the Remove Layer button.
- The highways layer is removed from the map and TOC.
Additional information
The following is a list of pages and descriptions of their content. In most cases, session state is managed in the page code file. Since this samples works with a pooled server object, the changes are applied when the server context is created and removed, before server context is released, which resets the map server object to its original state.
- Default.aspx—Adds dynamic layers to a pooled ArcGIS for Server map server object using the ArcGIS Server ArcObjects application programming interface (API). The pure ArcObjects application displays the map image output in a standard .NET image control. The Web ADF controls are not used.
- Default_ADF.aspx—Adds dynamic layers to a pooled ArcGIS Server map server object using the Web ADF and the ArcGIS for Server local data source implementation classes. In this sample, it is assumed that the map server has access to the shapefiles in the layers.catalog text file.
-
CustomMapHandler_ADF.aspx—Includes the same content as that used in Default_ADF.aspx, except that it was enhanced at ArcGIS 9.3. At ArcGIS 9.3, map draw operations do not iterate through the page life cycle. Rather, a Hypertext Transfer Protocol (HTTP) handler, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler, is responsible for managing map draw operations. Other actions, such as those initiated from map tools, commands, or TOC changes, still iterate through the page life cycle. MapHandler is enabled by default via the EnableMapHandler property on the Map control. If MapHandler is disabled, all requests are processed by the page.
To take advantage of the performance enhancement offered by MapHandler, changes to server object state need to be duplicated or shared for map draw requests to MapHandler and all other requests to the page. MapHandler offers a set of events to override and modify resources before and after map draw. To override the events, create a class derived from the MapHandler class and define the events to override. This page uses a custom MapHandler (CustomMapHandler.cs). The code that manages server object state is contained in ServerObjectStateModifier.cs, and shared by the page and custom MapHandler. The following tags must be added in web.config under the <httpHandlers> tag. This allows the map class to use the custom maphandler. - <remove path="ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler.ashx" verb="*"/>
<add path="ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler.ashx" verb="*" type="MyHandler.CustomMapHandler" validate="false"/> - ChangeRenderer_ADF.aspx—Changes the renderer on an existing layer in a pooled ArcGIS for Server map service.
- MoveLayer_ADF.aspx—Moves an existing layer in a pooled ArcGIS for Server map service.
- RemoveLayer_ADF.aspx—Removes an existing layer in a pooled ArcGIS for Server map service.
ArcGIS_AddDynamicData_CSharp\Default.aspx | Contains the Web user interface (UI) to interact with server-side code. |
ArcGIS_AddDynamicData_CSharp\Default.aspx.cs | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_CSharp\layers.catalog | Text file containing file system paths to data layers. |
ArcGIS_AddDynamicData_CSharp\Default_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_CSharp\Default_ADF.aspx.cs | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_CSharp\CustomMapHandler_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_CSharp\CustomMapHandler_ADF.aspx.cs | Code behind the .aspx file. Manages server content and session state. Calls methods in ServerObjectStateModifier.cs where required. |
ArcGIS_AddDynamicData_CSharp\ChangeRenderer_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_CSharp\ChangeRenderer_ADF.aspx.cs | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_CSharp\RemoveLayer_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_CSharp\RemoveLayer_ADF.aspx.cs | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_CSharp\MoveLayer_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_CSharp\MoveLayer_ADF.aspx.cs | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_CSharp\App_Code\CustomMapHandler.cs | Custom MapHandler enabled via entries in the web.config file. Calls methods in ServerObjectStateModifier.cs where required. |
ArcGIS_AddDynamicData_CSharp\App_Code\ServerObjectStateModifier.cs | Manages stateful changes to a stateless server object. |
ArcGIS_AddDynamicData_CSharp\App_Code\Utility.cs | Utility class for common actions. |
ArcGIS_AddDynamicData_VBNet\Default.aspx | Contains the Web user interface (UI) to interact with server-side code. |
ArcGIS_AddDynamicData_VBNet\Default.aspx.vb | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_VBNet\layers.catalog | Text file containing file system paths to data layers. |
ArcGIS_AddDynamicData_VBNet\Default_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_VBNet\Default_ADF.aspx.vb | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_VBNet\CustomMapHandler_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_VBNet\CustomMapHandler_ADF.aspx.vb | Code behind the .aspx file. Manages server content and session state. Calls methods in ServerObjectStateModifier.vb where required. |
ArcGIS_AddDynamicData_VBNet\ChangeRenderer_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_VBNet\ChangeRenderer_ADF.aspx.vb | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_VBNet\RemoveLayer_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_VBNet\RemoveLayer_ADF.aspx.vb | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_VBNet\MoveLayer_ADF.aspx | Contains the Web UI to interact with server-side code. |
ArcGIS_AddDynamicData_VBNet\MoveLayer_ADF.aspx.vb | Code behind the .aspx file. Manages server content and session state. |
ArcGIS_AddDynamicData_VBNet\App_Code\CustomMapHandler.vb | Custom MapHandler enabled via entries in the web.config file. Calls methods in ServerObjectStateModifier.vb where required. |
ArcGIS_AddDynamicData_VBNet\App_Code\ServerObjectStateModifier.vb | Manages stateful changes to a stateless server object. |
ArcGIS_AddDynamicData_VBNet\App_Code\Utility.vb | Utility class for common actions. |
Download the files for all languages