Consuming WebMaps from with ArcGIS Runtime for iOS

ArcGIS Online brings the concept of WebMaps, a ready to use intelligent map that includes a way to “mashup” of all your data. WebMaps are highly configurable for any user wanting to tell a story or share their geographic information. Those maps are stored in the cloud to be available and easy accessible using a browser with nothing to install on your computer.

ArcGIS Runtime for iOS provides Objective-C developers access to consume and display webmaps on Apple Mobile devices. Developing for those mobile devices and deploying to the App Store has changed the practices of releasing applications.

Now the iOS developer has to wait seven to ten days, on average, to get their application posted to the online store for users to be able to consume them. Configuration now on those applications, with all resources embedded, are bundle to a common file to be deployed. For this now common scenario the task of the developer is more difficult to change the configuration of those resources on released applications. In the worse possible case scenario if a resource used in the application needs to change, the developer would have to make modifications to the code or project and submit the new binary to Apple for review, before gets acceptance and finally published to the App Store. Because of this exact problem when a resource needs to change or when is not available anymore due different reasons.

Developers are looking for configurations to those applications that won’t require a binary changes avoiding the delay and possible keeping the application from working for long periods of time until Apple review process happens. For GIS and map developers using iOS the ArcGIS Online infrastructure can be a valuable solution to this problem.

In this blog post we show how to use the ArcGIS Runtime for iOS, however this scenario is not limited to iOS, the same functionality can be found on all ArcGIS Runtimes to consume WebMaps.

ArcGIS Online allows developers to create and customize maps using a browser and store them in the Cloud using a simple user experience. Maps created using ArcGIS Online can be deployed to the web, desktop or mobile devices or share it with only the users you want. To learn more about the capabilities and features of webmap including the customization you can read them at the resource page

With the webmap, also known as intelligent map, a unique identifier will be created with that map to be consume. At any time, the developer can make changes to the webmap and will reflect on the client application.

Creating a WebMap at ArcGIS Online

Sign into ArcGIS Online and Click Map, you’ll be able to select your basemap and extent you want to display at startup.

The Add button will allow you to customize the map and add your layers from the web as well as upload different formats to “mashup” with the basemap.

You can add information to that map including notes and external resources such as:

  • shapefiles, GPX files, CSV files containing addresses to geocode,
  • OGC WMS Web Services, KML or ArcGIS Server Web Services.

All those layers you add to the basemap will be stored in the WebMap after saving, then you can retrieve the WebMap at anytime and make any modifications you want, including adding more layer or editing Map Notes. There are extensive of functionality in ArcGIS online to customize and add information to the map is beyond this blog post and won’t be able cover.

Next step is saving the WebMap and select if you would like to share it with other users or even make it public. A good description and tags makes the map easier to find at ArcGIS Online.

ArcGIS Online will produce the WebMap and a unique identifier that you can use for consuming on different devices and frameworks, in this case we going to use it with the ArcGIS Runtime for iOS.

After this very quick tutorial for creating a map using ArcGIS Online, let’s write a little code to consume it on an iPhone or iPad.

Automatic Reference Counting (ARC)

With xCode 4.2 and above Apple released a new feature called; Automatic Reference Counting as a compiler feature that provides automatic memory management in Objective-C, to avoiding the developer being the one thinking about retain and release objects. ARC is not garbage collection, is a compilation time instead of run time.

All the sample code in this blog are implemented using ARC.

Creating an xCode project to consume a configurable map

Let’s begin by creating a new xCode iOS application project, for this blog post we’ll be using the version 2.3 of the ArcGIS Runtime for iOS.

You can use the simple MapView sample installed on your Mac or create a new project and configure to run the ArcGIS Runtime for iOS, instructions for configuring the project can be found here:

Once you created the project and is configured with a AGSMapView the next step will be to open the WebMap to display on your View, to do so there are 3 pieces of information you’ll need, the ArcGIS portal Url in case you have installed your instance of the portal instead of using the; the username and password you want to use, if the webmap is secured ( you can skip that if you published the map publicly) as well as the unique identifier for the webmap created.

Make sure to use the WebMap created on the previous step, if you didn’t share the webmap publicly, the username and password is required to generate the AGSCredential.

For the WebMap API AGSWebMap there is a delegate to be use to get notifications of events happening on the WebMap, that delegate is called AGSWebMapDelegate and can be reference on the interface of the class to receive the notifications. If you are not familiar with delegates in developing for the Apple platform, I do recommend you to read this first.

That will provide you with methods to know when a WebMap has been loaded, open or failed to load, as well as the reason on the error parameter in case of failure. That parementer is very useful when you want to display the error to the user.

You may want to warn the user, like the code above, when a WebMap failed to open and the reason a UIAlertView is shown to the user.

This simple code above will display to the user on an iOS device the map you have configured in ArcGIS Online. Now you can always go to ArcGIS Online to change layers, add map notes or change the initial extent and basemap, the changes will be reflected on the iOS mobile application without having to redeploy the binary to the app store. Having the configuration of the map outside of the application is a great benefit, even more when there is a great user interface to make those changes and see the result before saving it.

WebMaps are stored in the Cloud and available where Internet is present, those maps are not offline, therefore the developer needs to make an effort to provide a feedback interface to the user on the chance the WebMap is not available due connectivity with Internet.

Reachability Framework

Apple provided a sample class to include on your project to notify you on the access to the Internet from the device. This is a good practice to include on projects containing resources downloaded from the Internet or that require Internet access like Maps, when panning, zooming, etc. The application consumes that information from ArcGIS Online or other servers. Therefore those mobile applications are using actively making requests. The Reachability framework allows notifying the user when the device cannot connect to the Internet, due Wi-Fi issue or the device is in a poor area for 3G/4G coverage.  Avoid user experiences where the user waits for a map panning or zooming when the Internet is not reachable.

To find more information about the Reachability Framework, you can download the sample code from Apple here.

Because in this sample we are using Automatic Reference Counting (ARC). You’ll be able to find the ARC version of the reachability framework at GitHub (by Tony Million)

Sample Source Code

Sample source code using WebMaps and ArcGIS Online API with ArcGIS Runtime for iOS can be found here

To keep up to date with important changes and resources you can follow the twitter account for the ArcGIS Runtimes at @ArcGIS_Runtime

The ArcGIS Sample for iOS: Routing and Offline Inspections, shown at the Esri Developer Summit 2012, source code is now at GitHub.

Happy forking.

Related Posts

New versions of Runtime SDKs for WP, iOS and Android released (by Will Crick)

This entry was posted in Developer, Mobile and tagged , , , , , , . Bookmark the permalink.

Leave a Reply