View on GitHub Sample viewer app

Display a route layer and its directions using a feature collection.

Image of display route layer

Use case

Routes can be stored as feature collection layers. These layers can store useful information such as directions, estimated trip time, and more.

You can create a route layer in ArcGIS Pro and store a route layer as a portal item, making it easy to access, share, or display.

How to use the sample

Pan and zoom to view the route displayed by the feature collection layer. The list of directions are displayed in the UI.

How it works

  1. Create a PortalItem with the item ID.
  2. Create and load a FeatureCollection with the item.
  3. After loading, get the specified ‘FeatureCollectionTable’ by name.
  4. Create an array of Features.
  5. Get the direction text from the attributes of each feature.
  6. Create a FeatureCollectionLayer with the feature collection and set it to the map’s operationalLayers.

Relevant API

  • FeatureCollection
  • FeatureCollectionLayer
  • FeatureCollectionTable

Tags

directions, feature collection, route layer

Sample Code

module-info.java module-info.java DisplayRouteLayerSample.java
/*
* Copyright 2023 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module com.esri.samples.display_route_layer {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// require JavaFX modules that the application uses
requires javafx.graphics;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
exports com.esri.samples.display_route_layer;
}