Switch Basemaps

Download Samples Repository

Description

Demonstrates changing the basemap layer in a map by switchingbetween ArcGIS tiled map services layers hosted by ArcGIS Online.

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

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.SwitchBasemaps"
             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>
        <esri:MapView x:Name="MyMapView" WrapAround="True" >
            <esri:Map>
                <esri:ArcGISTiledMapServiceLayer
                    ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
            </esri:Map>
        </esri:MapView>

		<Border Background="White" BorderBrush="Black" BorderThickness="1"
				HorizontalAlignment="Right" VerticalAlignment="Top"
				Margin="30" Padding="20">
			<Border.Effect>
				<DropShadowEffect/>
			</Border.Effect>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5">
                <RadioButton Tag="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" 
                             IsChecked="true" Margin="5,0,0,0" 
                             GroupName="Layers" Content="Streets" Click="RadioButton_Click"/>
                <RadioButton Tag="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" Margin="5,0,0,0"  
                             GroupName="Layers" Content="Topographic" Click="RadioButton_Click"/>
                <RadioButton Tag="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" Margin="5,0,0,0"  
                             GroupName="Layers" Content="Imagery" Click="RadioButton_Click"/>
				<RadioButton Tag="http://services.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer" Margin="5,0,0,0"  
                             GroupName="Layers" Content="Oceans" Click="RadioButton_Click"/>
                <RadioButton Tag="http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer" Margin="5,0,0,0"  
                             GroupName="Layers" Content="National Geographic" Click="RadioButton_Click"/>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Layers;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// Demonstrates changing the basemap layer in a map by switching  between ArcGIS tiled map services layers hosted by ArcGIS Online.
    /// </summary>
    /// <title>Switch Basemaps</title>
	/// <category>Mapping</category>
	public partial class SwitchBasemaps : UserControl
    {
        public SwitchBasemaps()
        {
            InitializeComponent();
        }

        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            MyMapView.Map.Layers.RemoveAt(0);

			MyMapView.Map.Layers.Add(new ArcGISTiledMapServiceLayer()
            {
                ServiceUri = ((RadioButton)sender).Tag as string
            });
        }
    }
}
Feedback on this topic?