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 tutorial, you will build a simple mapping app with the topographic vector basemap and a feature layer that represents trailheads near Los Angeles.
Make sure you have installed the latest version of Xcode.
If you have completed the Create a starter app tutorial, then copy the project into a new empty folder. Otherwise, download and unzip the project solution. Open the
.xcodeproj file in Xcode. Run and verify the map displays in the device simulator.
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))
Press Command-R to run the app in the iOS Simulator.
The app should run and show features displayed on top of a basemap. Compare your solution with our completed solution project.
Visit the iOS SDK documentation to learn more about the different types of basemaps available. Try some different basemap types such as
.streetsWithReliefVector and pick your favorite basemap.
Try to add a few more park datasets into the map. Here are a few suggestions:
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)
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).
for how to populate the data in the case of