Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Get Samples

Download Samples Repository

Description

This sample demonstrates using an QueryTask to Query an ArcGISImageServiceLayer to find the outlines of image tiles and display them in a GraphicOverlay. MapOverlay attribute information is displayed for selected tile graphics when they are clicked on the map.

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

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.GetSamples"
             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:SimpleFillSymbol x:Key="FootprintFillSymbol" Color="Transparent" Style="Solid">
                <esri:SimpleFillSymbol.Outline>
                    <esri:SimpleLineSymbol Color="White" Style="Solid" Width="2" />
                </esri:SimpleFillSymbol.Outline>
            </esri:SimpleFillSymbol>

            <esri:SimpleRenderer x:Key="FillRenderer" Symbol="{StaticResource FootprintFillSymbol}" />
        </Grid.Resources>

        <esri:MapView x:Name="MyMapView" WrapAround="True" MapViewTapped="MyMapView_MapViewTapped">
            <esri:Map>
                <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                    ServiceUri="http://services.arcgisonline.com/arcgis/rest/services/Canvas/World_Light_Gray_Base/MapServer" />

                <esri:ArcGISImageServiceLayer x:Name="imageLayer"
                    ServiceUri="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/Aerial/ImageServer" />
            </esri:Map>

            <esri:MapView.GraphicsOverlays>
                <esri:GraphicsOverlay ID="graphicsOverlay" Renderer="{StaticResource FillRenderer}"/>
            </esri:MapView.GraphicsOverlays>

            <esri:MapView.Overlays>
                <esri:OverlayItemsControl>
                    <Border x:Name="mapTip" HorizontalAlignment="Right" VerticalAlignment="Top" Padding="12"
                            Background="LightGray" BorderBrush="Black" BorderThickness="2" Visibility="Collapsed">
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Grid.Column="0" Text="Name: " FontWeight="Bold" />
                                <TextBlock Grid.Column="1" Text="{Binding Attributes[Name]}" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Grid.Column="0" Text="Pixel Size (meters/pixel): " FontWeight="Bold"/>
                                <TextBlock Grid.Column="1" Text="{Binding Attributes[LowPS]}" />
                            </StackPanel>
                        </StackPanel>
                    </Border>
                </esri:OverlayItemsControl>
            </esri:MapView.Overlays>
        </esri:MapView>

        <Border x:Name="uiPanel"
				Background="White" BorderBrush="Black" BorderThickness="1"
				HorizontalAlignment="Right" VerticalAlignment="Top"
				Margin="30" Padding="20"
				Width="350">
            <Border.Effect>
                <DropShadowEffect/>
            </Border.Effect>
            <StackPanel>
                <TextBlock Text="Click the 'Get Samples' button and drag a rectangle on the map to query image tiles. Tile footprints will be displayed and their attributes will be available in map tips."
                           Margin="12,0,12,0" TextWrapping="Wrap" />

                <Button Content="Get Samples" Margin="30,12,30,0" Click="GetSamplesButton_Click" />

                <ProgressBar x:Name="progress" IsIndeterminate="True" Margin="12,12,12,0" Visibility="Collapsed" />
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.Tasks.Query;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// This sample demonstrates using an QueryTask to Query an ArcGISImageServiceLayer to find the outlines of image tiles and display them in a GraphicOverlay. MapOverlay attribute information is displayed for selected tile graphics when they are clicked on the map.
    /// </summary>
    /// <title>Get Samples</title>
    /// <category>Tasks</category>
    /// <subcategory>Imagery</subcategory>
    public partial class GetSamples : UserControl
    {
		private GraphicsOverlay _graphicsOverlay;
		private FrameworkElement _mapTip;

        /// <summary>Construct Get Image Samples sample control</summary>
        public GetSamples()
        {
            InitializeComponent();
			_graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];
			_mapTip = MyMapView.Overlays.Items.First() as FrameworkElement;
            MyMapView.LayerLoaded += MyMapView_LayerLoaded;
        }

        // Zoom to the image service extent
        private async void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
        {
            if (e.Layer is ArcGISImageServiceLayer)
            {
                if (e.Layer.FullExtent != null)
                    await MyMapView.SetViewAsync(e.Layer.FullExtent);
            }
        }

        // Start query process on user button click
        private async void GetSamplesButton_Click(object sender, RoutedEventArgs e)
        {
            _graphicsOverlay.Graphics.Clear();
			_mapTip.Visibility = System.Windows.Visibility.Collapsed;
			await QueryImageTiles();
        }

        // Query the image service for sample tiles
        private async Task QueryImageTiles()
        {
            try
            {
                var envelope = await MyMapView.Editor.RequestShapeAsync(DrawShape.Envelope) as Envelope;

                QueryTask queryTask = new QueryTask(
					new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/Aerial/ImageServer/"));

                Query query = new Query(envelope)
                {
                    OutFields = new OutFields(new string[] { "Name", "LowPS" }),
                    ReturnGeometry = true,
                    OutSpatialReference = MyMapView.SpatialReference,
                    Where = "Category = 1"
                };

                var result = await queryTask.ExecuteAsync(query);

				_graphicsOverlay.Graphics.AddRange(result.FeatureSet.Features.OfType<Graphic>());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
        }

        // Hittest the graphics layer and show the map tip for the selected graphic
        private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            try
            {
				_graphicsOverlay.ClearSelection();

				var graphic = await _graphicsOverlay.HitTestAsync(MyMapView, e.Position);
                if (graphic != null)
                {
                    graphic.IsSelected = true;
					MapView.SetViewOverlayAnchor(mapTip, e.Location);
					_mapTip.DataContext = graphic;
					_mapTip.Visibility = System.Windows.Visibility.Visible;
                }
                else
					_mapTip.Visibility = System.Windows.Visibility.Collapsed;
            }
            catch
            {
				_mapTip.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
    }
}
Feedback on this topic?