Display a web scene

Learn how to create and display a scene from a web scene stored in ArcGIS.

display a web scene

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 features layers for the Santa Monica Mountains in California.

Prerequisites

The following are required for this tutorial:

  1. An ArcGIS account to access API keys. If you don't have an account, sign up for free.
  2. Your system meets the system requirements.
  3. The ArcGIS Runtime API for Qt is installed.

Steps

Open the project in Qt Creator

  1. To start this tutorial, complete the Display a scene tutorial or download and unzip the solution.

  2. Open the display_a_scene project in Qt Creator.

  3. 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.

    1. 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.

    2. In the Projects window, in the Sources folder, open the main.cpp file.

    3. Modify the code to set the API key. Paste the API key, acquired from your dashboard, between the quotes.

      main.cpp
      48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 49 50 51 52 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53
      Add line.Add line.Add line.Add line.Add line.
      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
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      //   Copyright 2020 Esri
      //   Licensed under the Apache License, Version 2.0 (the "License");
      //   you may not use this file except in compliance with the License.
      //   You may obtain a copy of the License at
      //
      //   https://www.apache.org/licenses/LICENSE-2.0
      //
      //   Unless required by applicable law or agreed to in writing, software
      //   distributed under the License is distributed on an "AS IS" BASIS,
      //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      //   See the License for the specific language governing permissions and
      //   limitations under the License.
      
      #include "Display_a_scene.h"
      
      #include "ArcGISRuntimeEnvironment.h"
      #include "SceneQuickView.h"
      
      #include <QDir>
      #include <QGuiApplication>
      #include <QSurfaceFormat>
      #include <QQmlApplicationEngine>
      
      //------------------------------------------------------------------------------
      
      using namespace Esri::ArcGISRuntime;
      
      int main(int argc, char *argv[])
      {
      #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
        // Linux requires 3.2 OpenGL Context
        // in order to instance 3D symbols
        QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
        fmt.setVersion(3, 2);
        QSurfaceFormat::setDefaultFormat(fmt);
      #endif
      
        QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
      
      
        // Use of Esri location services, including basemaps and geocoding, requires
        // either an ArcGIS identity or an API key. For more information see
        // https://links.esri.com/arcgis-runtime-security-auth.
      
        // 1. ArcGIS identity: An ArcGIS named user account that is a member of an
        // organization in ArcGIS Online or ArcGIS Enterprise.
      
        // 2. API key: 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 = QStringLiteral("");
      
        if (apiKey.isEmpty())
        {
            qWarning() << "Use of Esri location services, including basemaps, requires "
                          "you to authenticate with an ArcGIS identity or set the API Key property.";
        }
        else
        {
            ArcGISRuntimeEnvironment::setApiKey(apiKey);
        }
      
        // Production deployment of applications built with ArcGIS Runtime requires you to
        // license ArcGIS Runtime functionality. For more information see
        // https://links.esri.com/arcgis-runtime-license-and-deploy.
      
        //ArcGISRuntimeEnvironment::setLicense("Place license string in here");
      
        // Register the scene view for QML
        qmlRegisterType<SceneQuickView>("Esri.Display_a_scene", 1, 0, "SceneView");
      
        // Register the Display_a_scene (QQuickItem) for QML
        qmlRegisterType<Display_a_scene>("Esri.Display_a_scene", 1, 0, "Display_a_scene");
      
        // Initialize application view
        QQmlApplicationEngine engine;
      
        // Add the import Path
        engine.addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml"));
      
        // Set the source
        engine.load(QUrl("qrc:/qml/main.qml"));
      
        return app.exec();
      }
      
      //------------------------------------------------------------------------------

Get the web scene item ID

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.

  1. 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.
  2. Make a note of the item ID at the end of the browser's URL.

    The item ID should be 579f97b2f3b94d4a8e48a5f140a6639b

