Learn how to create and display a scene from a web scene stored in ArcGIS.
This tutorial shows you how to create and display a scene from a web scene. All web scenes are stored in ArcGIS with a unique item ID. You will access an existing web scene by item ID and display its layers. The web scene contains feature layers for the Santa Monica Mountains in California.
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.
To start this tutorial, complete the Display a scene tutorial or download
and unzip the solution.
Open the display_a_scene project in Qt Creator.
If you downloaded the Display a scene solution, set your API key.
An API Key enables access to services, web maps, and web scenes hosted in ArcGIS Online.
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.
In the Projects window, in the Sources folder, open the main.cpp file.
Modify the code to set the API key. Paste the API key, acquired from your dashboard, between the quotes.
You can use ArcGIS tools to create and view web scenes. Use the Scene Viewer to identify the web scene item ID. This item ID will be used later in the tutorial.
Go to the LA Trails and Parks web scene in the Scene Viewer in ArcGIS Online. This web scene displays trails, trailheads and parks in the Santa Monica Mountains.
Make a note of the item ID at the end of the browser's URL. The item ID should be 579f97b2f3b94d4a8e48a5f140a6639b
Remove unneeded code
A web scene can define all of the content created in this code, such as the basemap, elevation layer, and initial viewpoint. Accordingly, the following code needs to be removed or changed.
In Projects, double-click Sources >Display_a_scene.cpp to open the file.
Remove the unnecessary #include statements for: ArcGISTiledElevationSource.h, Camera.h, ElevationSourceListModel.h, MapTypes.h, and Surface.h. Removing these lines of code will keep you from having compiler warnings.
Loading a scene from a web scene usually requires less code and makes it easier to update a scene used by several apps. Furthermore, web scenes can provide a more consistent experience for your user.
Display a web scene using its portal item URL
You can display a web scene using the web scene's item ID. Create a scene from the web scene portal item, and display it in your app.
Add code to the setupScene method to create the web scene portal URL. Concatenate the web scene's unique item ID and the URL for ArcGIS Online.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
voidDisplay_a_scene::setupScene(){
// Create an item_id to reference an item at a web serverconst QString item_id("579f97b2f3b94d4a8e48a5f140a6639b");
// Create a QUrl from the web scene server URL and the item_idconst QUrl portal_url(QString("https://arcgis.com/sharing/rest/content/items/" + item_id));
// Create the scene, referencing the QUrl m_scene = newScene(portal_url, this);
Expand
Press <Ctrl+R> to run the app.
Your app displays the scene that you viewed earlier in the Scene Viewer.
Steps for Qml
Open the project in Qt Creator
To start this tutorial, complete the Display a scene tutorial or download
and unzip the solution.
Open the display_a_scene project in Qt Creator.
If you downloaded the Display a scene solution, set your API key.
An API Key enables access to services, web maps, and web scenes hosted in ArcGIS Online.
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.
In the Projects window, in the Sources folder, open the main.cpp file.
Modify the code to set the API key. Paste the API key, acquired from your dashboard, between the quotes.
You can use ArcGIS tools to create and view web scenes. Use the Scene Viewer to identify the web scene item ID. This item ID will be used later in the tutorial.
Go to the LA Trails and Parks web scene in the Scene Viewer in ArcGIS Online. This web scene displays trails, trailheads and parks in the Santa Monica Mountains.
Make a note of the item ID at the end of the browser's URL. The item ID should be 579f97b2f3b94d4a8e48a5f140a6639b
Remove unneeded code
A web scene can define all of the content created in this code, such as the basemap style, elevation layer, and initial viewpoint. Accordingly, the following code needs to be removed or changed.
If the main.qml file is not already open, in the Projects window, navigate to Resources > qml\qml.qrc > /qml and open main.qml.
Remove the code that sets the BasemapStyle enum for the Scene. At the same time, remove the Surface created using the ArcGIS image server.
Loading a scene from a web scene usually requires less code and makes it easier to update a scene used by several apps. Furthermore, web scenes can provide a more consistent experience for your user.
Display a web scene using its portal item ID
You can display a web scene using the web scene's item ID. Create a scene from the web scene portal item, and display it in your app.
Create the Scene using a PortalItem and set the itemId to the ID for the LA Trails and Parks web scene. This code creates a Scene from the web scene configuration.