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.
A feature layer is a dataset in a feature service hosted in ArcGIS. Each feature layer contains features with a single geometry type (point, line, or polygon), and a set of attributes. You can use feature layers to store, access, and manage large amounts of geographic data for your applications.
In this tutorial, you use URLs to access and display three different feature layers hosted in ArcGIS Online:
Click File > Sync Project with Gradle files. Android Studio will recognize your changes and create a new .idea folder.
If you downloaded the solution project, set your API key.
An API Key enables access to services, web maps, and web scenes hosted in ArcGIS Online.
Go to your developer dashboard to get your API key.
For these tutorials, use your default API key. It is scoped to include all of the services demonstrated in the tutorials.
In Android Studio: in the Android tool window, open app > java > com.example.app > MainActivity.
In the setApiKey() function, find the ApiKey.create() call and paste your API key inside the quotes, replacing YOUR_API_KEY.
MainActivity.kt
Use dark colors for code blocks
Change line
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
privatefunsetApiKey() {
// It is not best practice to store API keys in source code. We have you insert one here// to streamline this tutorial. ArcGISEnvironment.apiKey = ApiKey.create("YOUR_API_KEY")
}
Add import statements
Replace app-specific import statements with the imports needed for this tutorial.
Create service feature tables to reference feature service data
To display three new data layers (also known as operational layers) on top of the current basemap, you will create ServiceFeatureTables using URLs to reference datasets hosted in ArcGIS Online.
Open a browser and navigate to the URL for Parks and Open Spaces to view metadata about the layer. To display the layer in your app, you only need the URL.
The service page provides information such as the geometry type, the geographic extent, the minimum and maximum scale at which features are visible, and the attributes (fields) it contains. You can preview the layer by clicking on ArcGIS.com Map in the "View In:" list at the top of the page.
In Android Studio, open app > java > com.example.app > MainActivity.
You will create new FeatureLayers to display the hosted layers above the basemap.
Create a new FeatureLayer using the service feature table and add it to the map as a data (operational) layer.
If an app has multiple data layers, they are displayed in the order in which they are added to the app.
A FeatureLayer is simply a reference to a feature service and a fast and easy way to add data to a map. It is accessed via a URL which specifies the endpoint. By default, the API will try to load all of the features that fit into the current view.