Feature Layer From Service

Download Samples Repository

Description

This sample demonstrates the Feature Layer. Feature layers allow you to easily plot layers from a feature service on a map. As the sample XAML shows, this simply requires declaring a FeatureLayer element in the Map's layers collection and specifying the URL of the its ServiceFeatureTable attribute to the feature service layer.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.FeatureLayerFromService"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
		<esri:MapView x:Name="MyMapView" WrapAround="True" >
            <esri:Map>
                <esri:ArcGISTiledMapServiceLayer
                    ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
               
                <esri:FeatureLayer ID="featureLayer2">
                    <esri:FeatureLayer.FeatureTable>
                        <esri:ServiceFeatureTable
                            ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/2" />
                    </esri:FeatureLayer.FeatureTable>
                </esri:FeatureLayer>
                <esri:FeatureLayer ID="featureLayer1">
                    <esri:FeatureLayer.FeatureTable>
                        <esri:ServiceFeatureTable
                            ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/1" />
                    </esri:FeatureLayer.FeatureTable>
                </esri:FeatureLayer>
                <esri:FeatureLayer ID="featureLayer0">
                    <esri:FeatureLayer.FeatureTable>
                        <esri:ServiceFeatureTable
                            ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0" />
                    </esri:FeatureLayer.FeatureTable>
                </esri:FeatureLayer>
            </esri:Map>
        </esri:MapView>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Layers;
using System;
using System.Diagnostics;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
	/// <summary>
	/// This sample demonstrates the Feature Layer. Feature layers allow you to easily plot layers from a feature service on a map. As the sample XAML shows, this simply requires declaring a FeatureLayer element in the Map's layers collection and specifying the URL of the its ServiceFeatureTable attribute to the feature service layer.
	/// </summary>
	/// <title>Feature Layer From Service</title>
	/// <category>Layers</category>
	/// <subcategory>Feature Layers</subcategory>
	public partial class FeatureLayerFromService : UserControl
	{
		public FeatureLayerFromService()
		{
			InitializeComponent();

			// Note: code to create feature layer from a feature service
			//CreateFeatureLayer();
		}

		private async void CreateFeatureLayer()
		{
			try
			{
				var gdbFeatureServiceTable = await ServiceFeatureTable.OpenAsync(
					new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/2"));

				MyMapView.Map.Layers.Add(new FeatureLayer(gdbFeatureServiceTable) { ID = "featureLayer" });
			}
			catch (Exception ex)
			{
				Debug.WriteLine("Cannot create FeatureLayer: {0}", ex.ToString());
			}
		}
	}
}
Feedback on this topic?