Show Properties

Download Samples Repository

Description

This sample illustrates a simple way of querying the Portal metadata/properties and retrieving featuredItems using the Portal API.

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

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.ShowProperties"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid x:Name="layoutGrid">
        <Grid.Resources>
            <DataTemplate x:Key="PortalGroupTemplate">
                <StackPanel Margin="2">
                    <TextBlock Text="{Binding Title, StringFormat='Title: {0}'}" FontWeight="Bold"/>
                    <TextBlock Text="{Binding Snippet, StringFormat='Snippet: {0}'}" TextWrapping="Wrap" Width="500"/>
                    <TextBlock Text="{Binding Owner, StringFormat='Owner: {0}'}" />
                    <TextBlock Text="{Binding CreationDate, StringFormat='Creation Date: {0}'}" />
                </StackPanel>
            </DataTemplate>
        </Grid.Resources>

        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="35"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.ColumnSpan="2">
            <TextBlock Text="Portal Url:" Margin="10,5,5,5" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            <TextBox x:Name="PortalUrltextbox" Text="http://www.arcgis.com/sharing/rest"
                             HorizontalAlignment="Left" VerticalAlignment="Center" Width="250" Margin="5"/>
            <Button Content="Initialize" Click="LoadPortalInfo_Click" Height="25"/>
        </StackPanel>

        <Grid Margin="2" Grid.Row="1" Grid.Column="0">
            <TextBlock HorizontalAlignment="Left" Text="Portal Details" 
                       VerticalAlignment="Top" Margin="15,10,0,0" FontSize="12" 
                       FontWeight="Bold"/>
            <ListView x:Name="PropertiesListBox" Margin="5,35,5,5" />
        </Grid>

        <Grid Margin="2" Grid.Row="1" Grid.Column="1">
            <TextBlock HorizontalAlignment="Left" Text="Featured Maps" 
                       VerticalAlignment="Top" Margin="15,10,0,0" FontSize="12" 
                       FontWeight="Bold"/>
            <ListView x:Name="FeaturedMapsList" Margin="5,35,5,5">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="6">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Border Background="White" Width="200" Height="133">
                                <Image Source="{Binding ThumbnailUri}" Stretch="UniformToFill" />
                            </Border>
                            <StackPanel Orientation="Vertical" Grid.Column="1" Margin="8,4">
                                <TextBlock Text="{Binding Title, StringFormat='Title: {0}'}"/>
                                <TextBlock Text="{Binding Type, StringFormat='Type: {0}'}"/>
                                <TextBlock Text="{Binding Owner, StringFormat='Owner: {0}'}"/>
                                <TextBlock Text="{Binding CreationDate, StringFormat='Creation Date: {0}'}"/>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </Grid>
</UserControl>
 
using Esri.ArcGISRuntime.Portal;
using Esri.ArcGISRuntime.WebMap;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// This sample illustrates a simple way of querying the Portal metadata/properties and retrieving featuredItems using the Portal API.
    /// </summary>
    /// <title>Show Properties</title>
    /// <category>Portal</category>
    public partial class ShowProperties : UserControl
    {
        /// <summary>Construct Show Portal Properties sample control</summary>
        public ShowProperties()
        {
            InitializeComponent();
        }

        private async void LoadPortalInfo_Click(object sender, RoutedEventArgs e)
        {
            PropertiesListBox.Items.Clear();
            if (String.IsNullOrEmpty(PortalUrltextbox.Text))
                return;

            await InitializePortalAsync(PortalUrltextbox.Text);
        }

        // Initializes the given portal and populates UI
        private async Task InitializePortalAsync(string portalUrl)
        {
            try
            {
                var portal = await ArcGISPortal.CreateAsync(new Uri(portalUrl));

                ArcGISPortalInfo portalInfo = portal.ArcGISPortalInfo;
                if (portalInfo == null)
                {
                    MessageBox.Show("Portal Information could not be retrieved");
                    return;
                }

                PropertiesListBox.Items.Add(string.Format("Current Version: {0}", portal.CurrentVersion));
                PropertiesListBox.Items.Add(string.Format("Access: {0}", portalInfo.Access));
                PropertiesListBox.Items.Add(string.Format("Host Name: {0}", portalInfo.PortalHostname));
                PropertiesListBox.Items.Add(string.Format("Name: {0}", portalInfo.PortalName));
                PropertiesListBox.Items.Add(string.Format("Mode: {0}", portalInfo.PortalMode));

                Basemap basemap = portalInfo.DefaultBasemap;

                PropertiesListBox.Items.Add(string.Format("Default BaseMap Title: {0}", basemap.Title));
                PropertiesListBox.Items.Add(string.Format("WebMap Layers ({0}):", basemap.Layers.Count));

                foreach (WebMapLayer webmapLayer in basemap.Layers)
                {
                    PropertiesListBox.Items.Add(webmapLayer.Url);
                }

                var portalgroup = await portalInfo.GetFeaturedGroupsAsync();
                PropertiesListBox.Items.Add("Groups:");

                ListBox listGroups = new ListBox();
                listGroups.ItemTemplate = layoutGrid.Resources["PortalGroupTemplate"] as DataTemplate;
                listGroups.ItemsSource = portalgroup;
                PropertiesListBox.Items.Add(listGroups);

                var result = await portalInfo.SearchFeaturedItemsAsync(new SearchParameters() { Limit = 15 });
                FeaturedMapsList.ItemsSource = result.Results;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to initialize" + ex.Message);
            }
        }
    }
}
Feedback on this topic?