Skip To Content ArcGIS for Developers Sign In Dashboard

Overview

You will learn: how to display a web scene stored in ArcGIS Online with your ArcGIS Runtime app.

A web scene is a JSON structure that contains the settings required to display a 3D map. ArcGIS and custom applications can load web scenes and automatically configure the map extent, camera, basemap, layers and styles, labels and more. Web scenes can be created interactively with the Scene Viewer and ArcGIS Pro. Web scenes are stored in ArcGIS Online or ArcGIS Enterprise as an item with a unique ID.

In this tutorial, you will build an app that loads and displays a web scene.

Before you begin

Make sure you have installed the latest version of Android Studio.

Reuse the starter project

If you have completed the Create a starter app tutorial, then copy the project into a new empty folder. Otherwise, download and unzip the project solution. Open, run, and verify the map displays in the device simulator.

Steps

Preview the web scene

  1. Go to the LA Trails and Parks Scene to view the scene in the Scene Viewer. Make note of the ID at the end of the url.

Modify the project to display a scene (3D) instead of a map (2D)

  1. Open the layout file app > res > layout > activity_main.xml in Text view. Change the MapView element to SceneView.

    <com.esri.arcgisruntime.mapping.view.SceneView
      android:id="@+id/sceneView"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
    </com.esri.arcgisruntime.mapping.view.SceneView>
    
  2. Open the file app > java > {your.package.name} > MainActivity.java and change the MapView private member variable type to SceneView and rename it to mSceneView. Change all occurrences of mMapView to mSceneView.

    public class MainActivity extends AppCompatActivity {
    
        // *** CHANGE ***
        private MapView mMapView;
        // *** CHANGE TO ***
        private SceneView mSceneView;
    

    Be sure to update the onCreate, onPause, onResume, and onDestroy methods.

  3. Completely remove the setupMap method. Create a new method named setupScene.

     private void setupScene() {
         if (mSceneView != null) {
         }
     }
    

Access a web scene from ArcGIS Online

  1. Create a Portal to reference ArcGIS Online over HTTPS. Create a PortalItem to reference the web scene by item ID. This is the unique ID for the LA Parks and Trails Scene portal item (web scene). Create a new Scene with the portalItem and assign the scene to the SceneView.

         if (mSceneView != null) {
             // *** ADD ***
             String itemID = "579f97b2f3b94d4a8e48a5f140a6639b";
             Portal portal = new Portal("https://www.arcgis.com");
             PortalItem portalItem = new PortalItem(portal, itemID);
             ArcGISScene scene = new ArcGISScene(portalItem);
             mSceneView.setScene(scene);
    
  2. Update onCreate to locate your SceneView and map it to the new mSceneView variable. Update the view ID to sceneView. Also change the setupMap method call to the new setupScene method.

     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         mSceneView = findViewById(R.id.sceneView);
         setupScene();
     }
    
  3. Run your app to test your code. When the app opens, you should see trail heads and recreation area polygons in the Santa Monica Mountains displayed in a 3D scene with elevation.

Congratulations, you're done!

Compare your solution with our completed solution project.

Challenge

Load other web scenes

Use the search tools in ArcGIS Online to locate other web scenes. Replace the web scene ID in your code to load them in your app. Better yet, complete the Create a web scene tutorial and then display your own web scene!

Change the displayed web scene at run time

Add a control that allows the user to select from a list of available web scenes when the app is running. Display the selected web scene in your app.