Learn how to create and display a scene with a basemap layer and an elevation layer. Set properties of the scene's camera to control the 3D perspective.
Like a map, a scene contains layers of geographic data. It contains a basemap layer and, optionally, one or more data layers. To provide a realistic view of the terrain, you can also add elevation layers to define the height of the surface across the scene. The 3D perspective of the scene is controlled by the scene's camera, which defines the position of the scene observer in 3D space.
In this tutorial, you create and display a scene using the imagery basemap layer. The surface of the scene is defined with an elevation layer and the camera is positioned to display an area of the Santa Monica Mountains in the scene view.
The scene and code will be used as the starting point for other 3D tutorials.
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.
- Your system meets the system requirements.
- The ArcGIS Maps SDK for Qt, version 200.4.0 or later is installed.
- The Qt 6.5.1 software development framework is installed.
Create a new ArcGIS Maps Qt Creator Project
Use Qt Creator to create an app that displays a Scene
centered on the Santa Monica Mountains in Southern California.
-
Start Qt Creator.
-
Click File > New File or Project. In the left frame, under Projects, select ArcGIS.
-
Select the ArcGIS Maps 200.4.0 Qt Quick C++ app project template, or a later version, and click Choose.
You may see several selections for the ArcGIS project type. Be sure to select ArcGIS Maps 200.4.0 Qt Quick C++ app (or a later version).
-
At the Project Location dialog, name your project Display_a_scene. Click Next.
-
At the Define Build System dialog, select qmake for your build system. Click Next.
-
At the Define Project Details dialog, enter a description for this app (or leave it as is). Click 3D project. At the ArcGIS Online Basemap dropdown menu, select Imagery. Leave the rest of this dialog unchanged and click Next.
-
At the Kit Selection dialog, check the kit(s) you previously set up when you installed Qt. You should select a Desktop kit to perform all steps in this tutorial. Click Next.
The Add as a subproject to root project option is only available if you have already created a root project. Ignore this option for this tutorial.
-
Verify your selections and click Finish.
Get an API key
An API key is required to enable access to services, web maps, and web scenes hosted in ArcGIS Online.
If you haven't already, 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.
Display a scene
-
In the Projects window, open the Sources folder. Open the main.cpp file. Paste the API key (that you retrieved from your dashboard) between the quotes on the line indicated. Then save and close the file.
main.cppUse dark colors for code blocks Add line. // 2. API key authentication: Get a permanent key that gives your application access to Esri // location services. Create a new API key or access existing API keys from // your ArcGIS for Developers dashboard (https://links.esri.com/arcgis-api-keys). const QString apiKey = QString("");
-
In the Projects window, open the Headers folder. Double-click the file Display_a_scene.h to open it.
-
Add the declaration
void setup
underScene(); private:
. Then save and close the file.Display_a_scene.hUse dark colors for code blocks Add line. private: Esri::ArcGISRuntime::SceneQuickView* sceneView() const; void setSceneView(Esri::ArcGISRuntime::SceneQuickView* sceneView); Esri::ArcGISRuntime::Scene* m_scene = nullptr; Esri::ArcGISRuntime::SceneQuickView* m_sceneView = nullptr; void setupScene();
-
In the Projects window, open the Sources folder. Open the Display_a_scene.cpp file. This app will use a Camera object to display the scene. Add the following include statement.
Display_a_scene.cppUse dark colors for code blocks Add line. #include "Display_a_scene.h" #include "ArcGISTiledElevationSource.h" #include "Camera.h"
-
Add this line to call to the new method,
setup
, that you will create.Scene Display_a_scene.cppUse dark colors for code blocks Add line. Display_a_scene::Display_a_scene(QObject* parent /* = nullptr */): QObject(parent), m_scene(new Scene(BasemapStyle::ArcGISImagery, this)) { // create a new elevation source from Terrain3D rest service ArcGISTiledElevationSource* elevationSource = new ArcGISTiledElevationSource( QUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"), this); // add the elevation source to the scene to display elevation m_scene->baseSurface()->elevationSources()->append(elevationSource); setupScene(); }
-
Create the new method named
setup
at the end of this file, after the closing brace ofScene set
.Scene View() Display_a_scene.cppUse dark colors for code blocks Add line. Add line. Add line. Add line. // Set the view (created in QML) void Display_a_scene::setSceneView(SceneQuickView* sceneView) { if (!sceneView || sceneView == m_sceneView) { return; } m_sceneView = sceneView; m_sceneView->setArcGISScene(m_scene); emit sceneViewChanged(); } void Display_a_scene::setupScene() { }
-
Create an
ElevationSource
instance to define the base surface for the scene.An elevation source can define a surface with 3D terrain in a scene. Without an elevation source, the default globe surface is used to display the scene.
Display_a_scene.cppUse dark colors for code blocks Add line. void Display_a_scene::setupScene() { ArcGISTiledElevationSource* elevationSource = new ArcGISTiledElevationSource(QUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"), this);
-
Create a
Surface
instance and append theelevation
to it.Source Display_a_scene.cppUse dark colors for code blocks Add line. Add line. ArcGISTiledElevationSource* elevationSource = new ArcGISTiledElevationSource(QUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"), this); Surface* elevationSurface = new Surface(this); elevationSurface->elevationSources()->append(elevationSource);
-
Set the
Elevation
value (to improve elevation visibility), and then set theExaggeration elevation
forSurface m_
.scene Display_a_scene.cppUse dark colors for code blocks Add line. Add line. Surface* elevationSurface = new Surface(this); elevationSurface->elevationSources()->append(elevationSource); elevationSurface->setElevationExaggeration(2.5); m_scene->setBaseSurface(elevationSurface);
-
Inside of the
set
method, create aScene View() Camera
with the given parameters.The position from which you view the scene from is defined by a
Camera
. The following properties of the camera are used to define an observation point in the scene:- latitude: The measurement of distance north or south of the Equator
- longitude: The measurement east or west of the prime meridian
- altitude: The distance above sea level
- heading: Azimuth of the camera's direction
- pitch: Up and down angle
- roll: Side-to-side angle
Display_a_scene.cppUse dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. // Set the view (created in QML) void Display_a_scene::setSceneView(SceneQuickView* sceneView) { if (!sceneView || sceneView == m_sceneView) { return; } m_sceneView = sceneView; m_sceneView->setArcGISScene(m_scene); constexpr double latitude = 33.909; constexpr double longitude = -118.805; constexpr double altitude = 5330.0; constexpr double heading = 355.0; constexpr double pitch = 72.0; constexpr double roll = 0.0; const Camera sceneCamera(latitude, longitude, altitude, heading, pitch, roll); m_sceneView->setViewpointCameraAndWait(sceneCamera);
-
Press Ctrl + R to run the app.
You should see a scene with the topographic basemap layer centered on the Santa Monica Mountains in California. Double-click, drag, and scroll the mouse wheel over the scene view to explore the scene.
What's next?
Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: