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

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 contains layers A layer is a reference to a collection of geographic data that is used to access and display data. The data for layers are typically provided by the basemap layer service and data services. Learn more of geographic data. A map contains a basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and, optionally, one or more 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 . This tutorial shows you how 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 . You access feature layers with an item An item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. Learn more ID or URL. You will use URLs to access the Trailheads, Trails, and Parks and Open Spaces feature layers and display them in a map.

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.

Prerequisites

Before starting this tutorial:

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

  2. Your system meets the system requirements.

  3. The ArcGIS Maps SDK for Qt, version 200.8.0 or later is installed.

  4. The Qt 6.8.2 software development framework or later is installed.

Develop or Download

You have two options for completing this tutorial:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

To start the tutorial, complete the Display a map tutorial. This creates a map to display the Santa Monica Mountains in California using the topographic basemap from the ArcGIS Basemap Styles service The ArcGIS Basemap Styles service, also referred to as the Basemap Styles service, is a location service that provides basemap styles and data for the world. It returns styles as Mapbox styles and web maps, and data as vector tiles and/or map tiles. It supports all of the styles in the ArcGIS Basemap style and Open Basemap style family. An ArcGIS Location Platform or ArcGIS Online account is required to use the service. Learn more .

Open a Qt Creator project

  1. Open the project you created by completing the Display a map tutorial.
  2. Continue with the following instructions to use a URL to access and display a feature layer in a map.

Include header files

  1. In the project Headers folder of Qt Creator, double-click the Display_a_map.cpp file to open it. Include these header files to be able to create ServiceFeatureTable and FeatureLayer instances.

    Display-a-map.cpp
    #include "Display_a_map.h"
    #include "Map.h"
    #include "MapTypes.h"
    #include "MapQuickView.h"
    #include "Point.h"
    #include "Viewpoint.h"
    #include "SpatialReference.h"
    #include <QFuture>
    #include "LayerListModel.h"
    #include "ServiceFeatureTable.h"
    #include "FeatureLayer.h"

Add a polygon feature layer

This tutorial will draw the map in following order:

  1. ArcGISTopographic basemap style layer
  2. Parks and Open Spaces (polygons)
  3. Trails (lines)
  4. Trailheads (points)

It is important to add feature layers in the correct order so features are displayed correctly. Polygon feature layers A feature layer (client-side) is a data layer that can access and display features from a feature service that has the same type of geometry and attribute fields. Learn more are typically created before lines or points, so that those features are not obscured by the polygons.

Use the FeatureLayer class to reference the Parks and Open Spaces URL and add features to the 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 .

  1. Go to the Parks and Open Spaces URL and browse the properties of the layer. You may want to explore the Name, Type, Drawing Info, and Fields properties.

  2. Within the setupViewpoint() method, add the following code. Create a QUrl instance named polygonFeatureUrl using an ArcGIS feature server as the feature data source. Then create a ServiceFeatureTable named polygon_feature_table from that QUrl.

    Display-a-map.cpp
    void Display_a_map::setupViewpoint()
    {
    const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
    const Viewpoint viewpoint(center, 100000.0);
    m_mapView->setViewpointAsync(viewpoint);
    const QUrl polygonFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
    ServiceFeatureTable* polygon_feature_table = new ServiceFeatureTable(polygonFeatureUrl, this);
    }
  3. Continuing within the setupViewpoint() method, you will create a FeatureLayer instance named polygon_feature_layer, passing in polygon_feature_table as the argument. Then append your new polygon_feature_layer to the Map instance named m_map.

    Display-a-map.cpp
    void Display_a_map::setupViewpoint()
    {
    const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
    const Viewpoint viewpoint(center, 100000.0);
    m_mapView->setViewpointAsync(viewpoint);
    const QUrl polygonFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
    ServiceFeatureTable* polygon_feature_table = new ServiceFeatureTable(polygonFeatureUrl, this);
    FeatureLayer* polygon_feature_layer = new FeatureLayer(polygon_feature_table, this);
    m_map->operationalLayers()->append(polygon_feature_layer);
    }

