![](dotnetdiagramimages/image1000.png)
public class DisplayUnitFormat : ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase, System.ComponentModel.INotifyPropertyChanged
Public Class DisplayUnitFormat Inherits ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase Implements System.ComponentModel.INotifyPropertyChanged
//var map = MapView.Active.Map; //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);
//var map = MapView.Active.Map; //Must be on the QueuedTask.Run() //Linear location unit formats are not included if the map sr //is geographic. var loc_units = map.GetAvailableLocationUnitFormats();
var mv = MapView.Active; var map = mv.Map; QueuedTask.Run(() => { //Get the current view camera location var center_pt = new Coordinate2D(mv.Camera.X, mv.Camera.Y); //Get the current location unit 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}"); });
var mv = MapView.Active; var map = mv.Map; QueuedTask.Run(() => { //Get the list of available location unit formats //for the current map var loc_units = map.GetAvailableLocationUnitFormats(); //arbitrarily use the last unit in the list map.SetLocationUnitFormat(loc_units.Last()); });
//var map = MapView.Active.Map; //Must be on the QueuedTask.Run() //If the map is not a scene, the default Project distance //unit will be returned var elev_unit = map.GetElevationUnitFormat(); var line = $"{elev_unit.DisplayName}, {elev_unit.UnitCode}"; System.Diagnostics.Debug.WriteLine(line);
//var map = MapView.Active.Map; //Must be on the QueuedTask.Run() //If the map is not a scene, the list of current //Project distance units will be returned var elev_units = map.GetAvailableElevationUnitFormats();
var mv = MapView.Active; var map = mv.Map; QueuedTask.Run(() => { //Get the current elevation unit. If the map is not //a scene the default Project distance unit is returned var elev_unit = map.GetElevationUnitFormat(); //Format the view camera elevation var str = elev_unit.FormatValue(mv.Camera.Z); System.Diagnostics.Debug.WriteLine($"Formatted elevation: {str}"); });
var map = MapView.Active.Map; QueuedTask.Run(() => { //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 map.SetElevationUnitFormat(loc_units.Last()); } });
System.Object
ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
ArcGIS.Desktop.Core.UnitFormats.DisplayUnitFormat
Target Platforms: Windows 11, Windows 10, Windows 8.1