Click or drag to resize
Code Example - MultipleMapsInMapView

Demonstrates switching out different Map objects (with different layers) for the MapView.Map Property.

Code Example
Multiple Maps In Map View

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="MultipleMapsInMapView.MainWindow"
        Title="MainWindow" Height="600" Width="800">

        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">

                <!-- Add a MapView Control.  We will set various Map's (with different Layers) in code behind based 
                on the users ListBox choice.  -->
                <esri:MapView x:Name="MyMapView" Width="637" Height="568" VerticalAlignment="Top"/>

                <TextBlock Width="10"/>
                <StackPanel Orientation="Vertical">
                    <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Pick a Map" 
                               VerticalAlignment="Top" Height="20"/>

                    <!-- This is the ListBox that will have the various Map objects available. -->
                    <ListBox x:Name="ListBox1" VerticalAlignment="Top" Width="120" Height="300"


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 "MultipleMapsInMapView.MainWindow" to be just "MainWindow".

// Click on the various Map names in the ListBox to switch between different Map controls as the MapView.Map Property.
// Each Map Control will have a different collection of layers (some with different Spatial References).

namespace MultipleMapsInMapView

    public partial class MainWindow : System.Windows.Window
        public MainWindow()

            // Add three strings for the different Map objects that will be renderer.

        private void ListBox1_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)

            if (ListBox1.SelectedItem.ToString() == "Map1")

                // Create an ArcGISTiledMapServiceLayer and an ArcGISDynamicMapServiceLayer and add it to Map1. Then set the MyMapView.Map to Map1. 

                Esri.ArcGISRuntime.Controls.Map Map1 = new Esri.ArcGISRuntime.Controls.Map();

                Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer ArcGISTiledMapServiceLayer1 = new Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer();
                ArcGISTiledMapServiceLayer1.ServiceUri = "";
                ArcGISTiledMapServiceLayer1.ID = "World_Light_Gray_Base";

                Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer ArcGISDynamicMapServiceLayer1 = new Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer();
                ArcGISDynamicMapServiceLayer1.ServiceUri = "";
                ArcGISDynamicMapServiceLayer1.ID = "USA_1990-2000_Population_Change";


                MyMapView.Map = Map1;

            else if (ListBox1.SelectedItem.ToString() == "Map2")

                // Create an ArcGISImageServiceLayer and add it to Map2. Then set the MyMapView.Map to Map2. 

                Esri.ArcGISRuntime.Controls.Map Map2 = new Esri.ArcGISRuntime.Controls.Map();

                Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer ArcGISImageServiceLayer2 = new Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer();
                ArcGISImageServiceLayer2.ServiceUri = "";
                ArcGISImageServiceLayer2.ID = "CaliforniaDEM";


                MyMapView.Map = Map2;

            else if (ListBox1.SelectedItem.ToString() == "Map3")

                // Create an ArcGISTiledMapServiceLayer and a FeatureLayer and add it to Map3. Then set the MyMapView.Map to Map3. 

                Esri.ArcGISRuntime.Controls.Map Map3 = new Esri.ArcGISRuntime.Controls.Map();
                Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer ArcGISTiledMapServiceLayer3 = new Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer();
                ArcGISTiledMapServiceLayer3.ServiceUri = "";
                ArcGISTiledMapServiceLayer3.ID = "World_Light_Gray_Base";

                Esri.ArcGISRuntime.Layers.FeatureLayer FeatureLayer3 = new Esri.ArcGISRuntime.Layers.FeatureLayer();
                Esri.ArcGISRuntime.Data.ServiceFeatureTable ServiceFeatureTable3 = new Esri.ArcGISRuntime.Data.ServiceFeatureTable();
                ServiceFeatureTable3.ServiceUri = "";
                ServiceFeatureTable3.OutFields = Esri.ArcGISRuntime.Tasks.Query.OutFields.All;
                FeatureLayer3.FeatureTable = ServiceFeatureTable3;


                MyMapView.Map = Map3;