You will learn: how to build an app that displays feature layers in a 3D scene.
Applications can access and display FeatureLayer
class can use this URL to access the layer's point, line, or polygon features. These features may be drawn on the scene with the SceneQuickView
class. If properties such as the renderer or pop-up have not been pre-defined for the hosted feature layer, the map will use default symbols and pop-ups will not be enabled.
In this tutorial, you will add the Trailheads, Trails, and Parks and open spaces hosted feature layers to the map.
You must have previously installed the ArcGIS Runtime SDK for Qt and set up the development environment for your operating system.
Start Qt Creator.
Choose the ArcGIS Runtime Qt Quick C++ project template.
Give your app a name. For this tutorial we chose add_layers_to_a_3d_scene, but you can choose any name that suits you. Click Next.
On the Define Project Details dialog, click the checkbox 3D project. Leave all the other settings as they are and click Continue.
On the Kit Selection dialog, choose one of the kits you previously setup when you installed the Qt Framework. Click Next.
Verify your selections and click Done.
In Projects, double click on Sources > Add_layers_to_a_3d_scene.cpp and add the following include statements.
#include "SceneQuickView.h"
// *** ADD ***
#include "FeatureLayer.h"
#include "ServiceFeatureTable.h"
Add the following code to the body of the constructor to load a feature layer.
Add_layers_to_a_3d_scene::Add_layers_to_a_3d_scene(QObject* parent /* = nullptr */):
QObject(parent),
m_scene(new Scene(Basemap::topographic(this), 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);
// *** ADD ***
QUrl serviceURL("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
ServiceFeatureTable* f_table = new ServiceFeatureTable(serviceURL, this);
FeatureLayer* f_layer = new FeatureLayer(f_table, this);
At the end of the body of the constructor, append the feature layer to the
FeatureLayer* f_layer = new FeatureLayer(f_table, this);
// *** ADD ***
m_scene->operationalLayers()->append(f_layer);
Add the setSceneView
member function to set the initial position of the Camera
of the scene view.
void Add_layers_to_a_3d_scene::setSceneView(SceneQuickView* sceneView)
{
if (!sceneView || sceneView == m_sceneView)
{
return;
}
m_sceneView = sceneView;
m_sceneView->setArcGISScene(m_scene);
// *** ADD ***
constexpr double latitude = 33.855;
constexpr double longitude = -118.85;
constexpr double altitude = 10010.0;
constexpr double heading = 40.0;
constexpr double pitch = 80.0;
constexpr double roll = 0.0;
Camera camera(latitude, longitude, altitude, heading, pitch, roll);
m_sceneView->setViewpointCameraAndWait(camera);
Run your app to test your code. You should see a 3D perspective of the scene with the trails drawn on the map.
Compare your project with our completed solution project.
Look at the available basemaps at the Basemap
class in the API reference documentation. Modify your code to display a different basemap.
To learn more, check out the working with scenes guide topic.
Visit ArcGIS Online and find additional interesting park datasets to load into the app. Here are a few suggestions:
https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0
https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0
Sometimes you want your layer to show a subset of the data from a service. A definition expression lets you define attribute criteria that restrict the features for a layer. Consult the service info for the Trailheads data source and construct an expression for the layer's definitionExpression
property that will show only those trailheads that do not have parking.