Click or drag to resize
Code Example - BaseMaps

Demonstrates switching out various BaseMap (via ArcGISTiledMapServiceLayer) layers served up by ArcGIS Online.

Code Example
Base Maps

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

<Window x:Class="BaseMaps.MainWindow"
    Title="MainWindow" Height="600" Width="800">

    <Grid x:Name="LayoutRoot">

        <StackPanel Orientation="Vertical">

            <!-- Add a TextBlock to hold the instructions on how to use the sample code. -->
            <TextBlock Name="TextBlock1" TextWrapping="Wrap" Height="77" />

            <StackPanel Orientation="Horizontal">

                <!-- Add a ComboBox to hold Urls to BaseMaps on ArcGIS Online. -->
                <ComboBox Name="ComboxBox1" Width="600" Margin="0,0,10,0" />

                <!-- Add a Button to switch the BaseMap layer (an ArcGISTileMapServiceLayer) in the Map Control. -->
                <Button Content="Change BaseMap" Name="Button1" Width="160" Click="Button1_Click"/>


            <!-- Add a MapView Control. -->
            <esri:MapView x:Name="MapView1" Background="Blue" Margin="0,10,0,0" Height="458" >

                <!-- Add a Map. -->
                <esri:Map x:Name="Map1" />




SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "BaseMaps.MainWindow" to be just "MainWindow".

namespace BaseMaps

    public partial class MainWindow : System.Windows.Window
        public MainWindow()
            // This call is required by the designer.

            // Provide instructions on how to use the sample. 
            TextBlock1.Text = "When the application loads, choose a Url from the ComboBox drop-down and click the 'Change BaseMap' button. An " + 
                "ArcGISTiledMapServiceLayer will load and be displayed in the Map. The listing of Urls available come from BaseMaps available " + 
                "on ArcGIS Online ( Additional BaseMaps are periodically added so check back " + 
                "often for additional layer that may be available.";

            // Add the URL's for the various BaseMaps available on ArcGIS Online (
            ComboxBox1.Items.Add(""); // World Topographic Map
            ComboxBox1.Items.Add(""); // World Street Map
            ComboxBox1.Items.Add(""); // Light Gray Canvas
            ComboxBox1.Items.Add(""); // National Geographic World Map
            ComboxBox1.Items.Add(""); // Ocean Basemap
            ComboxBox1.Items.Add(""); // Terrain with Labels
            ComboxBox1.Items.Add(""); // World Imagery
            ComboxBox1.Items.Add(""); // World Globe 1790
            ComboxBox1.Items.Add(""); // World Globe 1812

        private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
            // Clear out any existing layers in the Map.

            // Get the Url string for the various ArcGISTiledMapServiceLayer BaseMap's on ArcGIS Online.
            string myUserChoice = (string)ComboxBox1.SelectedValue;

            // Create a new ArcGISTiledMapServiceLayer and set its .ServiceUri Property.
            Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer myArcGISTiledMapServiceLayer = new Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer();
            myArcGISTiledMapServiceLayer.ServiceUri = myUserChoice;

            // Add the ArcGISTiledMapServiceLayer to the LayercCollection of the Map.