Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Display grid

This code sample is available for these platforms:
View Sample on GitHub

Display coordinate system grids including Latitude/Longitude, MGRS, UTM and USNG on a map view. Also, toggle label visibility and change the color of grid lines and grid labels.


Use case

Grids are often used on printed maps, but can also be helpful on digital maps, to identify locations on a map.

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.
  4. For the LatitudeLongitudeGrid type, you can specify a label format of DecimalDegrees or DEGREES_MINUTES_SECONDS.
  5. To set the grid, use the setGrid(grid) method on the map view.

Relevant API

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


MapViews SceneViews and UI, graticule

Sample Code

<?xml version="1.0" encoding="utf-8"?>

<ContentPage xmlns=""
            <Style TargetType="Picker">
                <Setter Property="VerticalOptions" Value="Center" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="2*" />
        <ScrollView Grid.Row="0">
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="2*" />
                <!-- Labels -->
                <Label Text="Grid type"
                       Grid.Row="0" />
                <Label Text="Show labels"
                       Grid.Row="1" />
                <Label Text="Show grid"
                       Grid.Row="2" />
                <Label Text="Grid color"
                       Grid.Row="3" />
                <Label Text="Label color"
                       Grid.Row="4" />
                <Label Text="Halo color"
                       Grid.Row="5" />
                <Label Text="Label position"
                       Grid.Row="6" />
                <Label Text="Label format"
                       Grid.Row="7" />
                <!-- Inputs -->
                <Picker x:Name="gridTypePicker"
                        Grid.Row="0" Grid.Column="1" />
                <Switch x:Name="labelVisibilitySwitch"
                        Grid.Row="1" Grid.Column="1" />
                <Switch x:Name="gridVisibilitySwitch"
                        Grid.Row="2" Grid.Column="1" />
                <Picker x:Name="gridColorPicker"
                        Grid.Row="3" Grid.Column="1" />
                <Picker x:Name="labelColorPicker"
                        Grid.Row="4" Grid.Column="1" />
                <Picker x:Name="haloColorPicker"
                        Grid.Row="5" Grid.Column="1" />
                <Picker x:Name="labelPositionPicker"
                        Grid.Row="6" Grid.Column="1" />
                <Picker x:Name="labelFormatPicker"
                        Grid.Row="7" Grid.Column="1" />
        <Button x:Name="applySettingsButton"
                Text="Apply settings"
                IsEnabled="False" />
        <esriUI:MapView x:Name="MyMapView"
                        Grid.Row="2" />
// Copyright 2018 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using System;
using Esri.ArcGISRuntime.Geometry;
using Xamarin.Forms;
using Colors = System.Drawing.Color;

namespace ArcGISRuntime.Samples.DisplayGrid
        "Display a grid",
        "This sample demonstrates how to display and work with coordinate grid systems such as Latitude/Longitude, MGRS, UTM and USNG on a map view. This includes toggling labels visibility, changing the color of the grid lines, and changing the color of the grid labels.",
        "Choose the grid settings and then tap 'Apply settings' to see them applied.")]
    public partial class DisplayGrid : ContentPage
        public DisplayGrid()

            // Create the UI, setup the control references and execute initialization

        private void Initialize()
            // Set up the map view with a basemap.
            MyMapView.Map = new Map(Basemap.CreateImageryWithLabels());

            // Configure the UI options.
            gridTypePicker.ItemsSource = new[] {"LatLong", "MGRS", "UTM", "USNG"};
            string[] colorItemsSource = {"Red", "Green", "Blue", "White", "Purple"};
            gridColorPicker.ItemsSource = colorItemsSource;
            labelColorPicker.ItemsSource = colorItemsSource;
            haloColorPicker.ItemsSource = colorItemsSource;
            labelPositionPicker.ItemsSource = Enum.GetNames(typeof(GridLabelPosition));
            labelFormatPicker.ItemsSource = Enum.GetNames(typeof(LatitudeLongitudeGridLabelFormat));
            foreach (Picker combo in new[]
                {gridTypePicker, gridColorPicker, labelColorPicker, labelPositionPicker, labelFormatPicker})
                combo.SelectedIndex = 0;

            // Update the halo color to have a good default.
            haloColorPicker.SelectedIndex = 3;

            // Handle grid type changes so that the format option can be disabled for non-latlong grids.
            gridTypePicker.SelectedIndexChanged += (o, e) =>
                labelFormatPicker.IsEnabled = gridTypePicker.SelectedItem.ToString() == "LatLong";

            // Subscribe to the button click event.
            applySettingsButton.Clicked += ApplySettingsButton_Clicked;

            // Enable the action button.
            applySettingsButton.IsEnabled = true;

            // Zoom to a default scale that will show the grid labels if they are enabled.
                new MapPoint(-7702852.905619, 6217972.345771, SpatialReferences.WebMercator), 23227);

            // Apply default settings.
            ApplySettingsButton_Clicked(this, null);

        private void ApplySettingsButton_Clicked(object sender, EventArgs e)
            Esri.ArcGISRuntime.UI.Grid grid;

            // First, update the grid based on the type selected.
            switch (gridTypePicker.SelectedItem.ToString())
                case "LatLong":
                    grid = new LatitudeLongitudeGrid();
                    // Apply the label format setting.
                    string selectedFormatString = labelFormatPicker.SelectedItem.ToString();
                    ((LatitudeLongitudeGrid) grid).LabelFormat =
                        (LatitudeLongitudeGridLabelFormat) Enum.Parse(typeof(LatitudeLongitudeGridLabelFormat),

                case "MGRS":
                    grid = new MgrsGrid();

                case "UTM":
                    grid = new UtmGrid();
                case "USNG":
                    grid = new UsngGrid();

            // Next, apply the label visibility setting.
            grid.IsLabelVisible = labelVisibilitySwitch.IsToggled;

            // Next, apply the grid visibility setting.
            grid.IsVisible = gridVisibilitySwitch.IsToggled;

            // Next, apply the grid color and label color settings for each zoom level.
            for (long level = 0; level < grid.LevelCount; level++)
                // Set the line symbol.
                Symbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid,
                    Colors.FromName(gridColorPicker.SelectedItem.ToString()), 2);
                grid.SetLineSymbol(level, lineSymbol);

                // Set the text symbol.
                Symbol textSymbol = new TextSymbol
                    Color = Colors.FromName(labelColorPicker.SelectedItem.ToString()),
                    OutlineColor = Colors.FromName(haloColorPicker.SelectedItem.ToString()),
                    Size = 16,
                    HaloColor = Colors.FromName(haloColorPicker.SelectedItem.ToString()),
                    HaloWidth = 3
                grid.SetTextSymbol(level, textSymbol);

            // Next, apply the label position setting.
            grid.LabelPosition =
                (GridLabelPosition) Enum.Parse(typeof(GridLabelPosition), labelPositionPicker.SelectedItem.ToString());

            // Apply the updated grid.
            MyMapView.Grid = grid;