Overview

You will learn: how to add feature layers to a 2D map.

With the ArcGIS Runtime SDK for iOS and ArcGIS Online it's easy to create a new web mapping app that displays a basemap and layer. ArcGIS Online hosts a number of tile and vector tile basemaps that you can choose from, including streets, satellite, streets-vector, and streets-navigation-vector. You can also add your own datasets by adding feature layers. These layers are hosted by ArcGIS Online or by other ArcGIS servers. By default, feature layers will draw with pre-set symbols to fill the extent of map, but you can customize this by setting your own styles with a renderer or using a SQL expression to limit the data retrieved.

In this lab, you will build a simple mapping app with the topographic vector basemap and a feature layer that represents trailheads near Los Angeles.

Before you begin

Make a copy of the finished Create a starter app lab (or download here) and open the .xcodeproj file in Xcode.

Steps

Add a layer to the map

  1. In the project navigator, open the ViewController.swift file. Update the setupMap() method to create an AGSServiceFeatureTable to access the trail heads data and an AGSFeatureLayer to view it. Add the layer to the map's operational layers.

         mapView.map = AGSMap(basemapType: .topographicVector, latitude: 34.09042, longitude: -118.71511, levelOfDetail: 10)
    
         // *** ADD ***
         let featureServiceURL = URL(string: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0")!
         let trailheadsTable = AGSServiceFeatureTable(url: featureServiceURL)
         mapView.map!.operationalLayers.add(AGSFeatureLayer(featureTable: trailheadsTable))
    
  2. Press Command-R to run the app in the iOS Simulator.

Congratulations, you're done!

The app should run and show features displayed on top of a basemap. Compare your solution with our completed solution project.

Challenge

Explore basemap

Visit the iOS SDK documentation to learn more about the different types of basemaps available. Try some different basemap types such as .lightGrayCanvasVector, .topographicVector or .streetsWithReliefVector and pick your favorite basemap.

Add more layers

Try to add a few more park datasets into the map. Here are a few suggestions:

  • Trails

    https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer

  • Parks and Open Spaces

    https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer

Filter features

Sometimes it's necessary to limit the data retrieved from a service. One way to accomplish this is by applying a SQL expression to the layer. Try defining an expression that limits the city to Los Angeles.

      let trailsTable = AGSServiceFeatureTable(url: URL(string: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer")!)
      let trailsLayer = AGSFeatureLayer(featureTable: trailsTable)
      trailsLayer.definitionExpression = "ELEV_GAIN < 250"
      map.operationalLayers.add(trailsLayer)

Investigate the feature request mode

By default, an AGSServiceFeatureTable stores retrieved features using On Interaction Cache mode. See here and here for more details.

Depending on the nature of your data and your app, you might choose to use Interaction No Cache (to get data that changes often) or Manual Cache (to get small amounts of data regardless of the map view extent).

See here for how to populate the data in the case of Manual Cache.