You will learn: how to create a new feature collection with a point feature collection table. The feature collection is then displayed on a map as a layer.

With the ArcGIS Runtime SDK for Android it's easy to create and add features to feature collections and display them on a map. A feature collection is a type of feature layer that holds static collections of features stored as JSON inside a map or portal item. Any feature collection can be saved as part of the map and edited like other feature layers. FeatureCollections are useful for adding and storing features, including their geometry and attributes, directly within a web map (no URL is used with feature collections.) Feature collections contain one or more feature collection tables and originate from shapefiles, CSVs, GPX files, or programatically as you will do in this lab.

In this lab, you will build an app that creates 3 point features, adds them to a Feature Collection Table, and then displays them in a Feature Layer on the map. The features will be created directly from latitude and longitude coordinates.

Before you begin

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

You must have previously installed the ArcGIS Runtime SDK for Android and set up your development environment. Please review the install and set up instructions if you have not done this.

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.


Add a FeatureCollectionLayer to the map view

  1. In the file app > java > {your.package.name} > MainActivity.java, add a new method named createFeatureCollection(). Create a FeatureCollection and a FeatureCollectionLayer. Add the FeatureCollectionLayer to the map view. Remember to use Alt + Enter on Windows (Option + Enter on Mac) to import FeatureCollection and FeatureCollectionLayer.

    private void createFeatureCollection() {
        if (mMapView != null) {
            FeatureCollection featureCollection = new FeatureCollection();
            FeatureCollectionLayer featureCollectionLayer = new FeatureCollectionLayer(featureCollection);
  2. Add a new private method createPointTable. Define it so that it takes a FeatureCollection as a parameter. This method will create the FeatureCollectionTable and add features to it. Each feature must have a symbol assigned in order to be visible on the map. Also create an ArrayList variable to hold the list of features in the collection.

    private void createPointTable(FeatureCollection featureCollection) {
         List<Feature> features = new ArrayList<>();
  3. Define the schema for the feature collection table by adding field definitions to an ArrayList, as follows:

         List<Feature> features = new ArrayList<>();
         // *** ADD ***
         List<Field> pointFields = new ArrayList<>();
         pointFields.add(Field.createString("Place", "Place Name", 50));
  4. Create a FeatureCollectionTable object using the schema created in the previous step:

         pointFields.add(Field.createString("Place", "Place Name", 50));
         // *** ADD ***
         FeatureCollectionTable pointsTable = new FeatureCollectionTable(pointFields, GeometryType.POINT, SpatialReferences.getWgs84());
  5. Create the symbol and renderer that will be used to visualize the features on the map:

         FeatureCollectionTable pointsTable = new FeatureCollectionTable(pointFields, GeometryType.POINT, SpatialReferences.getWgs84());
         // *** ADD ***
         SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, 0xFF0000FF, 18);
         SimpleRenderer renderer = new SimpleRenderer(simpleMarkerSymbol);
  6. Add the table to the featureCollection object:

         // *** ADD ***
  7. Create a feature for each of the 3 sporting venues that will be added to the pointTable:

         // *** ADD ***
         // Dodger Stadium
         Map<String, Object> attributes1 = new HashMap<>();
         attributes1.put(pointFields.get(0).getName(), "Malibu Pier");
         Point point1 = new Point(-118.676726, 34.037288, SpatialReferences.getWgs84());
         features.add(pointsTable.createFeature(attributes1, point1));
         // Los Angeles Memorial Coliseum
         Map<String, Object> attributes2 = new HashMap<>();
         attributes2.put(pointFields.get(0).getName(), "Malibu Hindi Temple");
         Point point2 = new Point(-118.709726, 34.095097, SpatialReferences.getWgs84());
         features.add(pointsTable.createFeature(attributes2, point2));
         // Staples Center
         Map<String, Object> attributes3 = new HashMap<>();
         attributes3.put(pointFields.get(0).getName(), "Escondido Falls");
         Point point3 = new Point(-118.779438, 34.044211, SpatialReferences.getWgs84());
         features.add(pointsTable.createFeature(attributes3, point3));
  8. Add the features asynchronously to the pointTable. This completes the createPointTable method.

         features.add(pointsTable.createFeature(attributes3, point3));
         // *** ADD ***
  9. Inside the setupMap() method, after adding the FeatureCollectionLayer to the map, make a call to the method you just created.

            // *** ADD ***
  10. Run the app and you should see 3 blue triangles positioned in the Los Angeles area.

Congratulations, you're done!

Your map should show a vector tiled basemap with the locations for Dodger Stadium, Staples Center, and the LA Coliseum, prominent sports venues in the Los Angeles area. Compare your solution with our completed solution project.


Add features with different symbols and styles

  1. Use a UniqueValueRenderer instead of the SimpleRenderer to display the features: UniqueValueRenderers are used to symbolize groups of features or graphics (see GeoElement that have matching attributes. This is most common with nominal, or string, data.
  2. Add a text symbol: TextSymbols are used to display text for graphics and features. Add text symbols for the point features used in the lab.
  3. Change the marker symbol: Use a different shape (for example a square) for the SimpleMarkerSymbol used in the lab using the available styles.