Skip to main content

How to: Format Coordinates Displayed in the Navigation Panel

  • 2 minutes to read

This example demonstrates how to change the text of map point coordinates displayed in the navigation panel using latitude and longitude format patterns.

To do this, specify a string that will represent the pattern displayed within a coordinate label in the map navigation panel using NavigationPanelOptions.XCoordinatePattern and NavigationPanelOptions.YCoordinatePattern properties.

In this example, you can format the values of map point coordinates using a predefined list of patterns from the combo box. In the combo box, you can also specify a custom pattern using standard specifiers together with placeholders. For example: “{CP}{D}°{M}’{S:2}’’ “, where CP – is a cardinal point; D – is a degree; M - is a minute; S – is a second. Note that the precision specifier (“2”) indicates the desired number of decimal places.

using DevExpress.XtraEditors;
using System;
using System.Windows.Forms;

namespace MapCoordinatePatterns {

    public partial class Form1 : Form {

        string[] patterns = new string[] {
            "{D:1}°{CP}",
            "{CP}{D:6}°",
            "{D}°{M:2}\'{CP}",
            "{CP}{D}°{M:2}\'",
            "{D}°{M}\'{S:4}\'\'{CP}",            
            "{CP}{D}°{M}\'{S:4}\'\'",
            "Coordinates: {D}°{M}\'{S:2}\'\'{CP}"
        };

        public Form1() {
            InitializeComponent();
            PopulateComboBox(cbXCoordinatePattern);
            PopulateComboBox(cbYCoordinatePattern);
        }

        private void PopulateComboBox(ComboBoxEdit comboBox) {
            comboBox.Properties.Items.AddRange(patterns);
            comboBox.EditValue = comboBox.Properties.Items[0];
        }
        private void OnXCoordinatePatternSelectedIndexChanged(object sender, EventArgs e) {
            map.NavigationPanelOptions.XCoordinatePattern = cbXCoordinatePattern.EditValue as String;
        }

        private void OnYCoordinatePatternSelectedIndexChanged(object sender, EventArgs e) {
            map.NavigationPanelOptions.YCoordinatePattern = cbYCoordinatePattern.EditValue as String;
        }
    }
}