Basemap Switcher Online

This sample demonstrates how to search for, return, and use basemaps from ArcGIS Online. The sample creates a Map control from a web map, then calls ArcGISPortalInfo.SearchBasemapGalleryAsync to return the first 20 basemaps in a gallery hosted by ArcGIS Online and binds the result to a ListBox. Note, ArcGIS Online and other portals can define a gallery of basemaps Each basemap is simply a web map with basemap layers. When creating a Map from a web map, the Document class provides an attached property IsBaseMapProperty to tag layers within a Map as basemap layers. Use the Document.GetIsBaseMap() method to check this attached property you can determine which layers are basemap layers. Click on the basemaps in the ListBox to replace the basemap layers in the current Map control with layers from the basemap clicked. To do this, first get the ArcGISPortalItem bound to the button clicked, then get the web map associated with it. Next return all the basemap layers from the chosen web map and add them to the existing Map. One nuance in this process is that when adding new layers, some layers in the basemap are "Reference Layers" which go on top of all other layers in the Map (e.g. label layers). Note, this sample includes an operational layer that contains United States federal land holdings. Switching basemaps enables a user to quickly visualize relationships between federal ownership, human infrastructure, and natural features.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.BasemapSwitcher"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <ScrollViewer MaxWidth="200" HorizontalAlignment="Left" Margin="5">
            <ItemsControl x:Name="basemapList">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Button Click="BaseMapButton_Click" Margin="5">
                            <StackPanel>
                                <Image Source="{Binding ThumbnailUri}" Margin="3" Width="200" Height="133" />
                                <TextBlock Text="{Binding Title}" />
                            </StackPanel>
                        </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014