Customizing the Web Mapping Application


Summary
Many applications created using ArcGIS Server Manager (Manager) are customized to meet specific needs. The Web Mapping Application (WMA) can be customized using Visual Studio or Visual Web Developer Express Edition (Express). A lot of customization can be done in Visual Studio that does not require programming. However, you can modify the application further by taking advantage of the various application programming interfaces (APIs). This topic focuses on customizing the WMA in Visual Studio without programming.

In this topic


Opening a WMA in an IDE

The first step in customizing the WMA is to open it in Visual Studio. When you open the application in your integrated development environment (IDE), it is opened in the Source view. The main page—Default.aspx—is comprised of Hypertext Markup Language (HTML) and JavaScript. When you change the view to Design view, a visual representation of the same information shows. You can use these views interchangeably. As you make changes to one view, they are reflected in the other view.
The Source view format is shown in the following screen shot:
The Design view format is shown in the following screen shot:
The WMA contains various Web controls that are server-side objects included as part of the Web Application Developer Framework (ADF). The WMA includes Web controls specific to mapping, such as Map, OverviewMap, and Toc (table of content) controls. There are some other controls existing in WMA that is not shown on the page. These controls are mainly used for connecting to different data sources, for example, MapResourceManager is available on the page and is not visible at runtime. It is required for connecting to different types of data sources.
The WMA also includes a number of HTML elements, such as DIV and TABLE, and Web controls, such as asp:panel, that are used in formatting the page. The following screen shot shows the WMA in Design view with a visual representation of Web controls:
Each Web control contains a set of properties. Each property has an attribute in the HTML source. In Design view, the properties are summarized in a Properties window that is located on the lower right of your IDE. The property is listed on the left and the property value is on the right.
The following screen shot shows the Properties window:

Do the following steps to open an application in an IDE:
  1. Start Visual Studio.
  2. Open your WMA. Click File, click Open, then click Web site.
  3. In the left panel, click Local Internet Information Services (IIS) if it is not already selected.
  4. Select your application from the list and click Open.
  5. After the application opens, double-click Default.aspx in the Solution Explorer located in the upper right of the IDE. Default.aspx is the main Web page that shows the layout of the application graphically or in HTML. By default, the page opens in Source view, which shows the HTML source.
  6. In the lower left area of the IDE, click the Design tab to switch to Design view.
The Design tab is shown in the following screen shot:

Accessing Web control properties

You can access Web control properties in the following ways:
  1. Right-click the Web control on the Design view page.
  2. Click the drop-down arrow on the Properties window and select the Web control. See the following screen shot:

Working with the WMA file structure

When you open a WMA in an IDE, the following folders and files are listed in Visual Studio's Solution Explorer:
  • App_Code—Standard ASP.NET folder for code modules used in the application. Contains Native64BitSupport.vb or Native64BitSupport.cs, which cab be used if running application in a 64-bit application pool.
  • App_Themes—Standard ASP.NET folder for application theme files, such as style sheets, skin files, and images. For more information, see the following section in this topic, Using themes and style sheets.
  • Help—Folder containing the Help files for the WMA. These are plain HTML files that can be customized for your application.
  • images—Folder containing images used by the WMA.
  • JavaScript—Folder containing two JavaScript library files used by the WMA, namely display_measure.js and WebMapApp.js.
  • ApplicationClosed.aspx—Displays if the Close link is clicked when the Web application is using a non-pooled ArcGIS for Server data source. This allows the application to release resources used on the geographic information system (GIS) server as soon as you are finished with them.
  • Default.aspx—Main Web page that includes the map, associated controls, and content.
  • ErrorPage.aspx—Shown if the Web application encounters an unhandled error.
  • Global.asax—Contains code that runs when the application and session, start and end.
  • Login.aspx—Used only when the application requires a login using a form (Forms authentication). If the application was created and security applied in Manager, this page shows when you open the application. If the application was created in Visual Studio or otherwise is not visible to Manager, security can be configured with other tools, such as the Web Site Administration Tool, available from the Visual Studio menu. For more information, see ASP.NET Web Site Configuration on the Microsoft Developer Network (MSDN) Web site.
  • Measure.ascx—Custom user control used in Default.aspx as a tool for measuring distance and area on the map.
  • PasswordRecoveryMail.txt—Contains the text to use when sending the user an e-mail to recover a lost password. Only used if the form-based login is active (see Login.aspx) and a mail server is defined in the Web.config file. For more information, see the security topics in the Server Help.
  • ReadMe.txt—Contains brief instructions on setting up a WMA in Visual Studio.
  • Web.config—Standard ASP.NET configuration file that stores references to .NET assemblies used, identity when using an ArcGIS for Server local data source, and other configuration settings.
