Skip To Content ArcGIS for Developers Sign In Dashboard


You will learn: how to build an app that loads and displays a layer from ArcGIS Online.

The ArcGIS Runtime SDK for .NET allows you to access items (such as layers) stored in ArcGIS Online by their item identifier. Feature layers can store geographic features (points, lines, polygons), edit or update attributes, and synchronize changes. As demonstrated in the tutorial Display a web map, you can load and display an existing web map that was pre-configured with a basemap and layers. Alternatively, you may wish to load one or more layers from ArcGIS Online and create a map with code. You may do this if you have operational or base layers from different sources in your app. You can publish your own feature layer to ArcGIS Online using the Create a new dataset data tutorial.

In this tutorial you will learn how to access a layer stored in ArcGIS Online. You will open the layer using its identifier and display its contents on a map.


Create the Project

  1. Start Visual Studio.

  2. Choose File > New > Project and select the ArcGIS Runtime App template for your chosen platform.

Create the portal

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

  2. Add the following function to the MapViewModel class:

    private async void InitializeMap()
  3. Add code to the initialization function to create the portal:

    ArcGISPortal portal = await ArcGISPortal.CreateAsync();

Load the portal item

  1. Create a variable to store an ArcGIS Online portal item ID. This is the unique ID for the Los Angeles Trailheads portal item (feature layer).

    string portalItemId = "883cedb8c9fe4524b64d47666ed234a7";
  2. Create the portal item from the portal and the item ID:

    PortalItem portalItem = await PortalItem.CreateAsync(portal, portalItemId);

Create the layer from the portal item

  1. Create the layer using the portal item and its layer ID:

    FeatureLayer layer = new FeatureLayer(portalItem, 0);

Add the layer to the map

  1. Ensure the layer is loaded and use it to update the map's InitialViewpoint:

    await layer.LoadAsync();
    Map = new Map(Basemap.CreateTopographic()) { InitialViewpoint = new Viewpoint(layer.FullExtent) };
  2. Update the MapViewModel.Map's OperationalLayers property with the newly created layer:

  3. Update the MapViewModel constructor to call InitializeMap:

    public MapViewModel()
  4. Run your app to test your code. When the app opens, you should see a map with the trailhead layer for Los Angeles.

Congratulations, you're done!

Your map and layer should load and display with the view point centered on the Los Angeles area and points identifying the trailheads.


Use your portal item

Instead of using the portal item we used above, use the one you made in the data tutorial Create a new dataset.

In Step 6 above, replace the value of portalItemId with the ID of your portal item.

Find the portal item URL

There are multiple ways to load a feature layer from ArcGIS Online. One way is to load the feature layer directly from a URL. This challenge is a follow-on to the challenge in Create a new dataset design tutorial.

Navigate to the page in ArcGIS Online for your portal item. In the item page, find the Service URL link and identify the service endpoint. This is the URL the runtime uses to access the data. It should look something like this:

Store the URL in an Uri:

// Hold the URL to the service
Uri uri = new Uri("");

Create the FeatureLayer from the Uri

// Create the layer
FeatureLayer layer = new FeatureLayer(uri);

Add the layer to the map


Discover data

If you have not already done so, visit the Discover data tutorial and search for interesting open data you could add in another layer in your app.