Learn how to use a URL to access and display a feature layer A feature layer (server-side) is a spatially-enabled table in a feature service. All features in a feature layer share the same geometry type and set of fields. Learn more in a map. A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more

add a feature layer

A feature layer A feature layer (server-side) is a spatially-enabled table in a feature service. All features in a feature layer share the same geometry type and set of fields. Learn more is a dataset in a feature service A feature service is a data service that provides access to spatial and non-spatial data in feature layers, feature layer views, and tables. Learn more hosted in ArcGIS ArcGIS is the brand name for all of the desktop, server, and developer products and technologies offered by Esri. Learn more . Each feature layer contains features A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. Learn more with a single geometry A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more type ( point A point is a type of geometry containing a single set of x,y coordinates and a spatial reference. Learn more , line A polyline is a type of geometry containing ordered point coordinates and a spatial reference. Learn more , or polygon A polygon is a type of geometry containing an array of rings and a spatial reference. Each ring contains an array of point coordinates, where the first and last point are the same. Learn more ), and a set of attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more . 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 A feature table is a database table of a single geometry type, such as point, line, or polygon, that stores features that conform to the schema of the table. Learn more .

In this tutorial, you use URLs to access and display three different feature layers A feature layer (server-side) is a spatially-enabled table in a feature service. All features in a feature layer share the same geometry type and set of fields. Learn more hosted in ArcGIS Online ArcGIS Online is a GIS mapping, analytics, data hosting, and content management software as a service (SaaS) product. It includes applications, tools, APIs, and location services for users and developers. It is subscription-based and requires an ArcGIS Online account. Learn more :

Prerequisites

Before starting this tutorial:

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

  2. Confirm that your system meets the minimum system requirements.

  3. An IDE for Java.

Steps

Open a Java project with Gradle

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

  2. Open the build.gradle file as a project in IntelliJ IDEA.

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

Add import statements