See the following screen shot that shows the Solution Explorer:
The WMA can also use files in the common ASP.NET folder, aspnet_client, which is stored in the root IIS folder. These files are typically in C:\Inetpub\wwwroot\aspnet_client\ESRI\WebADF.

Navigating Default.aspx (mapping page)

Default.aspx is the main mapping page in the Web application. It contains Web controls to show a map along with related items, such as a TOC, an overview map, and tools to interact with the map. In addition to Web controls, the page uses a combination of panel controls, DIV elements, and tables to format the page. At the highest level, the page is divided into the following panel controls:
  • PageHeader panel—Contains the title bar.
  • LinkBar panel—Contains the toolbar and menu-based hyperlinks.
  • Page Content panel—Contains Map and Control panels. The map is in a panel control called Map_Panel. The Control panel is the area on the left that contains Task and Results panels, an overview map, and a TOC. The Control panel is contained in a table and nested in several DIV tags, the innermost being LeftPanelCellDiv. These DIV tags control the resizing and position of the Control panel.
The following screen shot shows a sample WMA Default.aspx page in Design view:

Working with Web controls on the mapping page

The Default.aspx page contains controls for displaying and interacting with map information. The following table lists some of these controls:
ESRI ADF Web control
ASP.NET control
Custom user control
Notes
 
 
None
 
 
Resource manager controls manage access to server resources. It is important to configure properties in Mapresourcemanager, as it establishes connections to services. Other resource mangers can be configured as required.
 
 
 
 
 
 
None
 
TitleMenu
 
Standard ASP.NET menu control.
 
SiteMapDataSource
 
Standard ASP.NET control.
 
 
All are located in the Control panel on the left side of the Default.aspx page.
 
ZoomLevel is only visible when using ArcGIS for Server fused cashed data sources.
 
 
 
 
 
 
 
 
 
 
Not active by default.
 
 
None
 
 
None
 
 
Measure
None
 
 
Can contain tasks.

Selecting an overview map

In Manager, you can include an overview map and select which service to use. Manager restricts the list of services to those already selected for display in the map. In most cases, a map shows detail appropriate for its size on the screen, including labels and symbols. Overview maps are smaller, and it is often better to show less detail. This can be accomplished by selecting a secondary service for the overview map.
To select an overview map that is not in the map, the process is as follows:
  • Add a service to the list of map resources in your IDE.
  • Hide this map from view and from the table of contents.
  • Associate the overview map with the map you added to the list of map resources.
This process is detailed in the following steps:
  1. Click the MapResourceManager control in Design view, or click the drop-down arrow on the Properties window and select MapResourceManager1.
  2. Click the ResourceItems property, then click the ellipsis button. The MapResourceItem Collection Editor dialog box appears.
  3. Click Add. A new resource is added.
  4. On the right side of the MapResourceItem Collection Editor dialog box, click the Definition property, and click the ellipsis button. The Map Resource Definition Editor dialog box appears.
  5. In the editor, select the type of service to add from the drop-down list.
  6. Click the Data Source ellipsis button and add the required information for your data source.
  7. Click the Resource ellipsis button, select a service from the drop-down list, and click OK.
  8. Click OK to close the Map Resource Definition Editor dialog box.
  9. On the right side of the MapResourceItem Collection Editor dialog box, click the Name property and type the name of your service.
  10. Click the DisplaySettings property and click the ellipsis button. The Map Resource Display Settings Editor dialog box appears.
  11. Clear the Visible and Display in the Table of Contents check boxes, and click OK. See the following screen shot:


  12. Click OK to close the MapResourceItem Collection Editor dialog box.
  13. Reference the new service in the overview map by clicking the OverviewMap control in the lower left of the Design area or by clicking the drop-down arrow on the Properties window, and selecting OverviewMap1.
  14. Click the OverviewMapResource property and select the service from the drop-down list.
  15. Save your changes.
  16. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.
For more information, see the OverviewMap control.
For more information on adding services, see the MapResourceManager control.

Changing Navigation control properties

