Load WebMap

Download Samples Repository


This sample demonstrates adding data a WebMap from ArcGIS Online to an application.

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

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.LoadWebMap"
    <Grid x:Name="layoutGrid">
        <esri:MapView x:Name="MyMapView" />

		<Border x:Name="uiPanel" 
				Background="White" BorderBrush="Black" BorderThickness="1"
				HorizontalAlignment="Right" VerticalAlignment="Top"
				Margin="30" Padding="20" Width="375">
                <TextBlock Text="Select a featured map or enter the ID of a WebMap to load:" 
						   Margin="0,0,0,2" TextWrapping="Wrap" />
                <ComboBox x:Name="comboWebMap" IsEditable="True" 
						  DisplayMemberPath="Title" SelectedValuePath="Id" />
                <Button Content="Load WebMap" IsDefault="True" 
						HorizontalAlignment="Center" Margin="0,8,0,0" 
						Click="LoadButton_Click" />

                <ProgressBar x:Name="progress" IsIndeterminate="True"
							 Margin="12,12,12,0" Visibility="Hidden" />

                <Grid x:Name="detailsPanel" Margin="0,12,0,0" Visibility="Collapsed">
                        <Style TargetType="TextBlock">
                            <Setter Property="Margin" Value="4,2" />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" 
							   Text="WebMap Details" FontSize="14" FontWeight="Bold" />

                    <TextBlock Grid.Row="1" Grid.Column="0" Text="Title:" FontStyle="Italic" />
                    <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Title}" TextWrapping="Wrap" />

                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Snippet:" FontStyle="Italic" />
                    <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Snippet}" TextWrapping="Wrap" />

                    <TextBlock Grid.Row="3" Grid.Column="0" Text="Owner:" FontStyle="Italic" />
                    <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding Owner}" TextWrapping="Wrap" />
using Esri.ArcGISRuntime.Portal;
using Esri.ArcGISRuntime.WebMap;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
    /// <summary>
    /// This sample demonstrates adding data a WebMap from ArcGIS Online to an application.
    /// </summary>
    /// <title>Load WebMap</title>
    /// <category>Portal</category>
    public partial class LoadWebMap : UserControl
        private ArcGISPortal _portal;

        /// <summary>Construct Load WebMap sample control</summary>
        public LoadWebMap()

            Loaded += LoadWebMap_Loaded;

        // Loads UI elements and an initial webmap
        private async void LoadWebMap_Loaded(object sender, RoutedEventArgs e)
            _portal = await ArcGISPortal.CreateAsync();

            var searchParams = new SearchParameters("type: \"web map\" NOT \"web mapping application\"");
            var result = await _portal.ArcGISPortalInfo.SearchHomePageFeaturedContentAsync(searchParams);
            comboWebMap.ItemsSource = result.Results;

            var webmap = result.Results.FirstOrDefault();
            if (webmap != null)
                comboWebMap.SelectedIndex = 0;
                await LoadWebMapAsync(webmap.Id);

        // Loads a webmap on load button click
        private async void LoadButton_Click(object sender, RoutedEventArgs e)
            string id = string.Empty;
            if (comboWebMap.SelectedIndex >= 0)
                id = comboWebMap.SelectedValue as string;
                id = comboWebMap.Text;

            await LoadWebMapAsync(id);

        // Loads the given webmap
        private async Task LoadWebMapAsync(string wmId)
                progress.Visibility = Visibility.Visible;

                var item = await ArcGISPortalItem.CreateAsync(_portal, wmId);
                var webmap = await WebMap.FromPortalItemAsync(item);
                var vm = await WebMapViewModel.LoadAsync(webmap, _portal);
                MyMapView.Map = vm.Map;

                detailsPanel.DataContext = item;
                detailsPanel.Visibility = Visibility.Visible;
            catch (Exception ex)
                detailsPanel.Visibility = Visibility.Visible;
                MessageBox.Show(ex.Message, "Sample Error");
                progress.Visibility = Visibility.Hidden;
Feedback on this topic?