You will learn: how to build an app that displays feature layers in a 3D scene.
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 tutorial you will create a new scene with an imagery basemap, add a feature layer to it, and display the scene in your app.
Start Visual Studio.
Choose File > New > Project and select the Windows > Classic Desktop > ArcGIS Runtime Application (WPF) template.
Open MainWindow.xaml in XAML view.
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}}" />
Open the MapViewModel.cs code file in your project.
Add a Scene
property to the MapViewModel
class.
private Scene _scene;
public Scene Scene
{
get { return _scene; }
set { _scene = value; OnPropertyChanged(); }
}
Add a function to the MapViewModel
class that will create a new Scene
.
private async void CreateNewScene()
{
}
Add code to create a new Scene
with an imagery basemap.
Scene newScene = new Scene(Basemap.CreateImageryWithLabels());
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"));
Load the layer asynchronously and await its completion.
await trailHeadsLayer.LoadAsync();
Add the layer to the map's collection of operational layers.
newScene.OperationalLayers.Add(trailHeadsLayer);
Set the initial display area (Viewpoint
) of the map to the extent of features in the trailheads layer.
newScene.InitialViewpoint = new Viewpoint(trailHeadsLayer.FullExtent);
Set the MapViewModel.Scene property with your new scene.
Scene = newScene;
Call your CreateNewScene function from the MapViewModel constructor.
public MapViewModel()
{
CreateNewScene();
}
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.
Checkout and compare with our completed solution project.
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());
Visit ArcGIS Online and find additional interesting park datasets to load into the app. Here are a couple suggestions:
https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0
https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0
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.