Click or drag to resize
MapViewSpatialReference Property
Gets the spatial reference of the map.

Namespace: Esri.ArcGISRuntime.Controls
Assembly: Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: (
public override SpatialReference SpatialReference { get; }

Property Value

Type: SpatialReference

This Property only obtains the SpatialReference. To set the SpatialReference of the MapView, a Map must be added to the MapView.Map Property and the Map.SpatialReference must be set.


Demonstrates resetting the MapView.SpatialReference by setting it to a new Map.

Changing the MapView.SpatialReference.

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



            <!-- Add a ListBox that will hold Uri strings to various ArcGISDynamicMapServiceLayers.-->
            <ListBox x:Name="ListBox1" Height="75"/>

            <StackPanel Orientation="Horizontal">

                <!-- Add a button to add the ArcGISDynamicMapServiceLayer to the Map. -->
                <Button x:Name="Button1" Content="Add the Layer to the Map" Click="Button1_Click" Margin="0,0,3,3" Width="390"/>

                <!-- Add a button to obtain the SpatialReference and Extent of the MapView. -->
                <Button x:Name="Button2" Content="What's the Spatial Reference/Extent?" Click="Button2_Click"  Margin="0,0,3,3" Width="390"/>


            <!-- Add a default MapView and Map to the UI. -->
            <esri:MapView x:Name="MapView1" Height="474">
                <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 "MapView_SpatialReference.MainWindow" to be just "MainWindow".

// Typically the MapView.SpatialReference is set based upon the layers that are added to the Map.
// This example code shows how to reset the MapView.SpatialReference. 
// STEP1:
// When the application loads, select the 1st ServiceUri in the Listbox and click the button 'Add Layer to the Map'.
// Then click the button 'What's the Spatial Reference/Extent?' 
// The SpatialReference WKID = 4326.
// STEP2:
// Then repeat selecting the 2nd ServiceUri in the Listbox and click the button 'Add Layer to the Map'.
// You should get an MessageBox that says "This is a bad layer.".
// Then click the button 'What's the Spatial Reference/Extent?'
// The SpatialReference is Nothing/null. The MessageBox should say: "No SpatialReference Set"
// STEP3:
// Then repeat selecting the 3nd ServiceUri in the Listbox and click the button 'Add Layer to the Map'.
// Then click the button 'What's the Spatial Reference/Extent?'
// The SpatialReference WKID = 102100.

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

            // Add various ServiceUri strings into the ListBox. Some are good and others do not exist.
            // ---------------------------------------------------------------------------------------

            // This is a good web service. WKID=4326

            // This web service does not exist

            // This is a good web service. WKID=102100

           private async void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
            // Create a new Map and set it to the MapView.Map Property. This will reset the MapView.SpatialReference to Nothing/null.
            Esri.ArcGISRuntime.Controls.Map myMap = new Esri.ArcGISRuntime.Controls.Map();
            MapView1.Map = myMap;

            // Create a string to hold the Uri a an ArcGISDynamicMapServiceLayer.
            string theArcGISDynamicMapServiceLayerName = null;

                // Get the Uri string from the users ListBox choice.
                theArcGISDynamicMapServiceLayerName = ListBox1.SelectedItem.ToString();
            catch (System.Exception)
                // The user did not select a Uri string before clicking the button. Let them know what they need to do.
                System.Windows.MessageBox.Show("You must select a ServiceUri string in the listbox before clicking the button.");

            // Create a new ArcGISDynamicMapServiceLayer based upon the user selected Uri string.
            Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = new Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer();
            myArcGISDynamicMapServiceLayer.ServiceUri = theArcGISDynamicMapServiceLayerName;

                // Initialize the ArcGISDynamicMapServiceLayer.
                await myArcGISDynamicMapServiceLayer.InitializeAsync();

                // Add the ArcGISDynamicMapServiceLayer to the Map's LayerCollection.
                // This will cause the MapView.SpatialReference to take on the SpatialReference of the layer just added.
            catch (System.Exception)
                // We had an error for the 2nd ServiceUri in the ListBox. This is expected.
                System.Windows.MessageBox.Show("This is a bad layer.");


        private void Button2_Click(object sender, System.Windows.RoutedEventArgs e)
            // Get the MapView's SpatialReference.
            Esri.ArcGISRuntime.Geometry.SpatialReference theSpatialReference = MapView1.SpatialReference;

            if (theSpatialReference != null)
                // Get the Extent Envelope of the MapView.
                Esri.ArcGISRuntime.Geometry.Envelope theEnvelopeExtent = MapView1.Extent;

                // Display to the user the MapView.SpatialReference Wkid and the Extent coordinates.
                System.Windows.MessageBox.Show(theEnvelopeExtent.ToString(), theSpatialReference.Wkid.ToString());
                // There was not MapView.SpatialReference. This is because the user chose the bogus (2nd service).
                System.Windows.MessageBox.Show("No SpatialReference Set", "No SpatialReference Set");

See Also
Supported Platforms
This type is supported on the following ArcGIS Runtime .NET SDK platforms:
Windows Desktop
Windows Phone
Windows Store