Overview

You will learn: how to add feature layers to a 2D map.

With the ArcGIS Runtime SDK for Qt, it is easy to create a mapping app that displays a basemap and layer that is a hosted feature service. ArcGIS Online hosts a number of tile and vector tile basemaps that you can choose from, including streets, satellite, streets-vector, and streets-navigation-vector. You can also add your own datasets by adding feature layers. These layers are hosted by ArcGIS Online or by other ArcGIS servers. By default, feature layers will draw with pre-set symbols to fill the extent of the map, but you can customize this by setting your own styles with a renderer or using a SQL expression to limit the data retrieved.

In this lab, you will build a simple mapping app with a basemap and a feature layer that represents trailheads near the Santa Monica Mountains. The layer is hosted on ArcGIS Online.

Before you begin

You must have previously installed the ArcGIS Runtime SDK for Qt and set up your development environment. Please review the install and setup instructions if you have not done this.

Steps

Create a new ArcGIS Runtime App Qt Creator Project

  1. Start Qt Creator.

  2. Choose File > New File or Project and select the ArcGIS project template for ArcGIS Runtime Qt Quick app. Give your app a name. For this lab we chose add-layers-to-a-map, but you can choose any name that suits you. Also select the location where your project files should reside on your system. Select Continue.

  3. On the Define Project Details dialog, leave the settings as suggested. Select Continue.

  4. On the Kit Selection dialog, check the kits you previously setup when you installed the SDK. Select Continue.

  5. Verify your selections and select Done.

Add a layer to the map

  1. Open the main.qml code file in your project (Resources > qml > qml.qrc > /qml > main.qml). If you followed the prior steps, it should already be open in the IDE. You will update the ApplicationWindow QML component to display a basemap and a feature layer. First, add a property to define the URL of the feature service. Use the feature service showing all the trail heads in the Santa Monica Mountains. Add this to the ApplicationWindow immediately after the title property.

    property string featureServiceURL: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    
  2. Update the MapView component to use the topographic vector tile basemap and the feature service you discovered:

    Map {
        BasemapTopographicVector {}
        FeatureLayer {
            id: trailHeads
            ServiceFeatureTable {
                url: featureServiceURL
            }
        }
        ViewpointCenter {
            Point {
                x: -118.71511
                y: 34.09042
                SpatialReference { wkid: 4326 }
            }
            targetScale: 300000
        }
     }
    

Congratulations, you're done!

Your map should load and center on the Santa Monica Mountains with a separate layer (feature service) that shows the trailhead symbols represented as orange markers on the map. Compare your map with our completed solution project.

Challenge

Change the feature data

Return to the data lab where you created the trailheads layer and add or remove trailhead locations. Rerun your app and see the layer update without any code changes.

Change symbology

Return to the data lab where you created the trailheads layer and change the symbol used for trailhead locations. Rerun your app and see the layer update without any code changes.

Change basemap

Change the basemap to one of the many offered by the API. Customize your solution with the one you like best.