/GPX.Firemap.Desktop/GPX.Firemap.Desktop.CustomLayers/GraticuleCustomLayers/GraticuleCustomLayers/CustomLayers/MGA94GraticuleCustomLayer.cs
https://bitbucket.org/shope/dfu · C# · 740 lines · 487 code · 90 blank · 163 comment · 66 complexity · bddc1424172e3589638b95538f6ff0c7 MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using ESRI.ArcGIS.ADF;
- using ESRI.ArcGIS.ArcMapUI;
- using ESRI.ArcGIS.Carto;
- using ESRI.ArcGIS.Display;
- using ESRI.ArcGIS.esriSystem;
- using ESRI.ArcGIS.Geometry;
- using ESRI.ArcGIS.Geodatabase;
-
- namespace GraticuleCustomLayers
- {
- /// <summary>
- ///
- /// </summary>
- [Guid("b4244d63-a4f0-4649-bd96-88238b63b0f3")]
- [ClassInterface(ClassInterfaceType.None)]
- [ProgId("GraticuleCustomLayers.MGA94GraticuleCustomLayer")]
- public class MGA94GraticuleCustomLayer : ILayer, IGeoDataset, IPersistVariant
- {
- #region Module Level Variables and Constants
-
- // The default densify value used when densifying lines prior to projecting a line
- private const int DensifySegmentCount = 50;
-
- // MGA Grid spacing
- private const int MGAGridSpacing = 1000;
-
- // MGA Grid max scale (the MGA grid will be shown below this scale)
- private const double MGAGridMaxScale = 101000;
-
- // MGA Grid label scale boundary (the MGA grid will have additional labels shown below this scale)
- private const double MGAGridLabelScaleBoundary = 50000.5;
-
- /// <summary>
- /// Name of the layer
- /// </summary>
- public static readonly string LayerName = "MGA94 Graticule";
-
- /// <summary>
- /// Indicates if the layer needs its own display cache.
- /// </summary>
- private bool m_isCached = false;
-
- /// <summary>
- /// Indicates if the layer is currently visible.
- /// </summary>
- private bool m_visible = true;
-
- /// <summary>
- /// Describes the area of interest of the layer.
- /// </summary>
- private IEnvelope m_areaOfInterest = SpatialReferenceStore.Instance.ExtentMGAZone55.Envelope;
-
- #endregion
-
- #region Constructors
-
- // None
-
- #endregion
-
- #region ILayer Members
-
- /// <summary>
- /// The default area of interest for the layer.
- /// </summary>
- public IEnvelope AreaOfInterest
- {
- get
- {
- return m_areaOfInterest;
- }
- }
-
- /// <summary>
- /// Indicates if the layer needs its own display cache.
- /// </summary>
- public bool Cached
- {
- get
- {
- return m_isCached;
- }
- set
- {
- m_isCached = value;
- }
- }
-
- /// <summary>
- /// Draws the layer to the specified display for the given draw phase.
- /// </summary>
- /// <param name="DrawPhase"></param>
- /// <param name="Display"></param>
- /// <param name="TrackCancel"></param>
- public void Draw(esriDrawPhase DrawPhase, IDisplay Display, ITrackCancel TrackCancel)
- {
- System.Diagnostics.Debug.WriteLine("GraticuleDrawEvent");
- using (ComReleaser comReleaser = new ComReleaser())
- {
- // Make sure we can proceed, if not exit
- if (!Valid || !Visible) { return; }
-
- // Get the display transformation and spatial reference
- IDisplayTransformation displayTranformation = Display.DisplayTransformation;
- ISpatialReference displaySpatialReference = displayTranformation.SpatialReference;
- comReleaser.ManageLifetime(displaySpatialReference);
- if (SpatialReferenceStore.IsUnknownSpatialReference(displaySpatialReference)) { return; }
-
- // Get the bounds of the map.
- IEnvelope mapBounds = displayTranformation.FittedBounds;
-
- // Check if we should be drawing anything at all based on scale
- if (displayTranformation.ScaleRatio > MGA94GraticuleCustomLayer.MGAGridMaxScale) { return; }
-
- // Get the list of lines and label points to be displayed (calculated in graticule coords, returned in display coords)
- List<GraticuleLine> graticuleLines54 = CalculateGraticuleLines(mapBounds, displaySpatialReference, SpatialReferenceStore.Instance.ExtentMGAZone54);
- List<GraticuleLine> graticuleLines55 = CalculateGraticuleLines(mapBounds, displaySpatialReference, SpatialReferenceStore.Instance.ExtentMGAZone55);
- List<GraticuleLine> graticuleLines56 = CalculateGraticuleLines(mapBounds, displaySpatialReference, SpatialReferenceStore.Instance.ExtentMGAZone56);
- List<GraticuleLine> graticuleLines = new List<GraticuleLine>();
- if (graticuleLines54 != null) { graticuleLines.AddRange(graticuleLines54); }
- if (graticuleLines55 != null) { graticuleLines.AddRange(graticuleLines55); }
- if (graticuleLines56 != null) { graticuleLines.AddRange(graticuleLines56); }
-
- // Make sure we have something to draw
- if (graticuleLines.Count == 0) { return; }
-
- // Draw the lines
- Display.SetSymbol((ISymbol)GraticuleGraphics.MGA94GraticuleLineSymbol);
- foreach (GraticuleLine graticuleLine in graticuleLines)
- {
- Display.DrawPolyline((IGeometry)graticuleLine.Line);
- }
-
- // Hold some x values to help with label collision calculations
- double topBoundsCheck = 0;
- double bottomBoundsCheck = 0;
- int topCount = 0;
- int bottomCount = 0;
- int leftCount = 0;
- int rightCount = 0;
-
- // Draw the labels
- ITextSymbol textSymbol = GraticuleGraphics.MGA94GraticuleTextSymbol;
- foreach (GraticuleLine graticuleLine in graticuleLines)
- {
- foreach (GraticuleLabelPoint graticuleLabelPoint in graticuleLine.LabelPoints)
- {
- // Set the properties of the text symbol based on the properties of the label point
- textSymbol.HorizontalAlignment = graticuleLabelPoint.HorizontalAlignment;
- textSymbol.VerticalAlignment = graticuleLabelPoint.VerticalAlignment;
- textSymbol.Text = graticuleLabelPoint.Text;
-
- // Work out the extent of the label to be drawn
- IEnvelope boundsEnv = new EnvelopeClass();
- comReleaser.ManageLifetime(boundsEnv);
- ((IQueryGeometry)textSymbol).QueryEnvelope(Display.hDC, (ITransformation)displayTranformation, (IGeometry)graticuleLabelPoint.AnchorPoint, boundsEnv);
-
- // Do some calcs to make sure we only draw lables that not too close to the corners of the display.
- bool draw = false;
- if (textSymbol.VerticalAlignment == esriTextVerticalAlignment.esriTVATop) // Top labels
- {
- if (boundsEnv.XMin > (mapBounds.XMin + (boundsEnv.Width / 2D)) && boundsEnv.XMax < (mapBounds.XMax - (boundsEnv.Width / 2D)) && boundsEnv.XMin > topBoundsCheck)
- {
- if (displayTranformation.ScaleRatio > MGA94GraticuleCustomLayer.MGAGridLabelScaleBoundary)
- {
- topCount += 1;
- if (IsOdd(topCount))
- {
- topBoundsCheck = boundsEnv.XMax;
- draw = true;
- }
- }
- else
- {
- topBoundsCheck = boundsEnv.XMax;
- draw = true;
- }
- }
- }
- else if (textSymbol.VerticalAlignment == esriTextVerticalAlignment.esriTVABottom) // Bottom labels
- {
- if (boundsEnv.XMin > (mapBounds.XMin + (boundsEnv.Width / 2D)) && boundsEnv.XMax < (mapBounds.XMax - (boundsEnv.Width / 2D)) && boundsEnv.XMin > bottomBoundsCheck)
- {
- if (displayTranformation.ScaleRatio > MGA94GraticuleCustomLayer.MGAGridLabelScaleBoundary)
- {
- bottomCount += 1;
- if (IsOdd(bottomCount))
- {
- bottomBoundsCheck = boundsEnv.XMax;
- draw = true;
- }
- }
- else
- {
- bottomBoundsCheck = boundsEnv.XMax;
- draw = true;
- }
- }
- }
- else if (textSymbol.HorizontalAlignment == esriTextHorizontalAlignment.esriTHALeft) // Left labels
- {
- if ((mapBounds.YMax - boundsEnv.YMax) > boundsEnv.Height &&
- (boundsEnv.YMin - mapBounds.YMin) > boundsEnv.Height)
- {
- if (displayTranformation.ScaleRatio > MGA94GraticuleCustomLayer.MGAGridLabelScaleBoundary)
- {
- leftCount += 1;
- if (IsOdd(leftCount))
- {
- draw = true;
- }
- }
- else
- {
- draw = true;
- }
- }
- }
- else // Right labels
- {
- if ((mapBounds.YMax - boundsEnv.YMax) > boundsEnv.Height &&
- (boundsEnv.YMin - mapBounds.YMin) > boundsEnv.Height)
- {
- if (displayTranformation.ScaleRatio > MGA94GraticuleCustomLayer.MGAGridLabelScaleBoundary)
- {
- rightCount += 1;
- if (IsOdd(rightCount))
- {
- draw = true;
- }
- }
- else
- {
- draw = true;
- }
- }
- }
-
- // If the label is to be drawn, the draw it
- if (draw)
- {
- Display.SetSymbol((ISymbol)textSymbol);
- Display.DrawText((IGeometry)graticuleLabelPoint.AnchorPoint, graticuleLabelPoint.Text);
- }
- ComReleaser.ReleaseCOMObject(graticuleLabelPoint.AnchorPoint);
- }
- ComReleaser.ReleaseCOMObject(graticuleLine.Line);
- }
- }
- }
-
- /// <summary>
- /// Maximum scale (representative fraction) at which the layer will display.
- /// </summary>
- public double MaximumScale
- {
- get
- {
- return default(double);
- }
- set
- {
- // Setting MaximumScale does nothing
- }
- }
-
- /// <summary>
- /// Minimum scale (representative fraction) at which the layer will display.
- /// </summary>
- public double MinimumScale
- {
- get
- {
- return default(double);
- }
- set
- {
- // Setting MinimumScale does nothing
- }
- }
-
- /// <summary>
- /// Layer name.
- /// </summary>
- public string Name
- {
- get
- {
- return LayerName;
- }
- set
- {
- // Setting Name does nothing
- }
- }
-
- /// <summary>
- /// Indicates if the layer shows map tips.
- /// </summary>
- public bool ShowTips
- {
- get
- {
- return default(bool);
- }
- set
- {
- // Setting ShowTips does nothing
- }
- }
-
- /// <summary>
- /// Spatial reference for the layer.
- /// </summary>
- public ISpatialReference SpatialReference
- {
- set
- {
- // Setting SpatialReference does nothing
- }
- }
-
- /// <summary>
- /// Supported draw phases.
- /// </summary>
- public int SupportedDrawPhases
- {
- get
- {
- return (int)esriDrawPhase.esriDPGeography;
- }
- }
-
- /// <summary>
- /// Indicates if the layer is currently valid.
- /// </summary>
- public bool Valid
- {
- get
- {
- return true;
- }
- }
-
- /// <summary>
- /// Indicates if the layer is currently visible.
- /// </summary>
- public bool Visible
- {
- get
- {
- return m_visible;
- }
- set
- {
- m_visible = value;
- }
- }
-
- /// <summary>
- /// Get_s the tip text.
- /// </summary>
- /// <param name="x">The x.</param>
- /// <param name="y">The y.</param>
- /// <param name="Tolerance">The tolerance.</param>
- public string get_TipText(double x, double y, double Tolerance)
- {
- return default(string);
- }
-
- #endregion
-
- #region IGeoDataset Members
-
- IEnvelope IGeoDataset.Extent
- {
- get { return m_areaOfInterest; }
- }
-
- ISpatialReference IGeoDataset.SpatialReference
- {
- get { return m_areaOfInterest.SpatialReference; }
- }
-
- #endregion
-
- #region IPersistVariant Members
-
- public ESRI.ArcGIS.esriSystem.UID ID
- {
- get
- {
- UID typeID = new UIDClass();
- typeID.Value = GetType().GUID.ToString("B");
- return typeID;
- }
- }
-
- public void Load(ESRI.ArcGIS.esriSystem.IVariantStream Stream)
- {
- // TODO: Add ArcGISClass1.Load implementation
- }
-
- public void Save(ESRI.ArcGIS.esriSystem.IVariantStream Stream)
- {
- // TODO: Add ArcGISClass1.Save implementation
- }
-
- #endregion
-
- #region Static Helper Methods
-
- /// <summary>
- /// Calculates the graticule lines.
- /// </summary>
- /// <param name="displayBounds">The display bounds.</param>
- /// <param name="displaySpatialReference">The display spatial reference.</param>
- /// <param name="mgaZoneExtent">The mga zone extent.</param>
- /// <returns>
- /// A list of GraticuleLine DTOs
- /// </returns>
- private static List<GraticuleLine> CalculateGraticuleLines(IEnvelope displayBounds, ISpatialReference displaySpatialReference, IPolygon mgaZoneExtent)
- {
- using (ComReleaser comReleaser = new ComReleaser())
- {
- // Turn the display bounds in a polygon, densify it and project it to same spatial reference as the mga zone we are dealing with
- IPolygon displayBoundsPolyMga = new PolygonClass();
- comReleaser.ManageLifetime(displayBoundsPolyMga);
- ((IPointCollection)displayBoundsPolyMga).AddPoint(displayBounds.UpperLeft);
- ((IPointCollection)displayBoundsPolyMga).AddPoint(displayBounds.UpperRight);
- ((IPointCollection)displayBoundsPolyMga).AddPoint(displayBounds.LowerRight);
- ((IPointCollection)displayBoundsPolyMga).AddPoint(displayBounds.LowerLeft);
- displayBoundsPolyMga.Close();
- displayBoundsPolyMga.SpatialReference = displayBounds.SpatialReference;
- ((IPolycurve)displayBoundsPolyMga).Densify(displayBoundsPolyMga.Length / Convert.ToDouble(MGA94GraticuleCustomLayer.DensifySegmentCount), 0);
- displayBoundsPolyMga = (IPolygon)ProjectionMethods.Project(displayBoundsPolyMga, mgaZoneExtent.SpatialReference);
-
- // Determine the extent that is common between the zone extent and the display bounds
- IPolygon graticuleBoundsPolyMga = (IPolygon)((ITopologicalOperator)mgaZoneExtent).Intersect(displayBoundsPolyMga, esriGeometryDimension.esriGeometry2Dimension);
- comReleaser.ManageLifetime(graticuleBoundsPolyMga);
-
- // Make sure we have at least some common area
- if (graticuleBoundsPolyMga.IsEmpty) { return null; }
-
- // Make an envelope that covers the graticule polygon extent
- IEnvelope graticuleBoundsMga = graticuleBoundsPolyMga.Envelope;
- comReleaser.ManageLifetime(graticuleBoundsMga);
- graticuleBoundsMga.Expand(1.25, 1.25, true);
-
- // Work out how many vertical and horizontal grid lines are going to have
-
- // Make an envelope slightly smaller than the display bounds to use for calculating labels
- IEnvelope displayBoundsReduced = (IEnvelope)((IClone)displayBounds).Clone();
- comReleaser.ManageLifetime(displayBoundsReduced);
- displayBoundsReduced.Expand(0.9975, 0.9975, true);
-
- // Get the edges of the reduced display bounds in display coordinates
- object missing = Type.Missing;
- IPointCollection displayBoundsTopEdge = new PolylineClass();
- comReleaser.ManageLifetime(displayBoundsTopEdge);
- ((IPolyline)displayBoundsTopEdge).SpatialReference = displaySpatialReference;
- displayBoundsTopEdge.AddPoint(displayBoundsReduced.UpperLeft, ref missing, ref missing);
- displayBoundsTopEdge.AddPoint(displayBoundsReduced.UpperRight, ref missing, ref missing);
- IPointCollection displayBoundsBottomEdge = new PolylineClass();
- comReleaser.ManageLifetime(displayBoundsBottomEdge);
- ((IPolyline)displayBoundsBottomEdge).SpatialReference = displaySpatialReference;
- displayBoundsBottomEdge.AddPoint(displayBoundsReduced.LowerLeft, ref missing, ref missing);
- displayBoundsBottomEdge.AddPoint(displayBoundsReduced.LowerRight, ref missing, ref missing);
- IPointCollection displayBoundsLeftEdge = new PolylineClass();
- comReleaser.ManageLifetime(displayBoundsLeftEdge);
- ((IPolyline)displayBoundsLeftEdge).SpatialReference = displaySpatialReference;
- displayBoundsLeftEdge.AddPoint(displayBoundsReduced.LowerLeft, ref missing, ref missing);
- displayBoundsLeftEdge.AddPoint(displayBoundsReduced.UpperLeft, ref missing, ref missing);
- IPointCollection displayBoundsRightEdge = new PolylineClass();
- comReleaser.ManageLifetime(displayBoundsRightEdge);
- ((IPolyline)displayBoundsRightEdge).SpatialReference = displaySpatialReference;
- displayBoundsRightEdge.AddPoint(displayBoundsReduced.LowerRight, ref missing, ref missing);
- displayBoundsRightEdge.AddPoint(displayBoundsReduced.UpperRight, ref missing, ref missing);
-
- // Calc the starting cooordinates to build the grid lines
- int remainder = 0;
- int eastingLeft = Math.DivRem(Convert.ToInt32(graticuleBoundsMga.XMin), MGA94GraticuleCustomLayer.MGAGridSpacing, out remainder) * MGA94GraticuleCustomLayer.MGAGridSpacing;
- int northingBottom = Math.DivRem(Convert.ToInt32(graticuleBoundsMga.YMin), MGA94GraticuleCustomLayer.MGAGridSpacing, out remainder) * MGA94GraticuleCustomLayer.MGAGridSpacing;
-
- // Create the graticule lines (extend to expanded bounds), project back to the display coordinates and calculate label points
- List<GraticuleLine> graticuleLines = new List<GraticuleLine>();
- for (int i = eastingLeft; i <= graticuleBoundsMga.XMax; i += MGA94GraticuleCustomLayer.MGAGridSpacing)
- {
- IPoint lineStart = new PointClass();
- comReleaser.ManageLifetime(lineStart);
- IPoint lineEnd = new PointClass();
- comReleaser.ManageLifetime(lineEnd);
- lineStart.PutCoords(i, graticuleBoundsMga.YMin);
- lineEnd.PutCoords(i, graticuleBoundsMga.YMax);
- IPolyline verticalLineFull = new PolylineClass();
- comReleaser.ManageLifetime(verticalLineFull);
- verticalLineFull.SpatialReference = mgaZoneExtent.SpatialReference;
- verticalLineFull.FromPoint = lineStart;
- verticalLineFull.ToPoint = lineEnd;
- IPolyline verticalLine = (IPolyline)((ITopologicalOperator)verticalLineFull).Intersect((IGeometry)graticuleBoundsPolyMga, esriGeometryDimension.esriGeometry1Dimension);
- if (verticalLine != null && verticalLine.IsEmpty == false)
- {
- ((IPolycurve)verticalLine).Densify(verticalLine.Length / Convert.ToDouble(MGA94GraticuleCustomLayer.DensifySegmentCount), 0);
- verticalLine = (IPolyline)ProjectionMethods.Project((IGeometry)verticalLine, displaySpatialReference);
-
- // Intersect the lines with the display bounds (top and bottom)
- List<GraticuleLabelPoint> graticuleLabelPoints = new List<GraticuleLabelPoint>();
- IGeometry topLabelPoint = ((ITopologicalOperator)verticalLine).Intersect((IGeometry)displayBoundsTopEdge, esriGeometryDimension.esriGeometry0Dimension);
- if ((topLabelPoint as IMultipoint) != null && ((IPointCollection)topLabelPoint).PointCount == 1)
- {
- graticuleLabelPoints.Add(new GraticuleLabelPoint(((IPointCollection)topLabelPoint).get_Point(0),
- esriTextHorizontalAlignment.esriTHACenter, esriTextVerticalAlignment.esriTVATop, "<FNT scale='80'>" + mgaPrefix(i, MGA94GraticuleCustomLayer.MGAGridSpacing) + "</FNT>" + "<FNT scale='60'> </FNT>" + mgaSuffix(i, MGA94GraticuleCustomLayer.MGAGridSpacing) +
- System.Environment.NewLine + "<FNT scale='80'>" + "z" + mgaZoneExtent.SpatialReference.Name.Substring(mgaZoneExtent.SpatialReference.Name.IndexOf("_Zone_") + 6, 2) + "</FNT>"));
- }
- IGeometry bottomLabelPoint = ((ITopologicalOperator)verticalLine).Intersect((IGeometry)displayBoundsBottomEdge, esriGeometryDimension.esriGeometry0Dimension);
- if ((bottomLabelPoint as IMultipoint) != null && ((IPointCollection)bottomLabelPoint).PointCount == 1)
- {
- graticuleLabelPoints.Add(new GraticuleLabelPoint(((IPointCollection)bottomLabelPoint).get_Point(0),
- esriTextHorizontalAlignment.esriTHACenter, esriTextVerticalAlignment.esriTVABottom, "<FNT scale='80'>" + mgaPrefix(i, MGA94GraticuleCustomLayer.MGAGridSpacing) + "</FNT>" + "<FNT scale='60'> </FNT>" + mgaSuffix(i, MGA94GraticuleCustomLayer.MGAGridSpacing)));
- }
- graticuleLines.Add(new GraticuleLine(verticalLine, graticuleLabelPoints));
- }
- }
- for (int i = northingBottom; i <= graticuleBoundsMga.YMax; i += MGA94GraticuleCustomLayer.MGAGridSpacing)
- {
- IPoint lineStart = new PointClass();
- comReleaser.ManageLifetime(lineStart);
- IPoint lineEnd = new PointClass();
- comReleaser.ManageLifetime(lineEnd);
- lineStart.PutCoords(graticuleBoundsMga.XMin, i);
- lineEnd.PutCoords(graticuleBoundsMga.XMax, i);
- IPolyline horizontalLineFull = new PolylineClass();
- comReleaser.ManageLifetime(horizontalLineFull);
- horizontalLineFull.SpatialReference = mgaZoneExtent.SpatialReference;
- horizontalLineFull.FromPoint = lineStart;
- horizontalLineFull.ToPoint = lineEnd;
- IPolyline horizontalLine = (IPolyline)((ITopologicalOperator)horizontalLineFull).Intersect((IGeometry)graticuleBoundsPolyMga, esriGeometryDimension.esriGeometry1Dimension);
- if (horizontalLine != null && horizontalLine.IsEmpty == false)
- {
- ((IPolycurve)horizontalLine).Densify(horizontalLine.Length / Convert.ToDouble(MGA94GraticuleCustomLayer.DensifySegmentCount), 0);
- horizontalLine = (IPolyline)ProjectionMethods.Project((IGeometry)horizontalLine, displaySpatialReference);
-
- // Intersect the lines with the display bounds (top and bottom)
- List<GraticuleLabelPoint> graticuleLabelPoints = new List<GraticuleLabelPoint>();
- IGeometry leftLabelPoint = ((ITopologicalOperator)horizontalLine).Intersect((IGeometry)displayBoundsLeftEdge, esriGeometryDimension.esriGeometry0Dimension);
- if ((leftLabelPoint as IMultipoint) != null && ((IPointCollection)leftLabelPoint).PointCount == 1)
- {
- graticuleLabelPoints.Add(new GraticuleLabelPoint(((IPointCollection)leftLabelPoint).get_Point(0),
- esriTextHorizontalAlignment.esriTHALeft, esriTextVerticalAlignment.esriTVACenter, "<FNT scale='80'>" + mgaPrefix(i, MGA94GraticuleCustomLayer.MGAGridSpacing) + "</FNT>" + "<FNT scale='60'> </FNT>" + mgaSuffix(i, MGA94GraticuleCustomLayer.MGAGridSpacing)));
- }
- IGeometry rightLabelPoint = ((ITopologicalOperator)horizontalLine).Intersect((IGeometry)displayBoundsRightEdge, esriGeometryDimension.esriGeometry0Dimension);
- if ((rightLabelPoint as IMultipoint) != null && ((IPointCollection)rightLabelPoint).PointCount == 1)
- {
- graticuleLabelPoints.Add(new GraticuleLabelPoint(((IPointCollection)rightLabelPoint).get_Point(0),
- esriTextHorizontalAlignment.esriTHARight, esriTextVerticalAlignment.esriTVACenter, "<FNT scale='80'>" + mgaPrefix(i, MGA94GraticuleCustomLayer.MGAGridSpacing) + "</FNT>" + "<FNT scale='60'> </FNT>" + mgaSuffix(i, MGA94GraticuleCustomLayer.MGAGridSpacing)));
- }
- graticuleLines.Add(new GraticuleLine(horizontalLine, graticuleLabelPoints));
- }
- }
- return graticuleLines;
- }
- }
-
- /// <summary>
- /// Calculates the mag prefix for a label based on grid spacing.
- /// </summary>
- /// <param name="mgaValue">The mga value.</param>
- /// <param name="gridSpacing">The grid spacing.</param>
- /// <returns>The prefix string.</returns>
- private static string mgaPrefix(int mgaValue, int gridSpacing)
- {
- int result;
- string wholeValue = Math.DivRem(mgaValue, gridSpacing, out result).ToString();
- return wholeValue.Substring(0, (wholeValue.Length - 2));
- }
-
- /// <summary>
- /// Calculates the mag suffix for a label based on grid spacing.
- /// </summary>
- /// <param name="mgaValue">The mga value.</param>
- /// <param name="gridSpacing">The grid spacing.</param>
- /// <returns>The prefix string.</returns>
- private static string mgaSuffix(int mgaValue, int gridSpacing)
- {
- int result;
- string wholeValue = Math.DivRem(mgaValue, gridSpacing, out result).ToString();
- return wholeValue.Substring((wholeValue.Length - 2), 2);
- }
-
- /// <summary>
- /// Determines whether the specified int value is odd.
- /// </summary>
- /// <param name="intValue">The int value.</param>
- /// <returns>
- /// <c>true</c> if the specified int value is odd; otherwise, <c>false</c>.
- /// </returns>
- public static bool IsOdd(int intValue)
- {
- return ((intValue & 1) == 1);
- }
-
- #endregion
-
- #region Data Transfer Objects
-
- /// <summary>
- /// Class to hold details of a graticule line
- /// </summary>
- private class GraticuleLine
- {
- #region Module Level Variables
-
- private IPolyline _line;
-
- private List<GraticuleLabelPoint> _labelPoints;
-
- #endregion
-
- #region Constructors
-
- /// <summary>
- /// Initializes a new instance of the <see cref="GraticuleLine"/> class.
- /// </summary>
- /// <param name="line">The line.</param>
- /// <param name="labelPoints">The label points.</param>
- public GraticuleLine(IPolyline line, List<GraticuleLabelPoint> labelPoints)
- {
- _line = line;
- _labelPoints = labelPoints;
- }
-
- #endregion
-
- #region Properties
-
- /// <summary>
- /// Gets the line.
- /// </summary>
- /// <value>The line.</value>
- public IPolyline Line
- {
- get { return _line; }
- }
-
- /// <summary>
- /// Gets the label points.
- /// </summary>
- /// <value>The label points.</value>
- public List<GraticuleLabelPoint> LabelPoints
- {
- get { return _labelPoints; }
- }
-
- #endregion
- }
-
- /// <summary>
- /// Class to hold details of a graticule label point
- /// </summary>
- private class GraticuleLabelPoint
- {
- #region Module Level Variables
-
- private IPoint _anchorPoint;
-
- private esriTextHorizontalAlignment _horizontalAlignment;
-
- private esriTextVerticalAlignment _verticalAlignment;
-
- private string _text;
-
- #endregion
-
- #region Constructors
-
- /// <summary>
- /// Initializes a new instance of the <see cref="GraticuleLabelPoint"/> class.
- /// </summary>
- /// <param name="anchorPoint">The anchor point.</param>
- /// <param name="horizontalAlignment">The horizontal alignment.</param>
- /// <param name="verticalAlignment">The vertical alignment.</param>
- /// <param name="text">The text.</param>
- public GraticuleLabelPoint(IPoint anchorPoint, esriTextHorizontalAlignment horizontalAlignment,
- esriTextVerticalAlignment verticalAlignment, string text)
- {
- _anchorPoint = anchorPoint;
- _horizontalAlignment = horizontalAlignment;
- _verticalAlignment = verticalAlignment;
- _text = text;
- }
-
- #endregion
-
- #region Properties
-
- /// <summary>
- /// Gets the anchor point.
- /// </summary>
- /// <value>The anchor point.</value>
- public IPoint AnchorPoint
- {
- get { return _anchorPoint; }
- }
-
- /// <summary>
- /// Gets the horizontal alignment.
- /// </summary>
- /// <value>The horizontal alignment.</value>
- public esriTextHorizontalAlignment HorizontalAlignment
- {
- get { return _horizontalAlignment; }
- }
-
- /// <summary>
- /// Gets the vertical alignment.
- /// </summary>
- /// <value>The vertical alignment.</value>
- public esriTextVerticalAlignment VerticalAlignment
- {
- get { return _verticalAlignment; }
- }
-
- /// <summary>
- /// Gets the text.
- /// </summary>
- /// <value>The text.</value>
- public string Text
- {
- get { return _text; }
- }
-
- #endregion
- }
- #endregion
- }
- }