Overview

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

The fastest way to create a fully styled 3D mapping application is to load a web scene. Web scenes are special because the format is interchangeable between a number of applications running on the ArcGIS platform. Web scenes are generally created interactively with the Scene Viewer and saved in ArcGIS Online. Complex scenes can also be created with ArcGIS Pro. When you save a web scene it stores a number of settings such as the basemap, extent, layers and styles, and label configurations. When a web scene is loaded by an application, the settings are used to set up and configure the map, saving you from having to set them up yourself. Web scenes can also be updated independently from your apps, making it handy if you want to update the map and layers but don't want to make changes to the application code itself.

In this lab, you will use the ArcGIS Runtime SDK for Android to build a mapping app that loads and displays a web scene of trails and parks in the Santa Monica Mountains.

Before you begin

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

Reuse the starter project

In a new or empty project folder, make a copy of the Create a starter app or download and unzip the project solution.

  • Open the copied Android project in Android Studio.

  • Run the project and verify the project builds and the map displays in the device simulator.

  • You may be required to sync the project dependencies.

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