Create your first Runtime Application in 10 minutes

Retired
30th January 2013

ArcGIS Runtime enables you to build rich, highly functional GIS applications. The desktop version comes in WPF (.NET) or Java and has been designed to allow for quick development and easy deployment, but also power analysis. I want to show some of these features by providing some interesting resources and a quick tutorial on how you can rapidly develop a sample application. I will step through how to create a simple routing application that should take less than 10 minutes development time.

1.       Setup

The example will be based on the WPF version and you will need one of the development tool kits to start. The Runtime SDK is only available through a subscription to the Esri Developer Network (EDN). If you have a subscription the Runtime will be available to download and install. You will also need Visual Studio 2010 or 2012 for the WPF or Eclipse for Java. If you do not have an EDN subscription, don’t worry you can still continue with the WPF API. This is available to freely download from the Esri Resource Centre, here. This is an earlier version (2.4) of the WPF API used in the Runtime, which is currently at version 10.1.1. The WPF 2.4 version can be used to connect to online data and resources. It cannot work off-line like Runtime and is not as functionally rich but can give you a good feel for some of the functionality available in the full Runtime version. The workflow in the example will therefore be slightly different depending on the version installed. Once you have either the free WPF API or Runtime SDK installed continue to the next step.

2.       Sample Application

Next we will have a look at the sample application that comes with the Runtime. If you have the full Runtime SDK this should have been installed with the rest of the Runtime components. It is called ArcGIS Runtime WPF Samples 10.1.1 and will be in the installation folder. If not, it can be downloaded from ArcGIS Online here. The sample application has many different samples of the main functions you may need to develop with Runtime. It has a live sample and all the code that is used in the sample. The sample we want to use is under Geoprocessing > Network Routing > Drive Times Online. Find the sample and keep it open ready to cut and paste some code.

3.       Create Application

We are now going to create a WPF application. This step will differ depending on the API / SDK installed. If you have the full Runtime SDK, open Visual Studio (VS) and create a new project. As part of the SDK a template application is installed in VS, this should be under Installed Templates > Visual C# > Windows > ArcGIS >ArcGIS Runtime SDK 10.1.1 for WPF Application. Select this and choose a suitable location and name. If using the WPF 2.4 API, follow the instructions here to set up a project.

4.       Add Routing

Now we can add the routing capability from the sample application. This will be the same for both versions. We will be using the ArcGIS Online European routing service that is available for developers to use in their applications, details can be found here. First we will update the XAML code. Copy the code in the sample from the Grid tag, do not copy the UserControl tag. Paste this into your applications XAML below the Window tag overwriting the current XAML. Next copy the C# code behind from the sample; you need to copy the code from the first private void method, MyMap_MouseClick. Make sure to leave two curly brackets at the end and not to copy them. Paste it into the C# code in your application after the public MainWindow() method. You will also need to add a reference to Client Tasks at the top of the application like:

using ESRI.ArcGIS.Client.Tasks;

If you run the application it should start up in Redlands and the routing should work. We want to use the European routing service and start the map in Aylesbury in the UK. To add the European routing service, copy the REST end point from the link above and paste it into the url tag of the RouteTask in the XAML:

<esri:RouteTask

 x:Key=”MyRouteTask”

 Failed=”MyRouteTask_Failed”

 SolveCompleted=”MyRouteTask_SolveCompleted”

 Url=”http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_EU/NAServer/Route” />

 

5.       Add Aylesbury basemap

Now we are going to add the base map for the application. There will be two different ways of doing this. For the full Runtime SDK we are going to use a local tile cache and for the WPF 2.4 API we will use an ArcGIS Online basemap as we cannot use local off-line data with this API.

5.1   Full Runtime

Here we will be using a tile package for the basemap. Packages are the medium through which Runtime can work off-line. Tile, Map, Geoprocessing and locator packages can be created in ArcGIS Desktop 10.1 and accessed by the Runtime. For this example I have created a tile package of Aylesbury from Ordnance Survey Open Data, it can be downloaded here. Put the package in an appropriate folder that can be accessed by the application.

In the XAML code replace the <esri:ArcGISTiledMapServiceLayer tag from the sample code with <esri:ArcGISLocalTiledLayer, providing the path to the tile package that has just been downloaded. It should look like:

 

            <esri:ArcGISLocalTiledLayer ID=”Aylesbury” Path=”Data\OS_Open_Base_Map_Aylesbury.tpk”/>

 

Remove the Extent property from the esri:Map tag. Now run the application, it should open with a map on Aylesbury, and click the map to add locations to return the simple routing.

5.2   WPF 2.4

Here we are going to add the ArcGIS World Street Map and set the extent to Aylesbury. First change the url in the <esri:ArcGISTiledMapServiceLayer tag from the World­_2D basemap to the World Street Map, url below:

http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer

 

 

Change the Extent property in the Map tag to:

Extent=”-122540,6753761,-59385,6808602″

It should now look like:

<esri:Map x:Name=”MyMap” WrapAround=”True” Background=”White” Extent=”-122540,6753761,-59385,6808602″

 MouseClick=”MyMap_MouseClick”>

            <esri:Map.Layers>

                <esri:ArcGISTiledMapServiceLayer

Url=”http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer”/>

 

Run the application, it should open with a map centred on Aylesbury, click the map to add locations to return the simple routing.

That’s It

Hopefully that was not too difficult to follow and you now have a simple routing application. I have been working with the Runtime since it was released and think it is a really nice toolkit that can be used to build very powerful mapping applications. There are lots of resources to make development quick and simple, many of which I have referenced here. If you want to develop a desktop mapping application or integrate mapping into your current desktop application, Runtime is now the easiest way to do this and should be the first point of call.

 

Retired