Learn how to use an ArcGIS portal item to access and display a feature layer in a map.
You can host a variety of geographic data and other resources using ArcGIS Online. These portal items can also define how the data is presented. A web map or web scene, for example, not only defines the layers for a map or scene, but also how layers are symbolized, the minimum and/or maximum scales at which they display, and several other properties. Likewise, a hosted feature layer contains the data for the layer and also defines the symbols and other display properties for how it is presented. When you add a map, scene, or layer from a portal item to your app, everything that has been saved with the item is applied in your app. Adding portal items to your app rather than creating them programmatically saves you from writing a lot of code, and can provide consistency across apps that use the same data.
In this tutorial, you will add a hosted feature layer to display trailheads in the Santa Monica Mountains of Southern California. The hosted layer defines the trailhead locations (points) as well as the symbols used to display them.
Prerequisites
The following are required for this tutorial:
An ArcGIS account to access API keys. If you don't have an account, sign up for free.
To start this tutorial, complete the Display a map tutorial or download
and unzip the solution.
Open the display_a_map project in Qt Creator.
If you downloaded the Display a map solution, set your API key.
An API Key enables access to services, web maps, and web scenes hosted in ArcGIS Online.
Go to your developer dashboard to get your API key.
For these tutorials, use your default API key. It is scoped to include all of the services demonstrated in the tutorials.
In the Projects window, in the Sources folder, open the main.cpp file.
Modify the code to set the API key. Paste the API key, acquired from your dashboard, between the quotes. Then save and close the file.
You will connect to ArcGIS Online and access a hosted item (trailheads layer) using its item ID. You can then create a FeatureLayer to display the PortalItem in the map.
Create a Portal instance using the default constructor.
Create a FeatureLayer, using the PortalItem and referencing a serviceLayerId of 0 (zero). Then append this layer to the map's data layers (operational layers). Save the file.
Your app should display a map with the trailheads centered on the Santa Monica Mountains. Double-click, drag, and scroll the mouse wheel over the map view to explore the map.