Display feature layers

View inWPFWinUIForms
View on GitHub

Display feature layers from various data sources.

Display feature layers

Use case

Feature layers, like all layers, are visual representations of data and are used on a map or scene. In the case of feature layers, the underlying data is held in a feature table or feature service.

Feature services are useful for sharing vector GIS data with clients so that individual features can be queried, displayed, and edited. There are various online and offline methods to load feature services.

How to use the sample

Click the button on the toolbar to add feature layers, from different sources, to the map. Pan and zoom the map to view the feature layers.

How it works

  1. Set the basemap with a BasemapStyle.
  2. Load a feature layer with a URL.
    i. Create a ServiceFeatureTable from a URL.
    ii. Create a FeatureLayer with the feature table.
  3. Load a feature layer with a portal item.
    i. Create a PortalItem with the portal and item ID.
    ii. Create a FeatureLayer with the portal item and layer ID.
  4. Load a feature layer with a geodatabase.
    i. Instantiate and load a Geodatabase using the file name.
    ii. Get the feature table from the geodatabase with the feature table's name.
    iii. Create a FeatureLayer from the feature table.
  5. Load a feature layer with a geopackage.
    i. Instantiate and load a geopackage using its file name.
    ii. Get the first GeoPackageFeatureTable from the geoPackageFeatureTables array.
    iii. Create an FeatureLayer from the feature table.
  6. Load a feature layer with a shapefile.
    i. Create a ShapefileFeatureTable using the shapefile name.
    ii. Create a FeatureLayer from the feature table and load it.
  7. Add the feature layer to the map's OperationalLayers.

Relevant API

  • FeatureLayer
  • Geodatabase
  • GeoPackageFeatureTable
  • PortalItem
  • ServiceFeatureTable
  • ShapefileFeatureTable

About the data

This sample uses the Naperville damage assessment service, Trees of Portland portal item, Los Angeles Trailheads geodatabase, Aurora, Colorado GeoPackage, and Scottish Wildlife Trust Reserves Shapefile.

The Scottish Wildlife Trust shapefile data is provided from Scottish Wildlife Trust under CC-BY licence. Data Copyright Scottish Wildlife Trust (2022).

Tags

feature, geodatabase, geopackage, layers, service, shapefile, table

Sample Code

DisplayFeatureLayers.xamlDisplayFeatureLayers.xamlDisplayFeatureLayers.xaml.cs
Use dark colors for code blocksCopy
                 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<UserControl x:Class="ArcGISRuntime.WinUI.Samples.DisplayFeatureLayers.DisplayFeatureLayers"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="using:Esri.ArcGISRuntime"
             xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <Border MaxWidth="250" Style="{StaticResource BorderStyle}">
            <StackPanel>
                <TextBlock Text="Select a feature layer source" />
                <ComboBox x:Name="FeatureLayerCombo"
                          Width="180"
                          SelectionChanged="FeatureLayerCombo_SelectionChanged" />
            </StackPanel>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.