private static RectangleD GetFrame(double zoomValue, Session sessionToDraw, IList<int> legsToDraw, double frameWidth, WaypointAttribute colorCodingAttribute, RouteDrawingMode mode) { var vertices = sessionToDraw.GetAdjustedWaypointLocations(legsToDraw); var rls = sessionToDraw.Settings.RouteLineSettingsCollection[colorCodingAttribute]; double lineRadius = 0; switch(mode) { case RouteDrawingMode.Simple: lineRadius = rls.MonochromeWidth/2; break; case RouteDrawingMode.Extended: lineRadius = (rls.Width + (rls.MaskVisible ? 2 * rls.MaskWidth : 0)) / 2; break; case RouteDrawingMode.None: lineRadius = 0; break; } double minX = zoomValue * (vertices[0].X - lineRadius); double maxX = zoomValue * (vertices[0].X + lineRadius); double minY = zoomValue * (vertices[0].Y - lineRadius); double maxY = zoomValue * (vertices[0].Y + lineRadius); for (int i = 0; i < vertices.Count; i++) { minX = Math.Min(minX, zoomValue * (vertices[i].X - lineRadius)); maxX = Math.Max(maxX, zoomValue * (vertices[i].X + lineRadius)); minY = Math.Min(minY, zoomValue * (vertices[i].Y - lineRadius)); maxY = Math.Max(maxY, zoomValue * (vertices[i].Y + lineRadius)); } double maxWidth = Math.Max(maxX - minX, maxY - minY); return new RectangleD(new PointD(minX - frameWidth * maxWidth, minY - frameWidth * maxWidth), new SizeD(maxX - minX + 2 * frameWidth * maxWidth, maxY - minY + 2 * frameWidth * maxWidth)); }
// todo: skip showRouteLine parameter, use RouteDrawingMode instead public Bitmap CreateMapAndRouteImage(bool showRouteLine, double zoomValue, Session sessionToDraw, List<int> legsToDraw, double frameWidth, WaypointAttribute colorCodingAttribute, WaypointAttribute? secondaryColorCodingAttribute, RouteDrawingMode mode, SessionSettings sessionSettings) { RectangleD frame = GetFrame(zoomValue, sessionToDraw, legsToDraw, frameWidth, colorCodingAttribute, mode); var sc = new SessionCollection(); sc.Add(sessionToDraw); var wholeImage = CreateMapAndRouteImage(true, zoomValue, sc, colorCodingAttribute, secondaryColorCodingAttribute, mode, sessionSettings); AdjustFrameToImage(frame, wholeImage); var croppedImage = new Bitmap( Convert.ToInt32(Math.Ceiling(frame.Right) - Math.Floor(frame.Left)), Convert.ToInt32(Math.Ceiling(frame.Bottom) - Math.Floor(frame.Top))); var croppedImageGraphics = Graphics.FromImage(croppedImage); croppedImageGraphics.DrawImage( wholeImage, -Convert.ToInt32(Math.Floor(frame.Left)), -Convert.ToInt32(Math.Floor(frame.Top))); croppedImageGraphics.Dispose(); wholeImage.Dispose(); return croppedImage; }
public void DrawRoutes(IEnumerable<Session> sessionsToDraw, double zoom, Graphics graphics, Image mapImage, RouteDrawingMode mode, WaypointAttribute colorCodingAttribute, WaypointAttribute? secondaryColorCodingAttribute, SessionSettings sessionSettings) { graphics.Clip = new Region(new Rectangle(0, 0, mapImage.Width, mapImage.Height)); // copy map as a background to route graphics.DrawImage(mapImage, new Point(0, 0)); // draw the routes foreach (var s in sessionsToDraw) { s.DrawRoute(zoom, graphics, mode, colorCodingAttribute, secondaryColorCodingAttribute, sessionSettings); } }
public Bitmap CreateMapAndRouteImage(bool showMap, double zoomValue, SessionCollection sessionsToDraw, WaypointAttribute colorCodingAttribute, WaypointAttribute? secondaryColorCodingAttribute, RouteDrawingMode mode, SessionSettings sessionSettings) { Bitmap mapImage; if(showMap) { mapImage = CreateMapImage(zoomValue); } else { var size = GetMapImageSize(zoomValue); mapImage = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppPArgb); } if (mode == RouteDrawingMode.None) return mapImage; var mapAndRouteImage = new Bitmap(mapImage.Width, mapImage.Height, PixelFormat.Format32bppPArgb); var mapAndRouteGraphics = Graphics.FromImage(mapAndRouteImage); mapAndRouteGraphics.SmoothingMode = SmoothingMode.AntiAlias; DrawRoutes(sessionsToDraw, zoomValue, mapAndRouteGraphics, mapImage, mode, colorCodingAttribute, secondaryColorCodingAttribute, sessionSettings); mapAndRouteGraphics.Dispose(); mapImage.Dispose(); return mapAndRouteImage; }
private static RectangleD GetFrame(double zoomValue, Session sessionToDraw, IList <int> legsToDraw, double frameWidth, WaypointAttribute colorCodingAttribute, RouteDrawingMode mode) { var vertices = sessionToDraw.GetAdjustedWaypointLocations(legsToDraw); var rls = sessionToDraw.Settings.RouteLineSettingsCollection[colorCodingAttribute]; double lineRadius = 0; switch (mode) { case RouteDrawingMode.Simple: lineRadius = rls.MonochromeWidth / 2; break; case RouteDrawingMode.Extended: lineRadius = (rls.Width + (rls.MaskVisible ? 2 * rls.MaskWidth : 0)) / 2; break; case RouteDrawingMode.None: lineRadius = 0; break; } double minX = zoomValue * (vertices[0].X - lineRadius); double maxX = zoomValue * (vertices[0].X + lineRadius); double minY = zoomValue * (vertices[0].Y - lineRadius); double maxY = zoomValue * (vertices[0].Y + lineRadius); for (int i = 0; i < vertices.Count; i++) { minX = Math.Min(minX, zoomValue * (vertices[i].X - lineRadius)); maxX = Math.Max(maxX, zoomValue * (vertices[i].X + lineRadius)); minY = Math.Min(minY, zoomValue * (vertices[i].Y - lineRadius)); maxY = Math.Max(maxY, zoomValue * (vertices[i].Y + lineRadius)); } double maxWidth = Math.Max(maxX - minX, maxY - minY); return(new RectangleD(new PointD(minX - frameWidth * maxWidth, minY - frameWidth * maxWidth), new SizeD(maxX - minX + 2 * frameWidth * maxWidth, maxY - minY + 2 * frameWidth * maxWidth))); }
// todo: skip showRouteLine parameter, use RouteDrawingMode instead public Bitmap CreateMapAndRouteImage(bool showRouteLine, double zoomValue, Session sessionToDraw, List <int> legsToDraw, double frameWidth, WaypointAttribute colorCodingAttribute, WaypointAttribute?secondaryColorCodingAttribute, RouteDrawingMode mode, SessionSettings sessionSettings) { RectangleD frame = GetFrame(zoomValue, sessionToDraw, legsToDraw, frameWidth, colorCodingAttribute, mode); var sc = new SessionCollection(); sc.Add(sessionToDraw); var wholeImage = CreateMapAndRouteImage(true, zoomValue, sc, colorCodingAttribute, secondaryColorCodingAttribute, mode, sessionSettings); AdjustFrameToImage(frame, wholeImage); var croppedImage = new Bitmap( Convert.ToInt32(Math.Ceiling(frame.Right) - Math.Floor(frame.Left)), Convert.ToInt32(Math.Ceiling(frame.Bottom) - Math.Floor(frame.Top))); var croppedImageGraphics = Graphics.FromImage(croppedImage); croppedImageGraphics.DrawImage( wholeImage, -Convert.ToInt32(Math.Floor(frame.Left)), -Convert.ToInt32(Math.Floor(frame.Top))); croppedImageGraphics.Dispose(); wholeImage.Dispose(); return(croppedImage); }
public Bitmap CreateMapAndRouteImage(bool showMap, double zoomValue, SessionCollection sessionsToDraw, WaypointAttribute colorCodingAttribute, WaypointAttribute?secondaryColorCodingAttribute, RouteDrawingMode mode, SessionSettings sessionSettings) { Bitmap mapImage; if (showMap) { mapImage = CreateMapImage(zoomValue); } else { var size = GetMapImageSize(zoomValue); mapImage = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppPArgb); } if (mode == RouteDrawingMode.None) { return(mapImage); } var mapAndRouteImage = new Bitmap(mapImage.Width, mapImage.Height, PixelFormat.Format32bppPArgb); var mapAndRouteGraphics = Graphics.FromImage(mapAndRouteImage); mapAndRouteGraphics.SmoothingMode = SmoothingMode.AntiAlias; DrawRoutes(sessionsToDraw, zoomValue, mapAndRouteGraphics, mapImage, mode, colorCodingAttribute, secondaryColorCodingAttribute, sessionSettings); mapAndRouteGraphics.Dispose(); mapImage.Dispose(); return(mapAndRouteImage); }
public void DrawRoutes(IEnumerable <Session> sessionsToDraw, double zoom, Graphics graphics, Image mapImage, RouteDrawingMode mode, WaypointAttribute colorCodingAttribute, WaypointAttribute?secondaryColorCodingAttribute, SessionSettings sessionSettings) { graphics.Clip = new Region(new Rectangle(0, 0, mapImage.Width, mapImage.Height)); // copy map as a background to route graphics.DrawImage(mapImage, new Point(0, 0)); // draw the routes foreach (var s in sessionsToDraw) { s.DrawRoute(zoom, graphics, mode, colorCodingAttribute, secondaryColorCodingAttribute, sessionSettings); } }