public static IGridOptionsEnvironment Instance {get;}
Public Shared ReadOnly Property Instance As IGridOptionsEnvironment
public static IGridOptionsEnvironment Instance {get;}
Public Shared ReadOnly Property Instance As IGridOptionsEnvironment
{
GridOptionsEnvironment.Instance.ShowGrid = !GridOptionsEnvironment.Instance.ShowGrid;
}
{
await QueuedTask.Run(() =>
{
var gridOptions = GridOptionsEnvironment.Instance.DefaultGridOptions;
});
}
{
var gridOptionsMapView = MapView.Active;
if (gridOptionsMapView == null)
return;
await QueuedTask.Run(() =>
{
//Does the 'map' currently have any options?
var hasOptions = GridOptionsEnvironment.Instance.HasGridOptions(map);
//If grid options have not been set for the map, then default grid options are added
//for the map otherwise the existing gridoptions are returned.
//NOTE: Grid options are returned by value meaning a copy is always returned. Any changes made to the
//grid options need to be -set- back on the map using SetGridOptions for the changes to persist.
var gridOptions = GridOptionsEnvironment.Instance.GetGridOptions(
gridOptionsMapView.Map);
//Only return grid options if grid options have previously been set:
var gridOptions2 = GridOptionsEnvironment.Instance.GetGridOptions(
gridOptionsMapView.Map, false);
});
}
{
//assume
//var map = MapView.Active.Map;
await QueuedTask.Run(() =>
{
//If grid options have not been set for the map, then default grid options are added
//for the map and returned otherwise the existing gridoptions are returned.
//NOTE: Grid options are by value meaning a copy is returned. Any changes made to the
//grid options need to be -set- back on the map using SetGridOptions for the changes to persist.
var gridOptions = GridOptionsEnvironment.Instance.GetGridOptions(map);
//change some properties
gridOptions.RotateWithMap = !gridOptions.RotateWithMap;
gridOptions.GridLineColor = ColorFactory.Instance.RedRGB;
gridOptions.GridLineColor = ColorFactory.Instance.BlueRGB;
//To apply changes, the gridoptions must be set back on the map
GridOptionsEnvironment.Instance.SetGridOptions(map, gridOptions);
});
}
{
//assume
//var map = MapView.Active.Map;
var center_pt = mapView.Extent.Center;
var width = mapView.Extent.Width;
var height = mapView.Extent.Height;
var qtr_width = width * 0.25;
var qtr_ht = height * 0.25;
await QueuedTask.Run(() =>
{
//If grid options have not been set for the map, then default grid options are added
//for the map and returned otherwise the existing gridoptions are returned.
//NOTE: Grid options are by value meaning a copy is returned. Any changes made to the
//grid options need to be -set- back on the map using SetGridOptions for the changes to persist.
var gridOptions = GridOptionsEnvironment.Instance.GetGridOptions(map);
//Set the grid origin
var x1 = center_pt.X + qtr_width;
var y1 = center_pt.Y + qtr_ht;
gridOptions.SetGridOrigin(new Coordinate2D(x1, y1));
//or use Coordinate3D
gridOptions.SetGridOrigin(new Coordinate3D(x1, y1, 0));
//To apply changes, the gridoptions must be set back on the map
GridOptionsEnvironment.Instance.SetGridOptions(map, gridOptions);
});
}
{
var center_pt = mapView.Extent.Center;
var width = mapView.Extent.Width;
var height = mapView.Extent.Height;
var qtr_width = width * 0.25;
var qtr_ht = height * 0.25;
await QueuedTask.Run(() =>
{
//use defaults
var gridOptions = GridOptionsEnvironment.Instance.DefaultGridOptions;
//customize the options as needed
gridOptions.RotateWithMap = !gridOptions.RotateWithMap;
gridOptions.GridLineColor = ColorFactory.Instance.RedRGB;
var gs_rotation = gridOptions.GetGridRotation();
gridOptions.SetGridRotation(gs_rotation * 1.5);
var gs_meters = gridOptions.GetGridSpacingMeters();
var gs_in_spacing_units = gridOptions.GetGridSpacing();
var gs_units = gridOptions.GridSpacingUnits;
//meters assumed
gridOptions.SetGridSpacingInMeters(gs_meters + 10);
//specify units explicitly
gridOptions.SetGridSpacing(1000, LinearUnit.Feet);//internally will be converted to meters
gridOptions.IsGridLines = true;//use lines (default)
var grid_interval = gridOptions.GridMajorInterval;
gridOptions.SnapToGridEnabled = true;
var x1 = center_pt.X - qtr_width;
var y1 = center_pt.Y + qtr_ht;
gridOptions.SetGridOrigin(new Coordinate2D(x1, y1));
//To apply changes, the gridoptions must be set back on the map
GridOptionsEnvironment.Instance.SetGridOptions(map, gridOptions);
});
}
{
await QueuedTask.Run(() =>
{
if (GridOptionsEnvironment.Instance.HasGridOptions(map))
{
//set back to defaults - will overwrite existing
GridOptionsEnvironment.Instance.SetGridOptions(map,
GridOptionsEnvironment.Instance.DefaultGridOptions);
}
});
}
{
await QueuedTask.Run(() =>
{
if (GridOptionsEnvironment.Instance.HasGridOptions(map))
{
GridOptionsEnvironment.Instance.RemoveGridOptions(map);
}
});
}
{
await QueuedTask.Run(() =>
{
GridOptionsEnvironment.Instance.ClearGridOptions();
});
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)