The Navigation control allows users to pan the map by clicking different points on the control. In Manager, you can include a Navigation control and select the font symbol or image to be used. In your IDE, you can also change the size of the north arrow, the output image format, and how quickly the map moves when it is used for navigation.
Do the following steps to change the Navigation control properties:
  1. Click the Navigation control in Design view or click the drop-down arrow on the Properties window, and select Navigation1.
  2. Change the property values as appropriate. Common Navigation control properties are as follows:
    • DisplayCharacter—Font and character index of a glyph.
    • ImageFormat—Output format for the image.
    • Size—Size of the image in points.
    • Speed—The higher the value, the faster the map moves.
  3. Save your changes.
  4. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.
For more information, see the Navigation control.

Changing Toc control properties

In Web Manager, you can include a TOC and swatches, and allow users to turn layers on and off in the TOC. When using your IDE, you can change the font and set the TOC to be fully expanded when the application is opened.
Do the following steps to change Toc control properties:
  1. Click the Toc control in Design view or click the drop-down arrow on the Properties window, and select Toc1.
  2. Change the property values as appropriate (common Toc control properties are as follows):
    • ExpandDepth—Value of 2 means the TOC expands to the second level by default. This expansion is enough to see the swatches.
    • Font—Used for specifying layer names.
    • ForeColor—Color of the font.
    • ShowLayerCheckBoxes—Allows users to turn layers on and off.
    • ShowResourceCheckBoxes—Allows users to turn services on and off.
    • TocType—Allows to choose to display legend with swatches (Layer symbol) or only layer names.
  3. Save your changes.
  4. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.
For more information, see the Toc control.

Changing ScaleBar control properties

While creating the application using ArcGIS Server Manager, you can include a scale bar, as well as set the scale bar units, bar color, and text color. If you are using the Visual Studio IDE, you can also change the scale bar font, bar height, and bar length.
Do the following steps to change the ScaleBar control properties:
  1. Click the ScaleBar control in Design view, or click the drop-down arrow on the Properties window and select ScaleBar1.
  2. Change the property values as appropriate. Common ScaleBar control properties are as follows:
    • BarColor—Scale bar color
    • BarFont—Font used for scale bar text
    • BarHeight—Height of the scale bar
    • BarUnits—Scale bar units, such as miles or kilometers
    • ForeColor—Font color
    • Width—Scale bar length
  3. Save your changes.
  4. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.
For more information, see the ScaleBar control.

Adding a copyright statement

It's easy to add a copyright to the Web mapping application using the Visual Studio IDE. The Web mapping application template comes with the MapCopyrightText control added to the map. Do the following steps to change the copyright control properties:
  1. Click the MapCopyrightText control in Design view, or click the drop-down arrow on the Properties window and select MapCopyrightText1.
  2. Change the Text property to display the copyright text. Other properties can be changed as required.
  3. Save your changes.
  4. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.

Adding a north arrow

While there is no option available to add a north arrow via manager, you can add one in via visual studio IDE. Adding a north arrow to the map is in addition to using the Navigation control, which can also be used as a north arrow. The easiest way to add a north arrow is through the HTML source rather than in Design view.
Do the following steps to add a north arrow to your map:
  1. Click the Source tab to access the HTML page. The Source tab is shown in the following screen shot:


  2. Search for Map_Panel. See the following code example:
[HTML]
<div id="Map_Panel" style="...">
  <esri:Map ID="Map1" runat="server" ...>
  </esri:Map>
</div>
  1. Before the closing DIV tag, place the following line containing the north arrow. Modify the style attribute for your application as appropriate. See the following code example:
[HTML]
<div style="position:absolute; bottom:25px; left:20px;z-index:98; font-family:ESRI North;
font-size:36pt;color:Black;">
&#176
</div>
In the previous code example, the text is placed in a DIV tag. You can format the placement location and north arrow symbol by using the style attribute. The following table lists the style properties, values, and descriptions:
Style property and value
Description
position: absolute
Use absolute positioning with the text so that it does not move.
bottom: 25px; left: 20px
The placement of the text. In this case, the text is placed 25 pixels from the bottom and 20 pixels from the left.
z-index
Sets the order of the element in the stack. Use a high number so that the north arrow is always on top.
font-family: ESRI North; font-size: 36pt; color: Black
The font family, size, and color to be used. In this example, ESRI North is the font, the color is black, and the north arrow will be one half inch high based on 72 points per inch.
The north arrow is represented by a keyboard character or a character entity. The following table shows two examples:
Character
Symbol
Capital letter I or &#68
&#176 (No keyboard equivalent in English)
  1. Save your changes.
  2. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.

Using themes and style sheets

