Add a map to your app

To enhance your development experience, custom project templates are added to the Qt Creator integrated development environment (IDE). A project template includes all the files and property settings necessary to begin an ArcGIS Runtime application project. You can create new applications using one of these project templates and extend these applications with your own business logic.

The ArcGIS Runtime SDK for Qt includes the following project templates:

  • ArcGIS Runtime 10.2.6 Qt Quick Application
  • ArcGIS Runtime 10.2.6 Qt Widgets Application

ArcGIS Runtime has supported Qt Widgets applications written in C++ since its first release. ArcGIS Runtime 10.2.5 introduced support for developing Qt Quick applications using the QML language.

Get started with the Qt Quick Application template

This type of project is programmed primarily with the Qt QML language. Here are the steps to get started.

  • In Qt Creator, click File > New File or Project. The New Project dialog box appears with the list of installed project templates.
  • In the Projects list, browse to ArcGIS and you will see the ArcGIS Runtime 10.2.6 Qt Quick Application template. Highlight the template and click Choose.

  • In the Introduction and Project Location dialog, name the project MyFirstQmlApp, and choose a location to create the new project. For example, if you choose C:\QtProjects your project will be stored in C:\QtProjects\MyFirstQmlApp.

  • In the Kit Selection dialog, select the Qt kit(s) to use to build your project.

  • In the Application Parameters dialog, enter a title and short description of your application. You do not need to enter a client ID yet. You can license your app to obtain a client ID and add it to your app later. If you will deploy your app to Android, be sure to specify an android package name.

  • In the Product Management Summary dialog, review the summary.

  • In Qt Creator, enter Project Mode and select the kit you want to use for your application. For details about configuring projects with kits, see the Qt Creator Documentation.

  • In Qt Creator, enter Edit Mode.

  • Run qmake, and then build and run your application.

Note:

If you are using Red Hat Linux 6 and the Esri-provided build of the Qt SDK, you must copy two folders from the Qt SDK installation folder to the folder containing the executable before running your app for the first time from Qt Creator. The folders are the plugins/platform folder and the qml folder. See the topic Install and set up on Linux for details about setting up your development environment on Red Hat Linux.

Work with local data in your Qt Quick Application

To customize the Qt Quick application to use local data rather than data from an online service, edit the code provided. Local tiled basemap layers are often used as a way to help users orient themselves or navigate the map. Typically any operational layers are placed on top of basemap layers.

  • To use the local tiled basemap layer provided with the SDK samples, replace the existing ArcGISTiledMapServiceLayer component with an ArcGISLocalTiledLayer component. Instead of defining the url property as you would with an online tiled map service, define the path property of the local file. You can use a relative or absolute path to the data. The following example uses a relative reference:
    ArcGISLocalTiledLayer { 
            path: ArcGISRuntime.installDirectory + "/sdk/samples/data/tpks/Topographic.tpk"
        }
  • Operational data can be added to the map using a feature layer that references data in a geodatabase stored locally. To use a sample geodatabase file provided with the SDK samples, you will need to copy the geodatabase to a read/write location on your computer. In the following example, the file DamageInspection6.geodatabase has been copied to C:\Temp.
  • Create a Geodatabase component outside of your existing Map component (the Geodatabase is a sibling to the Map):
    Geodatabase {
             id: gdb
             path: "C:\\Temp\\DamageInspection6.geodatabase"
        }
  • Add a FeatureLayer inside your Map component (after the ArcGISLocalTiledLayer) that refers to this geodatabase:
    FeatureLayer {
            id: featureLayer
            featureTable: GeodatabaseFeatureTable {
                geodatabase: gdb.valid ? gdb : null
                featureServiceLayerId: 0
            }
        }

Inside your ApplicationWindow component, the full code that has been changed or added should look like this:

Geodatabase {
        id: gdb
        path: "C:\\Temp\\DamageInspection6.geodatabase"
    }

    Map {
        anchors.fill: parent
        focus: true

        ArcGISLocalTiledLayer {
            path: ArcGISRuntime.installDirectory + "/sdk/samples/data/tpks/Topographic.tpk"
        }

        FeatureLayer {
            id: featureLayer
            featureTable: GeodatabaseFeatureTable {
              geodatabase: gdb.valid ? gdb : null
              featureServiceLayerId: 0
            }
        }
    }