S57 Identify

Download Samples Repository

Description

This sample demonstrates how to perform a point-based identify style operation on an HydrographicS57Layer using the SearchLayer method.

"Desktop" "Store" Available for Desktop, Store

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.Symbology.Hydrographic.S57IdentifySample"
             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"
             xmlns:hydro="clr-namespace:Esri.ArcGISRuntime.Hydrographic;assembly=Esri.ArcGISRuntime"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="1200" d:DesignWidth="1600">
    <UserControl.Resources>
        <!-- selected point -->
        <esri:SimpleRenderer x:Key="PointSelectionRenderer">
            <esri:SimpleMarkerSymbol Color="Blue" />
        </esri:SimpleRenderer>
        <!-- selected polyline -->
        <esri:SimpleRenderer x:Key="LineSelectionRenderer">
            <esri:SimpleLineSymbol Color="Blue" Width="2" />
        </esri:SimpleRenderer>
        <!-- selected polygon -->
        <esri:SimpleLineSymbol x:Key="OutlineSelectionSymbol" Color="Black"/>
        <esri:SimpleFillSymbol x:Key="SelectionSymbol" Color="Blue" Style="DiagonalCross" Outline="{StaticResource OutlineSelectionSymbol}"/>
        <esri:SimpleRenderer x:Key="SelectionRendrer" Symbol="{StaticResource SelectionSymbol}"/>
    </UserControl.Resources>
    <Grid>
        <esri:MapView x:Name="MyMapView" 
					  LayerLoaded="MyMapView_LayerLoaded"
					  MapViewTapped="MyMapView_MapViewTapped">
            <esri:Map>
                <esri:ArcGISTiledMapServiceLayer ID="Ocean_BaseMap"
                        ServiceUri="http://services.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer" />

                <!-- Using group layer to group all Hydrographic layers -->
                <esri:GroupLayer ID="Hydrographic">
                    <hydro:HydrographicS57Layer ID="US1WCO1M" 
						Path="..\..\..\samples-data\symbology\s57-electronic-navigational-charts\us1wc01m\US1WC01M.000">
                    </hydro:HydrographicS57Layer>
                    <hydro:HydrographicS57Layer ID="US1WC07M" 
						Path="..\..\..\samples-data\symbology\s57-electronic-navigational-charts\us1wc07m\US1WC07M.000">
                    </hydro:HydrographicS57Layer>
                </esri:GroupLayer>
            </esri:Map>
            <esri:MapView.GraphicsOverlays>
                <esri:GraphicsOverlay ID="polygonResultsOverlay" Renderer="{StaticResource SelectionRendrer}"/>
                <esri:GraphicsOverlay ID="lineResultsOverlay" Renderer="{StaticResource LineSelectionRenderer}"/>
                <esri:GraphicsOverlay ID="pointResultsOverlay" Renderer="{StaticResource PointSelectionRenderer}"/>
            </esri:MapView.GraphicsOverlays>
        </esri:MapView>


        <Border Background="White" BorderBrush="Black" BorderThickness="1" Margin="0,30,30,0" Padding="20"
                HorizontalAlignment="Right" VerticalAlignment="Top" Height="500" Width="400" >
            <Border.Effect>
                <DropShadowEffect />
            </Border.Effect>
        </Border>

        <Border Background="White" BorderBrush="Black" BorderThickness="1" Margin="0,30,30,0" Padding="20"
                HorizontalAlignment="Right" VerticalAlignment="Top" Height="500" Width="400">
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">

                <StackPanel>
                    <TextBlock Text="Identify results"
						   FontWeight="ExtraBold"
                           FontSize="14"
						   TextAlignment="Left" TextWrapping="Wrap" />
                    <Border x:Name="noResultsArea" Margin="10" Padding="20">
                        <TextBlock Text="No identify results."/>
                    </Border>

                    <!-- List of results -->
                    <StackPanel x:Name="resultsArea" Visibility="Collapsed" >
                        <ListView x:Name="resultList" SelectionMode="Single" SelectionChanged="resultList_SelectionChanged">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <StackPanel Margin="5">
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="Acronym: " />
                                                <TextBlock Text="{Binding Path=Acronym}" />
                                            </StackPanel>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="Long Name: " />
                                                <TextBlock Text="{Binding Path=LongName}"/>
                                            </StackPanel>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="Cell Name: " />
                                                <TextBlock Text="{Binding Path=CellName}"/>
                                            </StackPanel>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="Composition Scale: " />
                                                <TextBlock Text="{Binding Path=CompositionScale}"/>
                                            </StackPanel>
                                        </StackPanel>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                        <DataGrid ItemsSource="{Binding ElementName=resultList, Path=SelectedItem.Attributes}"  
							  AutoGenerateColumns="True" HeadersVisibility="All" 
                              Background="White" >
                        </DataGrid>
                    </StackPanel>
                </StackPanel>
            </ScrollViewer>
        </Border>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Hydrographic;
