Skip To Content ArcGIS for Developers Sign In Dashboard

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 tutorial, 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 the development environment for your operating system.

Steps

Open the starter app project

  1. If you have already completed the Create a starter app tutorial, start Qt Creator and open your starter app project. Otherwise, download and unzip the starter app project solution, and then open it in Qt Creator.

Add a layer to the map

  1. Open the main.qml code file in your project (Resources > qml > qml.qrc > /qml > main.qml). You will update the ApplicationWindow QML component to display a feature layer. 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 feature service you discovered:

    Map {
        BasemapTopographicVector {}
    
        // Add a FeatureLayer component to your starter app
        FeatureLayer {
            ServiceFeatureTable {
                url: featureServiceURL
            }
        }
    
        ViewpointCenter {
            center: Point {
                x: -118.80543                                        // Longitude
                y: 34.02700                                          // Latitude
                spatialReference: SpatialReference { wkid: 4326 }    // WGS84
            }
            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 tutorial 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 symbols

Return to the data tutorial where you created the trailheads layer and change the symbol used for trailhead locations. Change the URL of the fearure layer to your new feature layer and run your app to see the layer with the new symbols.

Change basemap

Change the basemap of your map by examining this basemap code sample. Customize your solution with the basemap you like best.