Map Grid

Download Samples Repository

Description

This sample shows how to enable a map grid using the MapView.MapGrid property.The user is allowed to switch between the standard grid types (Latitude / Longitude, MGRS, UTM, and USNG) by using a combobox in the upper right corner of the screen.

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

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.MapGrid"
             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_Topo_Map/MapServer" />
            </esri:Map>
            
            <!-- The following turns on the MapGrid via XAML -->
            <!--<esri:MapView.MapGrid>
                <esri:LatLonMapGrid />
            </esri:MapView.MapGrid>-->
        </esri:MapView>

		<Border Background="White" BorderBrush="Black" BorderThickness="1"
				HorizontalAlignment="Right" VerticalAlignment="Top"
				Margin="30" Padding="20">
			<Border.Effect>
				<DropShadowEffect/>
			</Border.Effect>
			<StackPanel>
                <TextBlock Text="Grid Type:" Margin="4,0" FontWeight="Bold" />
                <ComboBox x:Name="gridTypeCombo" Margin="4" Width="100"
                          SelectionChanged="gridTypeCombo_SelectionChanged"
                          ItemsSource="{Binding GridTypes}" SelectedIndex="0" />
            </StackPanel>
		</Border>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using System.Collections.Generic;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
	/// <summary>
	/// This sample shows how to enable a map grid using the MapView.MapGrid property.  The user is allowed to switch between the standard grid types (Latitude / Longitude, MGRS, UTM, and USNG) by using a combobox in the upper right corner of the screen.
	/// </summary>
	/// <title>Map Grid</title>
	/// <category>Mapping</category>
	public partial class MapGrid : UserControl
	{
		public List<string> GridTypes { get; set; }

		private MapGridLevelCollection _mapGridLevels;

		public MapGrid()
		{
			InitializeComponent();
			GridTypes = new List<string>() { "None", "Lat/Lon", "MGRS", "UTM", "USNG" };
			DataContext = this;
		}

		private void gridTypeCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			switch (gridTypeCombo.SelectedIndex)
			{
				case 0:
					MyMapView.MapGrid = null;
					break;
				case 1:
					LatLonMapGrid latLongMapGrid = new LatLonMapGrid();
					// Use Geographic positioning for LatLong MapGrid.
					latLongMapGrid.LabelPosition = MapGridLabelPosition.Geographic;
					MyMapView.MapGrid = latLongMapGrid;
					break;
				case 2:
					MgrsMapGrid mgrsGrid = new MgrsMapGrid();
					// Use Screen-aligned TopLeft position for MGRS MapGrid.
					mgrsGrid.LabelPosition = MapGridLabelPosition.TopLeft;
					MyMapView.MapGrid = mgrsGrid;
					break;
				case 3:
					UtmMapGrid utmGrid = new UtmMapGrid();
					MyMapView.MapGrid = utmGrid;
					break;
				case 4:
					UsngMapGrid usngMapGrid = new UsngMapGrid();
					// Use Screen-aligned AllSides option for USNG MapGrid.
					usngMapGrid.LabelPosition = MapGridLabelPosition.AllSides;
					MyMapView.MapGrid = usngMapGrid;
					break;
			}
		}
	}
}
Feedback on this topic?