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.
NoteTo learn more about working with feature layers, see Data hosting.
PrerequisitesBefore starting this tutorial:
You need an ArcGIS Location Platform or ArcGIS Online account.
Your system meets the system requirements.
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 using your ArcGIS Location Platform or ArcGIS Online account. 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 AppDelegate.swift.
In the editor, set the APIKey
property on the AGSArcGISRuntimeEnvironment
with your access token.
AppDelegate.swift
Expand
Use dark colors for code blocks1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AGSArcGISRuntimeEnvironment.apiKey = "YOUR_ACCESS_TOKEN"
return true
}
Warning
The access token is stored directly in the code as a convenience for this tutorial. Storing access tokens in the source code is not best practice.
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.
ViewController.swift
Use dark colors for code blocks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
private func setupMap() {
let map = AGSMap(basemapStyle: .arcGISTopographic)
let featureLayer: AGSFeatureLayer = {
let featureServiceURL = URL(string: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0")!
let trailheadsTable = AGSServiceFeatureTable(url: featureServiceURL)
return AGSFeatureLayer(featureTable: trailheadsTable)
}()
map.operationalLayers.add(featureLayer)
mapView.map = map
mapView.setViewpoint(
AGSViewpoint(
latitude: 34.09042,
longitude: -118.71511,
scale: 200_000
)
)
}
Press Command + R to run the app.
If you are using the Xcode simulator your system must meet these minimum requirements: macOS Big Sur 11.3, Xcode 13, iOS 13. 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:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4