Add a feature layer from an item

Learn how to use a ID to access and display a feature layer in a map.

A map contains layers of geographic data. A map contains a basemap layer and, optionally, one or more data layers. This tutorial shows you how to access and display a feature layer in a map. You access feature layers with an item ID or URL. You will use item IDs to access the Trailheads, Trails, and Parks and Open Spaces feature layers and display in them in a map.

The following are required for this tutorial:

  1. An ArcGIS account to access your API keys. If you don't have an account, sign up for free.
  2. Your system meets the system requirements.
  3. The ArcGIS Runtime API for iOS is installed.

In your browser, go to the Trailheads Styled layer on ArcGIS Online and find the item ID at the end of the URL. It should be 2e4b3df6ba4b44969a3bc9827de746b3.


  1. Open the ViewController.swift file, update the setupMap() method to create an AGSPortal object and an AGSPortalItem object referencing the feature layer.

    Each portal item has a unique itemID, identified from its URL on ArcGIS Online.

    The feature layer referenced with this portal item contains trailheads in and around the Santa Monica Mountains.

          = AGSMap(basemapType: .navigationVector, latitude: 34.09042, longitude: -118.71511, levelOfDetail: 10)
         // *** ADD ***
         let portal = AGSPortal(url: URL(string: "")!, loginRequired: false)
         let item = AGSPortalItem(portal: portal, itemID: "2e4b3df6ba4b44969a3bc9827de746b3")
  2. Create an AGSFeatureLayer object from the portal item and a layer ID. Add the layer to the map's operational layers.

    A layer ID is required because a portal item may have more than one layer. For instance, when a feature service has 3 layers - trailheads (points), trails (polylines) and trail areas (polygons), the corresponding portal item would contain all three layers.

         let item = AGSPortalItem(portal: portal, itemID: "2e4b3df6ba4b44969a3bc9827de746b3")
         // *** ADD ***
         let layer = AGSFeatureLayer(item: item, layerID: 0)!.operationalLayers.add(layer)
  3. Press Command-R to run the app in the iOS Simulator.

    Other ways to run the project in Xcode:

    • In Xcode's app menu, select Product > Run.
    • Pressing the Run button at the top-left of the Xcode project window.

Congratulations, you're done!

Your app should display a map with the trailheads centered on the Santa Monica Mountains. Compare your solution with our completed solution project.