using Esri.ArcGISRuntime.Layers;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop.Symbology.Hydrographic
{
	/// <summary>
	/// This sample demonstrates how to perform a point-based identify style operation on an HydrographicS57Layer using the SearchLayer method.
	/// </summary>
	/// <title>S57 Identify</title>
	/// <category>Symbology</category>
	/// <subcategory>Hydrographic</subcategory>
	/// <requiresSymbols>true</requiresSymbols>
	public partial class S57IdentifySample : UserControl
	{
		private GroupLayer _hydrographicLayers;
		private GraphicsOverlay _pointResultGraphicsOverlay;
		private GraphicsOverlay _lineResultGraphicsOverlay;
		private GraphicsOverlay _polygonResultGraphicsOverlay;
		private ObservableCollection<S57FeatureObject> _searchResults;
		private bool _isLoaded;

		public S57IdentifySample()
		{
			InitializeComponent();
			_searchResults = new ObservableCollection<S57FeatureObject>();
			resultList.ItemsSource = _searchResults;

			// Reference layers that are used
			_hydrographicLayers = MyMapView.Map.Layers.OfType<GroupLayer>().First();
			_polygonResultGraphicsOverlay = MyMapView.GraphicsOverlays["polygonResultsOverlay"];
			_lineResultGraphicsOverlay = MyMapView.GraphicsOverlays["lineResultsOverlay"];
			_pointResultGraphicsOverlay = MyMapView.GraphicsOverlays["pointResultsOverlay"];
			ZoomToHydrographicLayers();
		}

		// When user clicks/taps the map, execute search to all hydrographic layers and set results to view
		private async void MyMapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
		{
			if (!_isLoaded)
				return;

			// Clear previous results
			_searchResults.Clear();

			foreach (var layer in _hydrographicLayers.ChildLayers)
			{
				var hydroLayer = layer as HydrographicS57Layer;

				// Identify feature objects from layer
				var results = await hydroLayer.HitTestAsync(MyMapView, e.Position, 10, 3);
			
				// Add results to results list
				if (results != null && results.Count > 0)
				{
					foreach (var result in results)
						_searchResults.Add(result);
				}
			}

			// Show results if there were any, other vice show no results
			if (_searchResults.Count > 0)
			{
				// Select first one
				resultList.SelectedIndex = 0;
				resultsArea.Visibility = Visibility.Visible;
				noResultsArea.Visibility = Visibility.Collapsed;
			}
			else
			{
				resultsArea.Visibility = Visibility.Collapsed;
				noResultsArea.Visibility = Visibility.Visible;
			}
		}

		// Zoom to combined extent of the group layer that contains all hydrographic layers
		private async void ZoomToHydrographicLayers()
		{
			try
			{
				// wait until all layers are loaded
				await MyMapView.LayersLoadedAsync();

				Envelope extent = _hydrographicLayers.ChildLayers.First().FullExtent;

				// Create combined extent from child hydrographic layers
				foreach (var layer in _hydrographicLayers.ChildLayers)
					extent = extent.Union(layer.FullExtent);

				// Zoom to full extent
				await MyMapView.SetViewAsync(extent);
				_isLoaded = true;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		// Show error if loading layers fail
		private void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
		{
			if (e.LoadError == null)
				return;

			MessageBox.Show(
					string.Format("Error when loading layer. {0}", e.LoadError.ToString()),
					"Error loading layer");
		}

		private void resultList_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			// Clear previous selection
			_polygonResultGraphicsOverlay.Graphics.Clear();
			_lineResultGraphicsOverlay.Graphics.Clear();
			_pointResultGraphicsOverlay.Graphics.Clear();

			// When no results found, this is 0
			if (e.AddedItems.Count > 0)
			{
				// Using single mode so there is only one item
				var selectedFeatureObject = e.AddedItems[0] as S57FeatureObject;

				var selectedGeometry = selectedFeatureObject.Geometry;
				if (selectedGeometry is Polygon)
				{
					_polygonResultGraphicsOverlay.Graphics.Add(new Graphic(selectedFeatureObject.Geometry));
					_polygonResultGraphicsOverlay.Graphics[0].IsSelected = true;
				}
				else if (selectedGeometry is Polyline)
				{
					_lineResultGraphicsOverlay.Graphics.Add(new Graphic(selectedFeatureObject.Geometry));
					_lineResultGraphicsOverlay.Graphics[0].IsSelected = true;
				}
				else if (selectedGeometry is MapPoint)
				{
					_pointResultGraphicsOverlay.Graphics.Add(new Graphic(selectedFeatureObject.Geometry));
					_pointResultGraphicsOverlay.Graphics[0].IsSelected = true;
				}
			}
		}
	}
}
Feedback on this topic?