A theme is a collection of property settings that allow you to define the look of pages and controls, then apply the look consistently across pages in a Web application, across an entire Web application. Each theme is self-contained, making it easy to move among themes without affecting the code in the application.
Themes consist of a .skin and .css file plus any supporting images. These files can have any name, but the WMA has standardized the following:
  • Default.skin—Defines display properties for some of the server-side controls, such as task floating panel, and magnifier
  • MapViewerStyleSheet.css—Contains styles for many of the surrounding elements, such as the title bar area
  • Images—Used by skins and styles for background images
For a WMA, each theme is created as a separate subdirectory in the App_Themes folder as shown in the following screen shot. You can modify an existing theme or create one.
Some of the controls in a WMA do not reference a theme's style sheet. Instead, colors and fonts are set within the properties of the control. These values override attributes set in the style sheet. In the following screen shot, the Font and ForeColor (font color) properties have been set in the Properties window:
When an HTML page is sent to the client, the font information is included in the style attribute, which overrides any attributes in the style sheet. See the following code example:
[HTML]
<span
  id="MapViewer_TitleTextShadowLabel"
  style="color:White;font-family:Verdana;font-size:12pt;font-weight:bold;position:
absolute; left: 5px; top: 5px;">
  Web Mapping Application
</span>
To reference a style sheet, the property values for Font and ForeColor need to be removed, and a value for CssClass needs to be added that references a class in the style sheet.

Modifying an existing theme

Do the following steps to modify an existing theme in an application:
  1. In the Solution Explorer, double-click Web.config to open the file.
  2. Scroll until you come to the theme reference. The name of the theme reflects the directory your application is currently referencing. See the following code example:
[HTML]
<pages theme="Blue_Bridge"/>
  1. Navigate to this directory in the Solution Explorer.
  2. Double-click Default.skin or MapViewerStyleSheet.css to open the files. Make changes to fonts, colors, and other formatting attributes as appropriate.
  3. Save your changes.
  4. Click the Default.aspx tab to make Default.aspx the active page. See the following screen shot:


  5. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.

Adding a theme

Do the following steps to add a theme to an application:
  1. Add a theme directory under App_Themes.
    1. In the Solution Explorer, right-click App_Themes, and select Add ASP.NET folder.
    2. Add and rename the folder.
    3. Right-click the new folder and select Add Existing Item.
    4. Navigate to the location of the theme folder you want to use, and copy the .css and .skin files you want to use.
    5. If necessary, repeat Steps 1, a–d to add subfolders, such as one for images.
    6. Optionally, copy an existing directory to App_Themes.
  2. Make changes to the files as needed.
  3. In the Solution Explorer, double-click Web.config to open the file.
  4. Scroll until you come to the theme reference. Change the theme reference to the new folder name as shown in the following code example:
[HTML]
<pages theme="mytheme"/>
  1. Save your changes.
  2. Click the Default.aspx tab to make Default.aspx the active page.
  3. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.

Referencing a theme's style sheet

Do the following steps to reference a theme's style sheet in a control:
  1. Click the control in Design view, or click the drop-down arrow on the Properties window and select the control.
  2. Check if the control has a CssClass property. If this property is populated, the control is referencing MapViewerStyleSheet.css. To reference the style sheet if this property is not populated, set the value for CssClass to one of the classes in MapViewerStyleSheet.css. For example, set the CssClass value for MapViewer_TitleTextShadowLabel to MapViewer_TitleBarStyle.
  3. Click the Source tab.
  4. If the cursor is not already at the control you want to change, search for the control.
  5. Remove any font, color, or other formatting attributes that are included in the style sheet. For example, for MapViewer_TitleTextShadowLabel, remove all the font attributes since they are already included in the MapViewer_TitleBarStyle class.

    See the following code example:
[HTML]
<asp:Label ID="MapViewer_TitleTextShadowLabel" runat="server" Text="Web
Mapping Application" Font-Size="12pt" Font-Names="Verdana" ForeColor="White"
Font-Bold="True" style= "position: absolute; left: 5px; top:
5px;"CssClass="MapViewer_TitleBarStyle">
</asp:Label>
The code after the font attributes have been removed as follows:
[HTML]
<asp:Label ID="MapViewer_TitleTextShadowLabel" runat="server" Text="Web
Mapping Application" style="position: absolute; left: 5px; top: 5px;"
CssClass="MapViewer_TitleBarStyle">
</asp:Label>
  1. Save your changes.

Adding or modifying template themes

