ArcGIS Add dynamic data


Purpose
This sample illustrates the management of shallowly stateful operations with stateless pooled ArcGIS Server map server objects. Shallowly stateful means that state is managed by the client rather than by the server object. Pooled server objects are stateless, so any stateful changes must be made and reset in server content. Since pooled server objects reside in a pool, any stateful changes that are not reset are visible by the next client who accesses that server object.

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 appropriate services are available (see the Additional information section for more details).
  2. Verify that 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.
  3. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNET\ArcGIS_AddDynamicData.
  4. Open the folder of the language you're going to use—CSharp or VBNet—and copy the ArcGIS_AddDynamicData_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  5. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
  6. 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_AddDynamicData_<language> folder, and click Properties. The Properties dialog box opens.
  7. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  8. 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_AddDynamicData_CSharp2008.sln and is located in the c:\inetpub\wwwroot\ArcGIS_AddDynamicData_CSharp folder.
  9. In Solution Explorer, right-click Default.aspx and select Set As Start Page.
  10. 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. Sample uses LocalHost as servername and "USA" as map server object (map service).
  11. 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.
  12. In the code file for Default_ADF.aspx (for example, Default_ADF.aspx.cs), search for the region named Create Layer (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.
  13. 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 opens.
  14. Add or change the MapResourceItem associated with an ArcGIS Server map service. In this sample, use the USA map service.
  15. If necessary, set the run time identity of the Web application by following either of the next two steps. If not necessary, proceed to step 18.
  16. 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 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.
  17. 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. Other pages in this sample do not require specific changes as long as the data referenced here is used.
  18. Make sure web.config has entries under <httpHandlers> tag. This allows customMapHandler to function. Entries should look like as shown in next point.
  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"/>
  20. Save the project.
  21. Click the Debug drop-down menu and click Start.

Running the application
  1. Browse to the viewer uniform resource locator (URL) (for example, http://localhost/ArcGIS_AddDynamicData_CSharp) or start the Web application in Visual Studio 2008 or 2010.

Using the Default.aspx page
  1. Select a layer to add dynamically from the drop-down list.
  2. Click the Add Layer button. The layer is added dynamically.
  3. Click the Change Extent button. The map extent shifts, but the dynamic layer remains visible.
  4. 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
  1. Click the Add Layer button to add the Canada.shp shapefile to the map. The TOC shows the newly added layer. This layer remains visible in the map and the TOC as you navigate the map.
  2. Click the Remove Layer button to remove the layer from the map and TOC.

Using the CustomMapHandler_ADF.aspx page
  1. 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 the 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 lifecycle.
  2. Click the Remove Layer button to remove the layer from the map and TOC.

Using the ChangeRenderer_ADF.aspx page
  1. 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
  1. 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
  1. Click the Remove Layer button to remove the highways layer from the map and TOC.

Additional information

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, resetting the map server object to its original state.
  • Default.aspx—Adds dynamic layers to a pooled ArcGIS Server map server object using the ArcGIS Server ArcObjects 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 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 was enhanced at ArcGIS 9.3. At ArcGIS 9.3, map draw operations do not iterate through the page lifecycle. Rather, a Hypertext Transfer Protocol (HTTP) handler, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler, is solely responsible for managing map draw operations. Other actions, such as those initiated from map tools, commands, or TOC changes, still iterate through the page lifecycle. 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. Following tags must be added in web.config under <httpHandlers> tag. This will allow the map to class to use custom maphandler.
 
<removepath="ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler.ashx"verb="*"/>
<addpath="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 Server map service.
  • MoveLayer_ADF.aspx—Moves an existing layer in a pooled ArcGIS Server map service.
  • RemoveLayer_ADF.aspx—Removes an existing layer in a pooled ArcGIS 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.
Download the C# files
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 VB.NET files

Download the files for all languages