Add import statements to reference the API classes.

  1. In the IntelliJ IDEA’s Project tool window, open src/main/java/com.example.app and double-click App.

  2. Add the following imports above the existing imports.

    App.java
    import com.esri.arcgisruntime.data.ServiceFeatureTable;
    import com.esri.arcgisruntime.layers.FeatureLayer;
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    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;
  3. In the start() life-cycle method, change the title that will appear on the application window to Add a feature layer.

    App.java
    @Override
    public void start(Stage stage) {
    // set the title and size of the stage and show it
    stage.setTitle("Add a feature layer tutorial");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.show();

Create service feature tables to reference feature service data

To display three new data layers A data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more (also known as operational layers) on top of the current basemap, you will create ServiceFeatureTable objects using URLs to reference datasets hosted in ArcGIS Online ArcGIS Online is a GIS mapping, analytics, data hosting, and content management software as a service (SaaS) product. It includes applications, tools, APIs, and location services for users and developers. It is subscription-based and requires an ArcGIS Online account. Learn more .

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

  2. In the start() method, create three ServiceFeatureTable objects, using a string URL in each to reference the datasets. You will add: Trailheads (points), Trails (lines), and Parks and Open Spaces (polygons).

    App.java
    50 collapsed lines
    package com.example.app;
    import com.esri.arcgisruntime.data.ServiceFeatureTable;
    import com.esri.arcgisruntime.layers.FeatureLayer;
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    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 javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    public class App extends Application {
    private MapView mapView;
    public static void main(String[] args) {
    Application.launch(args);
    }
    @Override
    public void start(Stage stage) {
    // set the title and size of the stage and show it
    stage.setTitle("Add a feature layer tutorial");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.show();
    // create a JavaFX scene with a stack pane as the root node, and add it to the scene
    StackPane stackPane = new StackPane();
    Scene scene = new Scene(stackPane);
    stage.setScene(scene);
    ArcGISRuntimeEnvironment.setApiKey("YOUR_ACCESS_TOKEN");
    // create a map view to display the map and add it to the stack pane
    mapView = new MapView();
    stackPane.getChildren().add(mapView);
    ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
    // set the map on the map view
    mapView.setMap(map);
    mapView.setViewpoint(new Viewpoint(34.02700, -118.80543, 144447.638572));
    String parksUrl = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space_Styled/FeatureServer/0";
    String trailsUrl = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails_Styled/FeatureServer/0";
    String trailHeadsUrl = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads_Styled/FeatureServer/0";
    ServiceFeatureTable parksServiceFeatureTable = new ServiceFeatureTable(parksUrl);
    ServiceFeatureTable trailsServiceFeatureTable = new ServiceFeatureTable(trailsUrl);
    ServiceFeatureTable trailHeadsServiceFeatureTable = new ServiceFeatureTable(trailHeadsUrl);
    14 collapsed lines
    }
    /**
    * Stops and releases all resources used in application.
    */
    @Override
    public void stop() {
    if (mapView != null) {
    mapView.dispose();
    }
    }
    }

Create feature layers to display the hosted data

You will create three new FeatureLayer objects to display the hosted layers above the basemap.

  1. Create three new FeatureLayer objects using the service feature tables and add them to the map as data (operational) layers.

    Data layers A data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more are displayed in the order in which they are added. Polygon A polygon is a type of geometry containing an array of rings and a spatial reference. Each ring contains an array of point coordinates, where the first and last point are the same. Learn more layers should be added before layers with lines A polyline is a type of geometry containing ordered point coordinates and a spatial reference. Learn more or points A point is a type of geometry containing a single set of x,y coordinates and a spatial reference. Learn more if there’s a chance the polygon symbols will obscure features beneath.

    App.java
    58 collapsed lines
    package com.example.app;
    import com.esri.arcgisruntime.data.ServiceFeatureTable;
    import com.esri.arcgisruntime.layers.FeatureLayer;
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    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 javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    public class App extends Application {
    private MapView mapView;
    public static void main(String[] args) {
    Application.launch(args);
    }
    @Override
    public void start(Stage stage) {
    // set the title and size of the stage and show it
    stage.setTitle("Add a feature layer tutorial");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.show();
    // create a JavaFX scene with a stack pane as the root node, and add it to the scene
    StackPane stackPane = new StackPane();
    Scene scene = new Scene(stackPane);
    stage.setScene(scene);
    ArcGISRuntimeEnvironment.setApiKey("YOUR_ACCESS_TOKEN");
    // create a map view to display the map and add it to the stack pane
    mapView = new MapView();
    stackPane.getChildren().add(mapView);
    ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
    // set the map on the map view
    mapView.setMap(map);
    mapView.setViewpoint(new Viewpoint(34.02700, -118.80543, 144447.638572));
    String parksUrl = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space_Styled/FeatureServer/0";
    String trailsUrl = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails_Styled/FeatureServer/0";
    String trailHeadsUrl = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads_Styled/FeatureServer/0";
    ServiceFeatureTable parksServiceFeatureTable = new ServiceFeatureTable(parksUrl);
    ServiceFeatureTable trailsServiceFeatureTable = new ServiceFeatureTable(trailsUrl);
    ServiceFeatureTable trailHeadsServiceFeatureTable = new ServiceFeatureTable(trailHeadsUrl);
    map.getOperationalLayers().add(new FeatureLayer(parksServiceFeatureTable));
    map.getOperationalLayers().add(new FeatureLayer(trailsServiceFeatureTable));
    map.getOperationalLayers().add(new FeatureLayer(trailHeadsServiceFeatureTable));
    14 collapsed lines
    }
    /**
    * Stops and releases all resources used in application.
    */
    @Override
    public void stop() {
    if (mapView != null) {
    mapView.dispose();
    }
    }
    }
  2. Run the app. Ensure to run the app as a Gradle task and not as an application in your IDE. In the Gradle tool window, under Tasks > application, double-click run.

You should see point, line, and polygon features (representing trailheads, trails, and parks) 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: