Identify

Download Samples Repository

Description

This sample demonstrates performing identify operations. To use the sample, click anywhere in the United States to identify features. The results will be shown in the combo box and list view on the right side of the application. View the data for different results by selecting them from the combo box. In the code-behind, an IdentifyTask is used to perform the identify operation. The tasks IdentifyParameters specify to query the geometry of the map click and to query all the layers in the target map service, which enables returning results from multiple layers.

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

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.IdentifySample"
             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 x:Name="layoutGrid">
        <Grid.Resources>
            <esri:SimpleMarkerSymbol x:Key="MarkerSymbol" Size="12" Color="Red" Style="Circle" />
            <esri:SimpleRenderer x:Key="MarkerRenderer" Symbol="{StaticResource MarkerSymbol}" />
        </Grid.Resources>

        <esri:MapView x:Name="MyMapView" WrapAround="True" MapViewTapped="MyMapView_MapViewTapped">
			<esri:Map InitialViewpoint="-15000000, 2000000, -7000000, 8000000">
				<esri:ArcGISTiledMapServiceLayer 
                    ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
			</esri:Map>
			<esri:MapView.GraphicsOverlays>
				<esri:GraphicsOverlay ID="graphicsOverlay" Renderer="{StaticResource MarkerRenderer}" />
			</esri:MapView.GraphicsOverlays>
		</esri:MapView>

        <Border Background="White" BorderBrush="Black" BorderThickness="1" 
				Margin="30" Padding="20" Width="325"
                HorizontalAlignment="Right" VerticalAlignment="Top">
            <Grid x:Name="resultsGrid">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <TextBlock Text="Click in the United States to identify features" Margin="6" />

                <ComboBox x:Name="titleComboBox" Grid.Row="1" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="{}{0} ({1})">
                                        <Binding Path="Value" />
                                        <Binding Path="LayerName" />
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <ProgressBar Grid.Row="2" x:Name="progress" IsIndeterminate="True" Margin="10" Visibility="Collapsed" />

                <ListView Grid.Row="3" Margin="0,20,0,0" IsSynchronizedWithCurrentItem="True"
                          ItemsSource="{Binding ElementName=titleComboBox, Path=SelectedItem.Feature.Attributes}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=Key}" Width="100"/>
                                <TextBlock Text="{Binding Path=Value}" />
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>
        </Border>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.Tasks.Query;
using System;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
	/// <summary>
	/// This sample demonstrates performing identify operations. To use the sample, click anywhere in the United States to identify features. The results will be shown in the combo box and list view on the right side of the application. View the data for different results by selecting them from the combo box. In the code-behind, an IdentifyTask is used to perform the identify operation. The tasks IdentifyParameters specify to query the geometry of the map click and to query all the layers in the target map service, which enables returning results from multiple layers.
	/// </summary>
	/// <title>Identify</title>
	/// <category>Tasks</category>
	/// <subcategory>Query</subcategory>
	public partial class IdentifySample : UserControl
	{
		/// <summary>Construct Identify sample control</summary>
		public IdentifySample()
		{
			InitializeComponent();
		}

		// Identify features at the click point
		private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
		{
			try
			{
				progress.Visibility = Visibility.Visible;
				resultsGrid.DataContext = null;

				GraphicsOverlay graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
				graphicsOverlay.Graphics.Clear();
				graphicsOverlay.Graphics.Add(new Graphic(e.Location));

				// Get current viewpoints extent from the MapView
				var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
				var viewpointExtent = currentViewpoint.TargetGeometry.Extent;

				IdentifyParameters identifyParams = new IdentifyParameters(e.Location, viewpointExtent, 2, (int)MyMapView.ActualHeight, (int)MyMapView.ActualWidth)
				{
					LayerOption = LayerOption.Visible,
					SpatialReference = MyMapView.SpatialReference,
				};

				IdentifyTask identifyTask = new IdentifyTask(
					new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"));

				var result = await identifyTask.ExecuteAsync(identifyParams);

				resultsGrid.DataContext = result.Results;
				if (result != null && result.Results != null && result.Results.Count > 0)
					titleComboBox.SelectedIndex = 0;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message, "Identify Sample");
			}
			finally
			{
				progress.Visibility = Visibility.Collapsed;
			}
		}
	}
}
Feedback on this topic?