You will learn: how to build an app that loads and displays a layer from ArcGIS Online.
Applications can access
In this tutorial, you will add layers to the map that have been pre-configured and stored as an item in ArcGIS Online.
You must have previously installed ArcGIS AppStudio.
If you completed the Create a starter app tutorial, start ArcGIS AppStudio and then open your starter app project. Otherwise, complete the tutorial now and open the project.
33fc2fa407ab40f9add12fe38d5801f5
.Run ArcGIS AppStudio. Click your Starter app project in the App Gallery, and then click {;} Edit. This will open your project in Qt Creator.
In the Qt Creator Projects window, double-click MyApp.qml to open it in the editor. In the App
declaration, add the following properties to specify the URL of the portal and the layer item ID.
property real scaleFactor: AppFramework.displayScaleFactor
// *** ADD ***
property string portalUrl: "https://arcgis.com";
property string trailheadsItemID: "33fc2fa407ab40f9add12fe38d5801f5"
In the App
declaration, just below the properties, declare a Portal
type to create an unauthenticated connection to the
property string trailheadsItemID: "33fc2fa407ab40f9add12fe38d5801f5"
// *** ADD ***
Portal {
id: arcgisOnline
url: portalUrl
loginRequired: false
}
After the Portal
declaration, declare a PortalItem
type to load the layer with the Trailheads Styled item ID from the ArcGIS Online portal.
PortalItem {
id: portalItemTrailheads
portal: arcgisOnline
itemId: trailheadsItemID
}
In the code editor, scroll down to the Map
declaration. Add code after the basemap declaration to create a FeatureLayer
from the portal item.
Map {
id:map
BasemapTopographicVector {}
// *** ADD ***
FeatureLayer {
id:trailheadFeatureLayer
item: portalItemTrailheads
serviceLayerId: "0"
}
After the declaration of FeatureLayer
, add a callback to append the feature layer to the operationalLayers
of the map when the layer loads.
FeatureLayer {
id:trailheadFeatureLayer
item: portalItemTrailheads
serviceLayerId: "0"
}
// *** ADD ***
onLoadStatusChanged: {
if (loadStatus === Enums.LoadStatusLoaded) {
map.operationalLayers.append(trailheadFeatureLayer);
}
}
In the lower left Sidebar, click Run or press Control-R/Command-R to run the app.
Your app should display a map with the trailheads centered on the Santa Monica Mountains. Compare your solution with our completed solution project.
Use the same code pattern to load two more layers into the map. Go to the Trails Styled and the Parks and Open Space Styled layers to find the item IDs and add the layers to the map as additional operational layers.
There are multiple ways to load a ServiceFeatureTable
with a URL and create a FeatureLayer
from the service feature table in the Add layers to a map tutorial.
Learn how to create feature layers with your own data in the Create a new dataset tutorial.
If you have not already done so, visit the Discover data tutorial and search for open data you could use to add another layer to your app.