Overview

You will learn: how to add feature layers to a 3D map.

With ArcGIS Runtime SDK for .NET, it's easy to create a mapping app that displays a basemap and one or more layers. ArcGIS Online hosts several basemaps that you can use in your map (2D) or scene (3D). Feature layers allow you to add datasets hosted online (with ArcGIS Online or other ArcGIS servers) or stored locally (in a runtime geodatabase, for example). The data returned and the symbology used can be customized for a feature layer.

In this lab you will create a new scene with an imagery basemap, add a feature layer to it, and display the scene in your app.

Steps

Create a new ArcGIS Runtime App Visual Studio Project

  1. Start Visual Studio.

  2. Choose File > New > Project and select the Windows > Classic Desktop > ArcGIS Runtime Application (WPF) template.

Modify the project to display a Scene (3D) instead of a Map (2D)

  1. Open MainWindow.xaml in XAML view.

  2. Replace the existing line of XAML that defines a MapView control with the XAML below for a SceneView.

    <esri:SceneView Scene="{Binding Scene, Source={StaticResource MapViewModel}}" />
    

Create a new scene with an imagery basemap

  1. Open the MapViewModel.cs code file in your project.

  2. Add a Scene property to the MapViewModel class.

    private Scene _scene;
    public Scene Scene
    {
        get { return _scene; }
        set { _scene = value; OnPropertyChanged(); }
    }
    
  3. Add a function to the MapViewModel class that will create a new Scene.

    private async void CreateNewScene()
    {
    
    }
    
  4. Add code to create a new Scene with an imagery basemap.

    Scene newScene = new Scene(Basemap.CreateImageryWithLabels());
    

Create a new feature layer

  1. Add code that creates a new FeatureLayer. For the layer data source, provide a URI to the Trailheads layer in the Los Angeles Trails map service.

    FeatureLayer trailHeadsLayer = new FeatureLayer(new Uri("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"));
    
  2. Load the layer asynchronously and await its completion.

    await trailHeadsLayer.LoadAsync();
    
  3. Add the layer to the map's collection of operational layers.

    newScene.OperationalLayers.Add(trailHeadsLayer);
    
  4. Set the initial display area (Viewpoint) of the map to the extent of features in the trailheads layer.

    newScene.InitialViewpoint = new Viewpoint(trailHeadsLayer.FullExtent);
    

Display the new scene in your app

  1. Set the MapViewModel.Scene property with your new scene.

    Scene = newScene;
    
  2. Call your CreateNewScene function from the MapViewModel constructor.

    public MapViewModel()
    {
       CreateNewScene();
    }
    
  3. Run your app to test your code. When the app opens, you should see imagery of Los Angeles appear with trailhead points displayed on top. It might look like a 2D map at the initial scale, zoom out until you see the globe.

Congratulations, you're done!

Checkout and compare with our completed solution project.

Challenge

Explore basemaps

Look at the available static methods on the Basemap class for creating basemaps for your Scene. Modify your code to display a different basemap. For example:

Scene newScene = new Scene(Basemap.CreateNationalGeographic());

Add additional feature layers

Visit ArcGIS Online and find additional interesting park datasets to load into the app. Here are a couple suggestions:

  • Trails (lines): https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0
  • Parks (polygons): https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0

Filter features in the trailheads layer

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 without parking.