Overview

You will learn: how to add feature layers to a 2D map.

With the ArcGIS Runtime SDK for Android, it is easy to create a mapping app that displays a basemap and layer that is a hosted feature service. 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 the 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 lab, you will build a simple mapping app with a basemap and a feature layer that represents trailheads near Los Angeles. The layer is hosted on ArcGIS Online.

Before you begin

Make sure you have installed the latest version of Android Studio.

Reuse the starter project

In a new or empty project folder, make a copy of the Create a starter app or download and unzip the project solution.

  • Open the new Android project in Android Studio.

  • Run the project and verify the project builds and the map displays in the device simulator.

  • You may be required to sync the project dependencies.

Steps

Add a layer to the map

  1. In the file app > java > {your.package.name} > MainActivity.java, add a new method to create a feature layer for the trailheads data and then add the layer to the map. Remember to use Alt + Enter on Windows (Option + Enter on Mac) to import ServiceFeatureTable and FeatureLayer.

     private void addTrailheadsLayer() {
         String url = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/";
         ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(url);
         FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
         ArcGISMap map = mMapView.getMap();
         map.getOperationalLayers().add(featureLayer);
     }
    
  2. Call the new method from the onCreate method, after connecting to the MapView.

       mMapView = findViewById(R.id.mapView);
       setupMap();
       // *** ADD ***
       addTrailheadsLayer();
    

Congratulations, you're done!

The app should run and show features displayed on top of a basemap. Compare your solution with our completed solution project.

Challenge

Change the feature data

Return to the data lab where you created the trailheads layer and add or remove trailhead locations. Rerun your app and see the layer update without any code changes.

Change symbology

Return to the data lab where you created the trailheads layer and change the symbol used for trailhead locations. Rerun your app and see the layer update without any code changes.