Developing Mobile Applications using the Mobile ADF  

Mobile ADF walkthrough: Desktop application


 

This walkthrough is for developers who wish to create and deploy a simple ArcGIS Mobile application for the desktop environment. It demonstrates how to create the application using the ArcGIS Mobile Map Control, the ArcGIS Mobile API and parts of ADO.NET.

You can find this sample in: <ArcGIS_install_location>\DeveloperKit\Samples\Server\NET\Mobile_Applications\Walkthrough_WinCSharp.zip

Project Description

The application will display map data that has been extracted from an ArcGIS Map Service using a Map Control, provide basic navigation tools such as zoom and pan, and include an identify function to show feature attributes. Once you complete this walkthrough, you can then extend the application you build with additional functionality.

Concepts

There are some important concepts you should understand before following this example. As a prerequisite, please read through the Mobile SDK conceptual documentation found under the heading Developing Mobile Applications using the Mobile ADF to gain an understanding of the mobile framework and architecture. You should also have a good understanding of Visual Studio .NET 2005 and how to create a windows application.

ArcGIS Mobile Components

The ArcGIS Server Mobile SDK provides serveral Visual Studio components to help you develop mobile applications. The primary components that you will work with in this scenario are the Map Cache and the Map. The Map Cache component requests data stored in a folder called the Storage Path. Th map cache you will use has previously been extracted from a map web service that was published with mobile capabilities. You do not need to create a mobile web service to complete this walkthrough. The Map component will display the contents of the map cache that has been created for you without having to connect to a server. Additional components are used to navigate the map itself and identify attribute information for given features. For more information on the components used in this walkthrough please refer to the ArcGIS Server Developer Help.

Requirements

In order to walk through this scenario you will need the following installed on your machine:

This example is written in C#. You should also reference the ArcGIS Mobile object model diagram while proceeding through this example. You can find the OMD in ArcGIS Developer Help.

 


Implementation

In this example you will create a simple application that allows you to connect to open a mobile map cache and display the layers in a map control. You will then add additional controls that will let you navigate the map and identify features within the layers.

The first step is to create the new project.

Creating a new project

  1. Start Visual Studio .NET 2005.
  2. On the File menu, point to New, then Click Project .
  3. In the New Project dialog box, under Project Types, click Visual C#, then click Windows .
  4. In the Templates pane click Windows Application .
  5. Enter an appropriate name for the project.
  6. Click OK. This will create a new project for you.

 

 

Using the Map Control at design time

The ArcGIS Mobile controls are added to the Visual studio toolbox when you install the ArcGIS Mobile ADF. They are located within the ArcGIS Mobile Controls tab within the toolbox. To use the controls within your application you must drag and drop them from the Toolbox to your windows form.

 

 

Within the following section, you will add a Map component to the application and configure it.

  1. Drag the Map component from the toolbox onto the form.
  2. Resize the Map to fill the desired area as indicated by the screen shot above.

 

Your form should now contain a Map, called Map1, and a MapCache component that was automatically added, mapCache1. Additionally two new references have been added to your project, one to the Mobile ADF windows assembly and the other to the .NET System.Web.Services assembly.

You now need to configure the components via their properties.

  1. Right click the Map Control and choose Properties on the context menu to display its properties within the Properties window.
  2. Within the Properties window for Map1, set the MapCache property to mapCache1 .
  3. Now display the properties for the mapcache. Click the component mapCache1 in the Component pane within the application.
  4. Within the Properties window, select the StoragePath property and type C:\Temp\Redlands. Note that you will need to copy the Redlands map cache from the sample data folder to your temp folder.

