Skip To Content

Use ArcGIS basemaps

In this topic

This topic describes how to build an iOS application to switch basemaps. It's assumed that you've already added a map to your application as described in the Add a map to your app tutorial.

The API provides a number of layers that allow you display map content from sources such as ArcGIS services, Bing Maps, Open Street Map, local tile packages, and many more.

Learn more about layers

In this topic, you'll use some of the map services that are freely available on ArcGIS Online.

1. Allow a user to switch basemaps

In this section, you'll modify the UI by adding a segmented control on top of the map. This segmented control needs to have options for Gray canvas, Oceans, National Geographic, Topographic, and Satellite maps.


When adding UI components, you typically also need to specify Auto Layout constraints for the components so that they can be properly sized and positioned when the layout of your application changes, for example, when the device is rotated. For the sake of simplicity, we will skip setting layout constraints in this tutorial, but you can look at the accompanying tutorial app to see these constraints in action.

Next, you need to connect the segmented control's Value Changed event to an action method, such as basemapChanged: on your view controller. This will allow you to respond whenever the user selects a new option on the control.

2. Replace layers in the map

In this section, you'll add the logic to switch basemaps. Depending on the option selected by the user, you'll instantiate a URL object pointing to the map service you want to use. Then, you'll instantiate a tiled layer using this URL, remove the existing basemap layer in the map, and insert the new one in its place.

@IBAction func basemapChanged(sender: UISegmentedControl) {

 var basemapURL:NSURL
 switch sender.selectedSegmentIndex {
  case 0: //gray
   basemapURL = NSURL(string: "")
  case 1: //oceans
   basemapURL = NSURL(string: "")
  case 2: //nat geo
   basemapURL = NSURL(string: "")
  case 3: //topo
   basemapURL = NSURL(string: "")
  default: //sat
   basemapURL = NSURL(string: "")

 //remove the existing basemap layer
 //add new Layer
 let newBasemapLayer = AGSTiledMapServiceLayer(URL: basemapURL)
 self.mapView.insertMapLayer(newBasemapLayer, withName: kBasemapLayerName, atIndex: 0);


3. Run the application

And that's it. You've written all the code required to switch the basemap layer of a map. All you need to do now is run the application.