Learn how to use a URL 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 URLs to access the Trailheads, Trails, and Parks and Open Spaces feature layers and display them in a map.
Prerequisites
Before starting this tutorial:
-
You need an ArcGIS Location Platform or ArcGIS Online account.
-
Your system meets the system requirements.
Steps
Open the Xcode project
-
To start the tutorial, complete the Display a map tutorial or download and unzip the solution.
-
Open the
.xcodeproj
file in Xcode. -
If you downloaded the solution, get an access token and set the API key.
An API Key gives your app access to secure resources used in this tutorial.
-
Go to the Create an API key tutorial to obtain a new API key access token. Ensure that the following privilege is enabled: Location services > Basemaps > Basemap styles service. Copy the access token as it will be used in the next step.
-
In Xcode, in the Project Navigator, click MainApp.swift.
-
In the Editor, set the
ArcGISEnvironment.apiKey
property on theArcGIS
with your access token.Environment MainApp.swiftUse dark colors for code blocks init() { ArcGISEnvironment.apiKey = APIKey("<#YOUR-ACCESS-TOKEN#>") }
-
Add a feature layer to the map
-
In the project navigator, open the ContentView.swift file. Update the
map
object. Create aService
to access the trail heads data and aFeature Table Feature
to view it. Add the layer to the map's operational layers.Layer -
A
Service
is effectively an in-memory database of the features from a service URL.Feature Table -
A
Feature
andLayer Service
work together to request, cache locally, and display features on a map.Feature Table -
Operational layers are map layers that users can interact with and appear overlaid on top of the basemap.
ContentView.swiftUse dark colors for code blocks @State private var map: Map = { let map = Map(basemapStyle: .arcGISTopographic) map.initialViewpoint = Viewpoint(latitude: 34.02700, longitude: -118.80500, scale: 72_000) let featureServiceURL = URL(string: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0")! let serviceFeatureTable = ServiceFeatureTable(url: featureServiceURL) let trailheadsLayer = FeatureLayer(featureTable: serviceFeatureTable) map.addOperationalLayer(trailheadsLayer) return map }()
-
-
Press Command + R to run the app.
If you are using the Xcode simulator your system must meet these minimum requirements: macOS Monterey 12.5, Xcode 15, iOS 17. If you are using a physical device, then refer to the system requirements.
You should see point, line, and polygon features (representing trailheads, trails, and parks) draw on the map for an area in the Santa Monica Mountains.
What's Next?
Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: