Developing Mobile Applications using the Mobile SDK  

Mobile ADF developer scenario: Mobile walkthrough



 

This walkthrough is for developers who wish to create and deploy a simple ArcGIS Mobile application for the Smartphone 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_SP05CSharp.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 Smartphone 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# and will be deployed to the Windows Mobile 5.0 Smartphone emulator installed with Visual Studio. You should also reference the ArcGIS Mobile ADF 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 within the Windows Mobile 5.0 Smartphone emulator that allows you 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#, expand Smart Device then click Windows Mobile 5.0 Smartphone .
  4. In the Templates pane click Device 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 in 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 and  MapCache component to the application and configure them via properties.

  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.

When the Map component is added to the form, a MapCache component will be added to your project automatically. Your form should now contain a Map, called Map1, and a MapCache component called 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 \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.

 

Adding Map Navigation

You can add map navigation features such as zoom and pan via the Key Navigation MapAction. This provides a set of ready made navigation functions driven by the Smartphone keys and cursor.

 


 

Add the Key Navigation MapAction to the project.

  1. Double click the Key Navigation MapAction from the Visual Studio Toolbox to your form. The map action will be added as a component to your project.
  2. Set the Map property for the map action to Map1.

 

Application exit

Unlike PocketPC or Windows applications, Smartphone application forms do not present an Ok or X in the top right corner to close the form. You will need to add code to properly close your application. For this walkthrough you will close the application by pressing soft key 1.

  1. Return to the designer view for your form.
  2. Click the menu area above Soft Key 1 in the designer view to create a new menu entry (MenuItem1).
  3. Type Exit for the text property.
  4. Double click the menu item to create a code stub.
  5. Enter the following code in menuItem1_Clickevent.

    [C#]
    private void menuItem1_Click(object sender, EventArgs e)
    {
      this.Close();
    }

 


 

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.

 

Configuring the Smartphone Emulator

You will use the Windows Mobile 5 Smartphone emulator to test the application but before you can it must be started and then virtually cradled.

  1. From the Visual Studio Tools menu, choose Device Emulation Manager.
  2. In the Device Emulator Manager dialog, locate the Windows Mobile 5 Smartphone Emulator, right click and select Connect. This will start the device emulator.
  3. Right click again on the Windows Mobile 5 Smartphone Emulator entry and select Cradle. This will cradle the emulator via ActiveSync. Select a Guest partnership if asked for the type of ActiveSync relationship. Hint: If ActiveSync does not automatically connect to the device you can try this manually in ActiveSync by selecting File -> Connection Settings, then click the Connect button and follow the wizard.

 

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 compile and run the application. Select the Windows Mobile 5 Smartphone emulator as the target device. At this stage the form should display layers from the map service in the map control.

Run the application

The Smartphone emulator does not have a file explorer to locate and run the executable when deployed, for this exercise you can run the application via the debugger.

  1. From the Visual Studio Debug menu, choose Start Debugging.
  2. If asked, deploy the application to the emulator. The application should start after a while.
  3. Close the application via Soft Key 1

Application Hint: Rather than using the debugger to run the application you can setup a shortcut from the excutable to the Windows start menu on the device. Explore the device using Activesync to setup the shortcut.

 

Experiment with the application. Zoom and pan the map via the Key Navigation keys.

 


 


Deployment

The application may be deployed to a Smartphone device using either of the methods described in the Deploying mobile adf applications topic.