Add a line feature layer

Line 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 are typically displayed in a feature layer A feature layer (client-side) is a data layer that can access and display features from a feature service that has the same type of geometry and attribute fields. Learn more before points. Use the FeatureLayer class to reference the Trails URL and add features to the map, as described next.

  1. Staying within the setupViewpoint() method, add the following code to create a QUrl instance named lineFeatureUrl using the ArcGIS feature server as the feature data source, in this case, Trails_Styled. Then create a ServiceFeatureTable named line_feature_table from that QUrl.

    Display-a-map.cpp
    void Display_a_map::setupViewpoint()
    {
    const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
    const Viewpoint viewpoint(center, 100000.0);
    m_mapView->setViewpointAsync(viewpoint);
    const QUrl polygonFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
    ServiceFeatureTable* polygon_feature_table = new ServiceFeatureTable(polygonFeatureUrl, this);
    FeatureLayer* polygon_feature_layer = new FeatureLayer(polygon_feature_table, this);
    m_map->operationalLayers()->append(polygon_feature_layer);
    const QUrl lineFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trails/FeatureServer/0");
    ServiceFeatureTable* line_feature_table = new ServiceFeatureTable(lineFeatureUrl, this);
    }
  2. Continuing within the setupViewpoint() method, create a FeatureLayer instance named line_feature_layer, passing in line_feature_table as the argument. Then append your new line_feature_layer to the Map instance named m_map.

    Display-a-map.cpp
    void Display_a_map::setupViewpoint()
    {
    const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
    const Viewpoint viewpoint(center, 100000.0);
    m_mapView->setViewpointAsync(viewpoint);
    const QUrl polygonFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
    ServiceFeatureTable* polygon_feature_table = new ServiceFeatureTable(polygonFeatureUrl, this);
    FeatureLayer* polygon_feature_layer = new FeatureLayer(polygon_feature_table, this);
    m_map->operationalLayers()->append(polygon_feature_layer);
    const QUrl lineFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trails/FeatureServer/0");
    ServiceFeatureTable* line_feature_table = new ServiceFeatureTable(lineFeatureUrl, this);
    FeatureLayer* line_feature_layer = new FeatureLayer(line_feature_table, this);
    m_map->operationalLayers()->append(line_feature_layer);
    }

Add a point feature layer

  1. Staying within the setupViewpoint() method, add the following code to create a QUrl instance named pointFeatureUrl using the ArcGIS feature server as the feature data source, in this case, Trailheads. Then create a ServiceFeatureTable named point_feature_table from that QUrl.

    Display-a-map.cpp
    void Display_a_map::setupViewpoint()
    {
    const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
    const Viewpoint viewpoint(center, 100000.0);
    m_mapView->setViewpointAsync(viewpoint);
    const QUrl polygonFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
    ServiceFeatureTable* polygon_feature_table = new ServiceFeatureTable(polygonFeatureUrl, this);
    FeatureLayer* polygon_feature_layer = new FeatureLayer(polygon_feature_table, this);
    m_map->operationalLayers()->append(polygon_feature_layer);
    const QUrl lineFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trails/FeatureServer/0");
    ServiceFeatureTable* line_feature_table = new ServiceFeatureTable(lineFeatureUrl, this);
    FeatureLayer* line_feature_layer = new FeatureLayer(line_feature_table, this);
    m_map->operationalLayers()->append(line_feature_layer);
    const QUrl pointFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0");
    ServiceFeatureTable* point_feature_table= new ServiceFeatureTable(pointFeatureUrl, this);
    }
  2. Continuing within the setupViewpoint() method, add the following two lines of code to create a FeatureLayer, passing in point_feature_table as the argument. Then append your FeatureLayer to the Map instance named m_map.

    Display-a-map.cpp
    void Display_a_map::setupViewpoint()
    {
    const Point center(-118.80543, 34.02700, SpatialReference::wgs84());
    const Viewpoint viewpoint(center, 100000.0);
    m_mapView->setViewpointAsync(viewpoint);
    const QUrl polygonFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0");
    ServiceFeatureTable* polygon_feature_table = new ServiceFeatureTable(polygonFeatureUrl, this);
    FeatureLayer* polygon_feature_layer = new FeatureLayer(polygon_feature_table, this);
    m_map->operationalLayers()->append(polygon_feature_layer);
    const QUrl lineFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trails/FeatureServer/0");
    ServiceFeatureTable* line_feature_table = new ServiceFeatureTable(lineFeatureUrl, this);
    FeatureLayer* line_feature_layer = new FeatureLayer(line_feature_table, this);
    m_map->operationalLayers()->append(line_feature_layer);
    const QUrl pointFeatureUrl("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0");
    ServiceFeatureTable* point_feature_table= new ServiceFeatureTable(pointFeatureUrl, this);
    FeatureLayer* point_feature_layer = new FeatureLayer(point_feature_table, this);
    m_map->operationalLayers()->append(point_feature_layer);
    }