You now need to add code to create the map cache on disk and retrieve data from the server while the application is running.

  1. Create a form load event.
  2. Switch to code view and add a using statement to include the ArcGIS Mobile assembly:
    [C#]
    using ESRI.ArcGIS.Mobile;
  3. Add the following code to the form1_load event:
    [C#]
     private void Form1_Load(object sender, EventArgs e)
     {  
     if (!mapCache1.IsValid)   
       {
         MessageBox.Show("Map Cache is not valid!");
         return;
       }
     try
       {
         mapCache1.Open();
       }
     catch
       {
        MessageBox.Show("Cannot open map cache");
       }
      }
      

This code will open the mapcache, retrieve data for the current map extent and draw it to the display.

Compile the application. On the Build menu, choose Build Solution. This will display the Repair Native Dll's dialog prompting you to add the Mobile ADF unmanaged library to the solution. Click OK to add the dll. This dialog is displayed if the unmanaged dll is missing or has a broken link and you build or run your application.

NOTE:  Before running the application, you need to copy the map cache data from the samples' data directory to the emulators' \Temp folder. From the Tools menu in ActiveSync, click Explore Device and navigate to \Temp and paste the Redlands folder from <ArcGIS_Server_Install_Location>\DeveloperKit\SamplesNET\Server\data\mobile\MapCaches\Redlands. You may now run the application. At this stage the form should display layers from the map cache in the map control.

Changing the Mouse behavior

Map actions are components designed to listen and react to events raised by the mouse, keyboard, and other input devices against the map surface. For instance pan mouse action listens to the MouseDown, MouseMove, and MouseUp events to begin, execute, and complete panning action.

A map can have multiple map actions associated with it however, by design only one is active or current. For instance a map can have zoom in, zoom out, pan, identify, and polygon sketch actions available, but at any given time only one action is executed. In this section you will add mapaction components and controls to the project to alter the mouse behavior.

 

 

  1. From the Visual Studio toolbox add the mobile Pan, Zoom in and Zoom Out map action components to the project.
  2. Select each of the components and set their Map property to Map1.
  3. Find the RadioButton control from the Visual Studio toolbox and drag 3 of them onto the Form, similar to the screenshot above.
  4. Set the Text Property on each of them to Pan, In, and Out.
  5. Double click on each of the radio buttons on the form to create a code block for the Check Changed Event for each button.
  6. Add the following code to the CheckChanged Events
    [C#]
    private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
      {
        map1.CurrentMapAction = panMapAction1;
      }
    
    private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
      {
        map1.CurrentMapAction = zoomInMapAction1;
      }
    
    private void radioButton3_CheckedChanged(object sender, System.EventArgs e)
      {
        map1.CurrentMapAction = zoomOutMapAction1;
      }
  7. Compile and run your application.

Your application should now be in a state where it will compile and run. In this state, you should be able to change the mouse action by simply toggling the radio buttons appropriately between panning, zooming in, and zooming out.

Adding Identify Capability

Much like the functionality contained within ArcMap, you can identify features inside the MapControl by querying the location at the mouse position. In this section we will add some custom code to enable identify.

  1. Find the RadioButton control from the Windows Forms Toolbox and drag another to the Form.
  2. Set the Text Property on it to ID.
  3. Double click on the ID radio button to create a code block for the Check Changed Event.
  4. Add the following code to the CheckChanged event.
    [C#]
    private void radioButton4_CheckedChanged(object sender, System.EventArgs e)
      {
        map1.CurrentMapAction = null;
      }
  5. Add a mousedown event to the Map Control. With the Map Control active in the form, click Events in the Properties window. Find the MouseDown event in the list of events and double click it. This will create a code block for the event.
  6. Add the following code to the MapControl_MouseDown event.
    [C#]
    private void map1_MouseDown(object sender, MapMouseEventArgs e)
    {
      if (map1.CurrentMapAction != null)
        return;
    
      Cursor.Current = Cursors.WaitCursor;
      MapMouseEventArgs me = e as MapMouseEventArgs;
      Envelope qEnv = new Envelope(me.MapCoordinate, me.MapCoordinate);
    
      int mapTolerance = map1.ToMap(3);
      qEnv.Resize(mapTolerance, mapTolerance);
    
      QueryFilter qFilter = new QueryFilter(qEnv, EsriGeometricRelationship.Intersect);
    
      string txtResult = "Identify Results: ";
      int intFields;
    
      foreach (MapLayer lyr in map1.MapLayers)
      {
        FeatureLayer featLayerDT = lyr.Layer as FeatureLayer;
    
        if (featLayerDT == null)
            continue;
    
        txtResult += "\r\nLayer " + featLayerDT.Name;
    
        using (FeatureDataReader featReader = featLayerDT.GetDataReader(qFilter))
        {
          intFields = featReader.FieldCount;
    
          while (featReader.Read())
          {
            for (int i = 0; i < intFields; i++)
              txtResult += "\r\n" + featReader.GetName(i) + ": " + featReader.GetValue(i).ToString();
          }
        }
      }
      Cursor.Current = Cursors.Default;
      MessageBox.Show(txtResult);
    }
  7. Compile and run the application.

Experiment with the application. Change the mouse modes via the radio buttons.

 


 


Deployment

The application may be deployed to other PC's using either of the methods described in the Deploying mobile adf applications topic.