View in MAUI WPF WinUI View on GitHub Sample viewer app

Specify a map’s spatial reference.

Image of map spatial reference

Use case

Choosing the correct spatial reference is important for ensuring accurate projection of data points to a map.

How to use the sample

Pan and zoom around the map. Observe how the map is displayed in the World Bonne spatial reference. Pick a different spatial reference and see the map reproject.

How it works

  1. Instantiate a Map object using a spatial reference.
  2. Instantiate a Basemap object using an ArcGISMapImageLayer object.
  3. Set the basemap to the map.
  4. Set the map to a MapView object.
  5. Change the map’s spatial reference using SetSpatialReference method.

The ArcGIS map image layer will reproject into the spatial reference set to the map (such as World Bonne (WKID: 54024)), and not the map service’s default spatial reference.

Relevant API

  • ArcGISMapImageLayer
  • Basemap
  • Map
  • MapView
  • SpatialReference

About the data

This sample uses a World Cities Population map service that displays world cities symbolized based on population.

Additional information

Operational layers will automatically project to this spatial reference when possible. There are 3 kinds of layer reprojection behaviors:

  • Reprojected on device (on-the-fly reprojection), such as a FeatureLayer created from a mobile geodatabase
  • Reprojected from the service, such as an ArcGISMapImageLayer
  • Not able to reproject, such as an ArcGISTiledLayer with defined spatial reference in its tile cache. These layer might be able to reproject in a future update

For more information, check out the API reference doc for SetSpatialReference method.

Tags

coordinate system, project, projection, spatial reference, Web Mercator, WGS84, WKID

Sample Code

SetSpatialReference.xaml SetSpatialReference.xaml SetSpatialReference.xaml.cs
<UserControl
x:Class="ArcGIS.WPF.Samples.SetSpatialReference.SetSpatialReference"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.UI.Controls;assembly=Esri.ArcGISRuntime.WPF">
<Grid>
<esriUI:MapView x:Name="MyMapView" />
<Border Style="{StaticResource BorderStyle}">
<StackPanel>
<TextBlock
Margin="0,0,0,5"
FontWeight="Bold"
Text="Set Spatial Reference" />
<ComboBox
x:Name="SpatialReferenceComboBox"
Width="250"
DisplayMemberPath="Name"
SelectionChanged="SpatialReferenceComboBox_SelectionChanged" />
</StackPanel>
</Border>
</Grid>
</UserControl>