Display a web scene

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.

  1. In Projects, double-click Sources > Display_a_scene.cpp to open the file.

  2. Remove the following include statement because the Basemap class is not needed.

    Display_a_scene.cpp
    15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 17 18 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19
    Remove line
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    //   Copyright 2020 Esri
    //   Licensed under the Apache License, Version 2.0 (the "License");
    //   you may not use this file except in compliance with the License.
    //   You may obtain a copy of the License at
    //
    //   https://www.apache.org/licenses/LICENSE-2.0
    //
    //   Unless required by applicable law or agreed to in writing, software
    //   distributed under the License is distributed on an "AS IS" BASIS,
    //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    //   See the License for the specific language governing permissions and
    //   limitations under the License.
    
    #include "Display_a_scene.h"
    
    #include "ArcGISRuntimeEnvironment.h"
    #include "ArcGISTiledElevationSource.h"
    
    #include "Basemap.h"
    
    #include "Scene.h"
    #include "SceneQuickView.h"
    
    #include <QUrl>
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_scene::Display_a_scene(QObject* parent /* = nullptr */):
      QObject(parent),
      m_scene(new Scene(Basemap::imagery(this), this))
    {
    
      setupScene();
    
    }
    
    Display_a_scene::~Display_a_scene()
    {
    }
    
    SceneQuickView* Display_a_scene::sceneView() const
    {
      return m_sceneView;
    }
    
    // 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);
    
      emit sceneViewChanged();
    }
    
    void Display_a_scene::setupScene()
    {
    
      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);
    
      elevationSurface->setElevationExaggeration(2.5);
      m_scene->setBaseSurface(elevationSurface);
    
    }
    
  3. Delete the following lines to remove the sceneCamera object and all of its arguments.

    Display_a_scene.cpp
    45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
    Remove lineRemove lineRemove lineRemove lineRemove lineRemove lineRemove lineRemove line
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    //   Copyright 2020 Esri
    //   Licensed under the Apache License, Version 2.0 (the "License");
    //   you may not use this file except in compliance with the License.
    //   You may obtain a copy of the License at
    //
    //   https://www.apache.org/licenses/LICENSE-2.0
    //
    //   Unless required by applicable law or agreed to in writing, software
    //   distributed under the License is distributed on an "AS IS" BASIS,
    //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    //   See the License for the specific language governing permissions and
    //   limitations under the License.
    
    #include "Display_a_scene.h"
    
    #include "ArcGISRuntimeEnvironment.h"
    #include "ArcGISTiledElevationSource.h"
    
    #include "Basemap.h"
    
    #include "Scene.h"
    #include "SceneQuickView.h"
    
    #include <QUrl>
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_scene::Display_a_scene(QObject* parent /* = nullptr */):
      QObject(parent),
      m_scene(new Scene(Basemap::imagery(this), this))
    {
    
      setupScene();
    
    }
    
    Display_a_scene::~Display_a_scene()
    {
    }
    
    SceneQuickView* Display_a_scene::sceneView() const
    {
      return m_sceneView;
    }
    
    // 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);
    
      emit sceneViewChanged();
    }
    
    void Display_a_scene::setupScene()
    {
    
      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);
    
      elevationSurface->setElevationExaggeration(2.5);
      m_scene->setBaseSurface(elevationSurface);
    
    }
    
  4. Remove all of the existing code from the setupScene method.

    Display_a_scene.cpp
    67 67 67 67 67 67 67 67 67 67 67 67 67 67 67 67 67 67 66 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 64 63 62 61 60 59 58 57 56 56 56 56 57 58 59 60 61 62 63 64 65 66 67 68
    Remove lineRemove lineRemove lineRemove lineRemove line
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    //   Copyright 2020 Esri
    //   Licensed under the Apache License, Version 2.0 (the "License");
    //   you may not use this file except in compliance with the License.
    //   You may obtain a copy of the License at
    //
    //   https://www.apache.org/licenses/LICENSE-2.0
    //
    //   Unless required by applicable law or agreed to in writing, software
    //   distributed under the License is distributed on an "AS IS" BASIS,
    //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    //   See the License for the specific language governing permissions and
    //   limitations under the License.
    
    #include "Display_a_scene.h"
    
    #include "ArcGISRuntimeEnvironment.h"
    #include "ArcGISTiledElevationSource.h"
    
    #include "Basemap.h"
    
    #include "Scene.h"
    #include "SceneQuickView.h"
    
    #include <QUrl>
    
    using namespace Esri::ArcGISRuntime;
    
    Display_a_scene::Display_a_scene(QObject* parent /* = nullptr */):
      QObject(parent),
      m_scene(new Scene(Basemap::imagery(this), this))
    {
    
      setupScene();
    
    }
    
    Display_a_scene::~Display_a_scene()
    {
    }
    
    SceneQuickView* Display_a_scene::sceneView() const
    {
      return m_sceneView;
    }
    
    // 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);
    
      emit sceneViewChanged();
    }
    
    void Display_a_scene::setupScene()
    {
    
      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);
    
      elevationSurface->setElevationExaggeration(2.5);
      m_scene->setBaseSurface(elevationSurface);
    
    }
    

    A web scene can define all of the things that are created in this code, such as the basemap, elevation layer, and initial viewpoint. Loading a scene from a web scene usually requires less code, makes it easier to update a scene used by several apps, and can provide a more consistent experience for your user.

  5. Add code to the setupScene method to create the web scene portal URL. Provide the web scene's unique item ID and the URL referencing the ArcGIS Online web scene service.

    Display_a_scene.cpp
    51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 52 53 54 55 56 57 58 59 59 59 58 58
    Add line.Add line.Add line.Add line.
    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
    61
    62
    63
    //   Copyright 2021 Esri
    //   Licensed under the Apache License, Version 2.0 (the "License");
    //   you may not use this file except in compliance with the License.
    //   You may obtain a copy of the License at
    //
    //   https://www.apache.org/licenses/LICENSE-2.0
    //
    //   Unless required by applicable law or agreed to in writing, software
    //   distributed under the License is distributed on an "AS IS" BASIS,
    //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    //   See the License for the specific language governing permissions and
    //   limitations under the License.
    
    #include "Display_a_scene.h"
    
    #include "ArcGISRuntimeEnvironment.h"
    #include "ArcGISTiledElevationSource.h"
    #include "Scene.h"
    #include "SceneQuickView.h"
    
    #include <QUrl>
    
    using namespace Esri::ArcGISRuntime;
    Display_a_scene::Display_a_scene(QObject* parent /* = nullptr */):
        QObject(parent)
    {
        setupScene();
    }
    
    Display_a_scene::~Display_a_scene()
    {
    }
    
    SceneQuickView* Display_a_scene::sceneView() const
    {
        return m_sceneView;
    }
    
    // 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 item_id to reference an item at a web server
        const QString item_id("579f97b2f3b94d4a8e48a5f140a6639b");
        // Create a QUrl from the web scene server URL and the item_id
        const QUrl portal_url(QString("https://arcgis.com/sharing/rest/content/items/" + item_id));
    
        // Create the scene, referencing the QUrl
        m_scene = new Scene(portal_url, this);
    
    }
    
  6. Create the Scene using the web scene's url.

    Display_a_scene.cpp
    51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 52 53 54 55 56 57 58 59 60 61 61 61
    Add line.Add line.
    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
    61
    62
    63
    //   Copyright 2021 Esri
    //   Licensed under the Apache License, Version 2.0 (the "License");
    //   you may not use this file except in compliance with the License.
    //   You may obtain a copy of the License at
    //
    //   https://www.apache.org/licenses/LICENSE-2.0
    //
    //   Unless required by applicable law or agreed to in writing, software
    //   distributed under the License is distributed on an "AS IS" BASIS,
    //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    //   See the License for the specific language governing permissions and
    //   limitations under the License.
    
    #include "Display_a_scene.h"
    
    #include "ArcGISRuntimeEnvironment.h"
    #include "ArcGISTiledElevationSource.h"
    #include "Scene.h"
    #include "SceneQuickView.h"
    
    #include <QUrl>
    
    using namespace Esri::ArcGISRuntime;
    Display_a_scene::Display_a_scene(QObject* parent /* = nullptr */):
        QObject(parent)
    {
        setupScene();
    }
    
    Display_a_scene::~Display_a_scene()
    {
    }
    
    SceneQuickView* Display_a_scene::sceneView() const
    {
        return m_sceneView;
    }
    
    // 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 item_id to reference an item at a web server
        const QString item_id("579f97b2f3b94d4a8e48a5f140a6639b");
        // Create a QUrl from the web scene server URL and the item_id
        const QUrl portal_url(QString("https://arcgis.com/sharing/rest/content/items/" + item_id));
    
        // Create the scene, referencing the QUrl
        m_scene = new Scene(portal_url, this);
    
    }
    
  7. Press <Ctrl+R> to run the app.

Your app should display the scene that you viewed earlier in the Scene Viewer.

What's Next?

Learn how to use additional API features, ArcGIS platform services, and ArcGIS tools in these tutorials:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.