Set developer credentials

For the final steps of this tutorial, click the tab below that corresponds to the authentication type (API key authentication or User authentication) that you chose when you completed the Display a map tutorial.

Be sure to also provide the same authentication (API key or user authentication Client ID/Redirect URL) that you used for the Display a map tutorial.

Set the API Key

  1. In the project Sources folder of Qt Creator, open the main.cpp file.

  2. Modify the code to set the accessToken using your API key access token (highlighted in yellow).

    main.cpp
    // The following methods grant an access token:
    // 1. User authentication: Grants a temporary access token associated with a user's ArcGIS account.
    // To generate a token, a user logs in to the app with an ArcGIS account that is part of an
    // organization in ArcGIS Online or ArcGIS Enterprise.
    // 2. API key authentication: Get a long-lived access token that gives your application access to
    // ArcGIS location services. Go to the tutorial at https://links.esri.com/create-an-api-key.
    // Copy the API Key access token.
    const QString accessToken = QString("");
    if (accessToken.isEmpty())
    {
    qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" <<
    "you to authenticate with an ArcGIS account or set the API Key property.";
    }
    else
    {
    ArcGISRuntimeEnvironment::setApiKey(accessToken);
    }
  3. Save the main.cpp file.

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

Press Ctrl + R to run the app.

The map view should display all three feature layers in the map. Double-click, drag, and scroll the mouse wheel over the map view to explore the map.

Alternatively, you can download the tutorial solution, as follows.

Option 2: Download the solution

  1. Click the Download solution link under Solution and unzip the file to a location on your machine.

  2. Open the .pro project file in Qt Creator.

Since the downloaded solution does not contain authentication credentials, you must set up authentication to create the developer credentials and add them to the project.

For the final steps of this tutorial, click the tab below that corresponds to the authentication type (API key authentication or User authentication) that you chose when you completed the Display a map tutorial.

Be sure to also provide the same authentication (API key or user authentication Client ID/Redirect URL) that you used for the Display a map tutorial.

Set developer credentials in the solution

Set the API Key

  1. In the project Sources folder of Qt Creator, open the main.cpp file.

  2. Modify the code to set the accessToken using your API key access token (highlighted in yellow).

    main.cpp
    // The following methods grant an access token:
    // 1. User authentication: Grants a temporary access token associated with a user's ArcGIS account.
    // To generate a token, a user logs in to the app with an ArcGIS account that is part of an
    // organization in ArcGIS Online or ArcGIS Enterprise.
    // 2. API key authentication: Get a long-lived access token that gives your application access to
    // ArcGIS location services. Go to the tutorial at https://links.esri.com/create-an-api-key.
    // Copy the API Key access token.
    const QString accessToken = QString("");
    if (accessToken.isEmpty())
    {
    qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" <<
    "you to authenticate with an ArcGIS account or set the API Key property.";
    }
    else
    {
    ArcGISRuntimeEnvironment::setApiKey(accessToken);
    }
  3. Save main.cpp file.

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

Run the solution

Press Ctrl + R to run the app.

The map view should display all three feature layers in the map. Double-click, drag, and scroll the mouse wheel over the map view to explore the map.

What’s next?

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