Add a feature layer
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 URL s 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:
In the project navigator, open the ViewController.swift file. Update the
setupMap()method to create an
AGSServiceFeatureTableto access the trail heads data and an
AGSFeatureLayerto view it. Add the layer to the map's operational layers.
AGSServiceFeatureTableis effectively an in-memory database of the features from a service URL.
Operational layers are map layers that users can interact with and appear overlaid on top of the basemap.
The trail heads feature service was created in advance for this tutorial. Review the Style feature layers tutorial to learn how.
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))
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.
- Press the Run button at the top-left of the Xcode project window.
The app should run and show features displayed on top of a basemap. Compare your solution with our completed solution project.