View in MAUI WPF WinUI View on GitHub

Display and customize coordinate system grids including Latitude/Longitude, MGRS, UTM and USNG on a map view or scene view.

Image of display grid

Use case

Grids are often used on printed maps, but can also be helpful on digital 2D maps or 3D scenes, to identify locations.

How to use the sample

Use the controls to change the grid settings. You can change the view from 2D or 3D, select the type of grid from Grid Type (LatLong, MGRS, UTM, and USNG) and modify its properties like label visibility, grid line color, grid label color, label formatting, and label offset.

How it works

  1. Create an instance of one of the Grid types.
  2. Grid lines and labels can be styled per grid level with setLineSymbol(gridLevel, lineSymbol) and setTextSymbol(gridLevel, textSymbol) methods on the grid.
  3. The label position can be set with setLabelPosition(labelPosition) method on the grid.
    • Note that as of 200.6, MGRS, UTM, and USNG grids in a SceneView only support the Geographic label position.
  4. For the LatitudeLongitudeGrid type, you can specify a label format of DECIMAL_DEGREES or DEGREES_MINUTES_SECONDS.
  5. For all screen-aligned label placement strategies, you can set the labels’ offset in device-independent pixels (DIPs) from the screen edge with setLabelOffset(offset).
  6. To set the grid, use the setGrid(grid) method on the map view or scene view.

Relevant API

  • Grid
  • LatitudeLongitudeGrid
  • MapView
  • MGRSGrid
  • SceneView
  • SimpleLineSymbol
  • TextSymbol
  • USNGGrid
  • UTMGrid

Tags

coordinates, degrees, graticule, grid, latitude, longitude, MGRS, minutes, seconds, USNG, UTM

Sample Code

DisplayGrid.xaml DisplayGrid.xaml DisplayGrid.xaml.cs
<UserControl x:Class="ArcGIS.WinUI.Samples.DisplayGrid.DisplayGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
<UserControl.Resources>
<Style TargetType="ComboBox">
<Setter Property="Margin" Value="5" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style TargetType="Button">
<Setter Property="Margin" Value="0,5,5,0" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</UserControl.Resources>
<Grid>
<esriUI:MapView x:Name="MyMapView" />
<esriUI:SceneView x:Name="MySceneView" Visibility="Collapsed" />
<Border Width="450"
Margin="30"
Padding="20"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Background="White"
BorderBrush="Black"
BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<!-- TextBlocks -->
<TextBlock Grid.Row="0" Text="GeoView" />
<TextBlock Grid.Row="1" Text="Grid type" />
<TextBlock Grid.Row="2" Text="Show labels" />
<TextBlock Grid.Row="3" Text="Show grid" />
<TextBlock Grid.Row="4" Text="Grid color" />
<TextBlock Grid.Row="5" Text="Label color" />
<TextBlock Grid.Row="6" Text="Halo color" />
<TextBlock Grid.Row="7" Text="Label position" />
<TextBlock Grid.Row="8" Text="Label format" />
<TextBlock Grid.Row="9" Text="Label offset" />
<!-- Inputs -->
<StackPanel Grid.Row="0"
Grid.Column="1"
Orientation="Horizontal">
<RadioButton x:Name="mapViewRadioButton"
Content="MapView"
GroupName="GeoViewRadioButtons"
IsChecked="True" />
<RadioButton Content="SceneView" GroupName="GeoViewRadioButtons" />
</StackPanel>
<ComboBox x:Name="gridTypeCombo"
Grid.Row="1"
Grid.Column="1" />
<CheckBox x:Name="labelVisibilityCheckbox"
Grid.Row="2"
Grid.Column="1"
Margin="5,0,0,0"
IsChecked="True" />
<CheckBox x:Name="gridVisibilityCheckbox"
Grid.Row="3"
Grid.Column="1"
Margin="5,0,0,0"
IsChecked="True" />
<ComboBox x:Name="gridColorCombo"
Grid.Row="4"
Grid.Column="1" />
<ComboBox x:Name="labelColorCombo"
Grid.Row="5"
Grid.Column="1" />
<ComboBox x:Name="haloColorCombo"
Grid.Row="6"
Grid.Column="1" />
<ComboBox x:Name="labelPositionCombo"
Grid.Row="7"
Grid.Column="1" />
<ComboBox x:Name="labelFormatCombo"
Grid.Row="8"
Grid.Column="1" />
<Slider x:Name="labelOffsetSlider"
Grid.Row="9"
Grid.Column="1"
Maximum="150"
Minimum="0"
Value="40" />
<!-- Apply -->
<Button x:Name="applySettingsButton"
Grid.Row="10"
Grid.ColumnSpan="2"
Content="Apply settings"
IsEnabled="False" />
</Grid>
</Border>
</Grid>
</UserControl>