Add a feature layer

Learn how to use a URL to access and display a feature layer in a map.

add a feature layer

A feature layer is a visual representation of feature table data. Feature layers contain features with a geometry type (point, line, or polygon), and attributes. You can use feature layers to store, access, and manage large amounts of geographic data for your applications. You can access features from a feature layer using its underlying feature table.

In this tutorial, you use a URL to create, access, and display a feature layer in your app by first creating a local feature table from an ArcGIS Online service: Trailheads (points).

Prerequisites

Before starting this tutorial:

  1. You need an ArcGIS Location Platform or ArcGIS Online account.

  2. Confirm that your system meets the system requirements.

  3. An IDE for Android development in Kotlin.

Steps

Open an Android Studio project

  1. To start this tutorial, complete the Display a map tutorial. Or download and unzip the Display a map solution in a new folder.

  2. Modify the old project for use in this new tutorial. Expand More info for instructions.

  3. If you downloaded the solution, get an access token and set the API key.

Add import statements

Replace app-specific import statements with the imports needed for this tutorial.

MainActivity.kt
Use dark colors for code blocks
17 18 19 20 21 22 23 24 25 26 27 28 29 30
Change lineChange lineChange lineChange lineChange lineChange lineChange 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.example.app

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment
import com.esri.arcgisruntime.data.ServiceFeatureTable
import com.esri.arcgisruntime.layers.FeatureLayer
import com.esri.arcgisruntime.mapping.ArcGISMap
import com.esri.arcgisruntime.mapping.BasemapStyle
import com.esri.arcgisruntime.mapping.Viewpoint
import com.esri.arcgisruntime.mapping.view.MapView

import com.example.app.databinding.ActivityMainBinding

Change the view point scale

  1. In the setupMap() method, modify the Viewpoint constructor call so it passes a scale parameter more appropriate to this tutorial.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    73 74 75 76 77 78 79 80 81 82 83 84
    Change lineChange 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
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        // set up your map here. You will call this method from onCreate()
        private fun setupMap() {
            // create a map with the BasemapStyle topographic
            val map = ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC)
    
            // set the map to be displayed in the layout's MapView
            mapView.map = map
    
            // set the viewpoint, Viewpoint(latitude, longitude, scale)
            mapView.setViewpoint(Viewpoint(34.0270, -118.8050, 200000.0))
    
        }
    
    Expand

Create a service feature table to reference feature service data

To display a new data layer (also known as an operational layer) on top of the current basemap, you will create a ServiceFeatureTable using an URL to reference the dataset hosted in ArcGIS Online.

  1. 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 ArcGIS Runtime app, you only need the URL.

  2. In the setupMap() method, create a ServiceFeatureTable, using a string URL to reference the dataset. You will add Trailheads (points).

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    73 74 75 76 77 78 79 80
    Add line.Add line.Add 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
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        // set up your map here. You will call this method from onCreate()
        private fun setupMap() {
            // create a map with the BasemapStyle topographic
            val map = ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC)
    
            // create the service feature table
            val serviceFeatureTable =
                ServiceFeatureTable("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0")
    
    Expand

Create a feature layer to display the hosted data

You will create a new FeatureLayer to display the hosted layer above the basemap.

  1. 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.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    78 79 80 81 82 83 84
    Add line.Add line.Add 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
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
            // create the service feature table
            val serviceFeatureTable =
                ServiceFeatureTable("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0")
    
            // create the feature layer using the service feature table
            val featureLayer = FeatureLayer(serviceFeatureTable)
            map.operationalLayers.add(featureLayer)
    
    Expand
  2. Click Run > Run > app to run the app.

You should see point features (representing trailheads) draw on the map for an area in the Santa Monica Mountains in southern California.

What's next?

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.