To make a theme available in Manager or Web Manager, add a theme or replace an existing theme in the templates by doing the following steps:
  1. Create a theme or modify an existing theme in an application.
  2. Copy the theme directory from your application to the Manager directory typically located in the following locations:
    • C#—C:\Inetpub\wwwroot\ArcGIS\Manager\Modules\Applications\Templates\mv_cs\App_Themes
    • For VB.NET—C:\Inetpub\wwwroot\ArcGIS\Manager\Modules\Applications\Templates\mv_vb\App_Themes
  3. Close all browsers.

    The next time you open Manager or Web Manager, your new or updated theme is included in the drop-down list in the Page properties.

Adding and removing tools from the toolbar

While creating an application using Manager, you can include a toolbar but it is not possible to add more tools or remove existing tools. The toolbar contains the following tools:
  • ZoomToScale—Zooms to selected and entered map scale.
  • Zoom In—Zooms in to the area of the map that you click or drag a box around.
  • Zoom Out—Zooms out from the area of the map that you click or drag a box around.
  • Pan—Pans the map display in the direction you drag the mouse pointer.
  • Full Extent—Zooms to the full extent of the map.
  • Previous Extent—Takes the map to the last or previous extent.
  • Forward Extent—Takes the map to next/forward extent.
  • Go to Location— Allows the entry of x,y coordinates and zooms to that location.
  • Identify—Lists the attributes of the feature you clicked.
  • Measure—Measures distance or area.
  • Magnify—Magnifies a section of the map.
These tools are shown in the following screen shot:
However, it is possible to add, remove, or re-arrange tools using the IDE. You can use ToolbarCollectionEditorForm as shown in the following screen shot to make changes:
To access this form and make changes, do the following steps:
  1. Click the toolbar control in Design view, or click the drop-down arrow on the Properties window in the Visual Studio IDE and select the toolbar control.
  2. Select ToolbarItems property and click the ellipsis to show the ToolbarCollectionEditorForm.
  3. Make the changes and click OK to close the form.
  4. To see your changes in a Web browser, click File, and click View in Browser on the drop-down menu.
For more information, see the Toolbar control.

Pass initialization parameters in the URL

To provide initialization parameters in the uniform resource locator (URL) of a Web Mapping Application, do the following steps:
  1. Start Visual Studio and create a Web mapping application using the template.
  2. Set up Map and MapResourceManager by adding a valid map resource item.
  3. Double-click Default.aspx.cs in the Solution Explorer.
  4. Add a member variable to store the collection of name-value pairs passed to the Web application in the URL as shown in the following code example:
[C#]
public partial class _Default: System.Web.UI.Page
{

    private NameValueCollection queryvalues = null;
  1. On initialization of the page, add the Page_Init method with the following signature and code in the _Default class to capture the URL parameters using the Request.QueryString property:
[C#]
protected void Page_Init(object sender, EventArgs e)
{
    if (!IsCallback)
    {
        queryvalues = Request.QueryString;
    }
}
If the request to the page is not a callback (if it is a full page postback), the URL parameters are interrogated. Since URL parameter information is gathered during page initialization, subsequent page and control events (during the same request) can work with the query string to change properties.

In the following code example, a single name-value pair is queried during the pre-render event of the page. The URL contains the name Extent and a value consisting of a set of comma delimited values to define the extent envelope or a Map control.
  1. Add the Page_PreRender method with the following signature and code in the _Default class:
[C#]
protected void Page_PreRender(object sender, EventArgs e)
{
    string[] values = queryvalues.GetValues("Extent");
    if ((values != null) && (values.Length > 0))
    {
        string[] extentparams = values[0].Split(',');
        ESRI.ArcGIS.ADF.Web.Geometry.Envelope env = new
            ESRI.ArcGIS.ADF.Web.Geometry.Envelope(Double.Parse(extentparams[0]),
            Double.Parse(extentparams[1]), Double.Parse(extentparams[2]),
            Double.Parse(extentparams[3]));
        Map1.Extent = env;
        Map1.Refresh();
    }
}
  1. Run the application. In the Web browser, add the custom name-value pair to the Web Mapping Application URL and reload the page. The format is Extent=minx,miny,maxx,maxy. For example, Extent=-90,30,-70,50. Include a question mark (?) after the Web Mapping Application path to indicate that a set of name-values pairs is provided. The full URL appears as follows: http://localhost/SampleWebApp/default.aspx?Extent=-90,30,-70,50. See the following screen shot: