private void DrawCoordinates(Graphics graphics) { if (_appState.Coordinates.Count == 0) { return; } Pen pen = new Pen(Color.Black, Convert.ToSingle(_resolution * 2)); pen.EndCap = System.Drawing.Drawing2D.LineCap.Flat; System.Drawing.Font font = AppSettings.CoordinatesFont; font = new System.Drawing.Font(font.FontFamily, Convert.ToSingle(font.Size * _resolution), font.Style, font.Unit); SolidBrush textBrush = new SolidBrush(Color.Black); SolidBrush shadowBrush = new SolidBrush(Color.White); Configuration config = AppContext.GetConfiguration(); Configuration.ApplicationRow application = config.Application.FindByApplicationID(_appState.Application); StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Far; string[] modes = application.IsCoordinateModesNull() ? new string[] { "ne" } : application.CoordinateModes.ToLower().Split(','); for (int i = 0; i < _appState.Coordinates.Count; ++i) { IPoint p = new NetTopologySuite.Geometries.Point(_appState.Coordinates[i]); if (_appState.CoordinateLabels[i] != "1") { DrawCross(graphics, p, pen, 10); DrawText(graphics, p, _appState.CoordinateLabels[i], font, textBrush, shadowBrush, 2, -3, format); } else { DrawCoordinate(graphics, p, modes, pen, font, textBrush, shadowBrush, format); } } }
private void DrawMarkup(Graphics graphics) { if (_appState.Markup.Count == 0 && _appState.MarkupGroups.Count == 0) { return; } List <Markup> markupList = new List <Markup>(); if (_appState.MarkupGroups.Count > 0) { using (OleDbConnection connection = AppContext.GetDatabaseConnection()) { foreach (string groupId in _appState.MarkupGroups) { string sql = String.Format("update {0}MarkupGroup set DateLastAccessed = ? where GroupID = {1}", AppSettings.ConfigurationTablePrefix, groupId); using (OleDbCommand command = new OleDbCommand(sql, connection)) { command.Parameters.Add("@1", OleDbType.Date).Value = DateTime.Now; command.ExecuteNonQuery(); } sql = String.Format("select Shape, Color, Glow, Text, Measured from {0}Markup where GroupID = {1} and Deleted = 0", AppSettings.ConfigurationTablePrefix, groupId); using (OleDbCommand command = new OleDbCommand(sql, connection)) { using (OleDbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Markup markup = new Markup(); markup.Shape = reader.GetString(0); markup.Color = reader.GetString(1); markup.Glow = !reader.IsDBNull(2) ? reader.GetString(2) : null; markup.Text = !reader.IsDBNull(3) ? reader.GetString(3) : null; markup.Measured = !reader.IsDBNull(4) ? (int?)reader.GetInt32(4) : null; markupList.Add(markup); } } } } } } if (_appState.Markup.Count > 0) { markupList.AddRange(_appState.Markup); } SolidBrush pointBrush = new SolidBrush(Color.Red); SolidBrush polygonBrush = new SolidBrush(Color.FromArgb(128, 255, 192, 192)); Pen pen = new Pen(Color.Red, Convert.ToSingle(2 * _resolution)); pen.EndCap = System.Drawing.Drawing2D.LineCap.Square; pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; float dotSize = Convert.ToSingle(10 * _resolution); System.Drawing.Font font = AppSettings.MarkupFont; font = new System.Drawing.Font(font.FontFamily, Convert.ToSingle(font.Size * _resolution), font.Style, font.Unit); System.Drawing.Font coordinatesFont = AppSettings.CoordinatesFont; coordinatesFont = new System.Drawing.Font(coordinatesFont.FontFamily, Convert.ToSingle(coordinatesFont.Size * _resolution), coordinatesFont.Style, coordinatesFont.Unit); SolidBrush textBrush = new SolidBrush(Color.FromArgb(192, 0, 0)); SolidBrush glowBrush = new SolidBrush(Color.Black); StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Far; Configuration config = AppContext.GetConfiguration(); Configuration.ApplicationRow application = config.Application.FindByApplicationID(_appState.Application); string[] modes = application.IsCoordinateModesNull() ? new string[] { "ne" } : application.CoordinateModes.ToLower().Split(','); WKTReader wktReader = new WKTReader(); foreach (Markup markup in markupList) { IGeometry geometry = wktReader.Read(markup.Shape); Color color = ColorTranslator.FromHtml(markup.Color); bool isMeasured = markup.Measured.HasValue && markup.Measured == 1; bool isGlow = !String.IsNullOrEmpty(markup.Glow); if (isGlow) { glowBrush.Color = ColorTranslator.FromHtml(markup.Glow); } switch (geometry.OgcGeometryType) { case OgcGeometryType.Point: bool isText = !String.IsNullOrEmpty(markup.Text); if (isText) { textBrush.Color = color; DrawText(graphics, (IPoint)geometry, markup.Text, font, textBrush, isGlow ? glowBrush : null, 0, 0, format); if (isMeasured) { pen.Color = color; pen.EndCap = System.Drawing.Drawing2D.LineCap.Flat; DrawCross(graphics, (IPoint)geometry, pen, 10); } } else { if (isMeasured) { pen.Color = color; pen.EndCap = System.Drawing.Drawing2D.LineCap.Flat; textBrush.Color = color; DrawCoordinate(graphics, (IPoint)geometry, modes, pen, coordinatesFont, textBrush, isGlow ? glowBrush : null, format); } else { pointBrush.Color = color; DrawPoint(graphics, (IPoint)geometry, pointBrush, dotSize); } } break; case OgcGeometryType.LineString: pen.Color = color; pen.EndCap = System.Drawing.Drawing2D.LineCap.Square; DrawLineString(graphics, (ILineString)geometry, pen); break; case OgcGeometryType.Polygon: pen.Color = color; pen.EndCap = System.Drawing.Drawing2D.LineCap.Square; polygonBrush.Color = Color.FromArgb(128, color); DrawPolygon(graphics, (IPolygon)geometry, polygonBrush, null, pen); break; } if (isMeasured && geometry.OgcGeometryType != OgcGeometryType.Point) { DrawMeasure(graphics, geometry); } } }