

Public Class DisplayUnitFormat Inherits ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase Implements System.ComponentModel.INotifyPropertyChanged
public class DisplayUnitFormat : ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase, System.ComponentModel.INotifyPropertyChanged
{
//var map = MapView.Active.Map;
//Note: Must be on the QueuedTask.Run()
//Get the current location unit
var loc_unit = map.GetLocationUnitFormat();
var line = $"{loc_unit.DisplayName}, {loc_unit.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);
}
{
//Linear location unit formats are not included if the map sr
//is geographic.
//Note: Must be on the QueuedTask.Run()
var loc_units = map.GetAvailableLocationUnitFormats();
}
{
//Get the current view camera location
var center_pt = new Coordinate2D(mapView.Camera.X, mapView.Camera.Y);
//Get the current location unit
//Note: Must be on the QueuedTask.Run()
var loc_unit = map.GetLocationUnitFormat();
//Format the camera location
var str = loc_unit.FormatLocation(center_pt, map.SpatialReference);
System.Diagnostics.Debug.WriteLine($"Formatted location: {str}");
}
{
//Get the list of available location unit formats
//for the current map
//Note: Must be on the QueuedTask.Run()
var loc_units = map.GetAvailableLocationUnitFormats();
//arbitrarily use the last unit in the list
map.SetLocationUnitFormat(loc_units.Last());
}
{
var elev_unit = map.GetElevationUnitFormat();
var line = $"{elev_unit.DisplayName}, {elev_unit.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);
}
{
//If the map is not a scene, the list of current
//Project distance units will be returned
//Note: Must be on the QueuedTask.Run()
var elev_units = map.GetAvailableElevationUnitFormats();
}
{
//Get the current elevation unit. If the map is not
//a scene the default Project distance unit is returned
//Note: Must be on the QueuedTask.Run()
var elev_unit = map.GetElevationUnitFormat();
//Format the view camera elevation
var str = elev_unit.FormatValue(mapView.Camera.Z);
System.Diagnostics.Debug.WriteLine($"Formatted elevation: {str}");
}
{
//Trying to set the elevation unit on a map other than
//a scene will throw an InvalidOperationException
if (map.IsScene)
{
//Get the list of available elevation unit formats
//for the current map
var loc_units = map.GetAvailableElevationUnitFormats();
//arbitrarily use the last unit in the list
//Note: Must be on the QueuedTask.Run()
map.SetElevationUnitFormat(loc_units.Last());
}
}
System.Object
ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
ArcGIS.Desktop.Core.UnitFormats.DisplayUnitFormat
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)