private void DrawMap(Report rpt, Graphics g, string mapfile, double max, double min) { string file = XmlUtil.XmlFileExists(mapfile); MapData mp; if (file != null) { mp = MapData.Create(file); } else { rpt.rl.LogError(4, string.Format("Map Subtype file {0} not found.", mapfile)); mp = new MapData(); // we'll at least put up something; but it won't be right } float scale = mp.GetScale(Layout.PlotArea.Width, Layout.PlotArea.Height); for (int iRow = 1; iRow <= CategoryCount; iRow++) { for (int iCol = 1; iCol <= SeriesCount; iCol++) { string sv = GetSeriesValue(rpt, iCol); string c = this.GetDataValueString(rpt, iRow, iCol); List <MapPolygon> pl = mp.GetPolygon(sv); if (pl == null) { continue; } Brush br = new SolidBrush(XmlUtil.ColorFromHtml(c, Color.Transparent)); foreach (MapPolygon mpoly in pl) { PointF[] polygon = mpoly.Polygon; PointF[] drawpoly = new PointF[polygon.Length]; // make points relative to plotarea --- need to scale this as well for (int ip = 0; ip < drawpoly.Length; ip++) { drawpoly[ip] = new PointF(Layout.PlotArea.X + (polygon[ip].X * scale), Layout.PlotArea.Y + (polygon[ip].Y * scale)); } g.FillPolygon(br, drawpoly); if (_showToolTips) { StringBuilder sb = new StringBuilder(); sb.Append("PolyToolTip:"); sb.Append(sv.Replace('|', '/')); // we treat '|' as a separator character; don't allow in string sb.Append(' '); sb.Append(c.Replace('|', '/')); foreach (PointF pf in drawpoly) { sb.AppendFormat(NumberFormatInfo.InvariantInfo, "|{0}|{1}", pf.X, pf.Y); } g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(sb.ToString())); } } br.Dispose(); } } // draw the outline of the map foreach (MapObject mo in mp.MapObjects) { mo.Draw(g, scale, Layout.PlotArea.X, Layout.PlotArea.Y); } }
private void DrawMap(Report rpt, Graphics g, string mapfile, double max, double min) { string file = XmlUtil.XmlFileExists(mapfile); MapData mp; if (file != null) mp = MapData.Create(file); else { rpt.rl.LogError(4, string.Format("Map Subtype file {0} not found.", mapfile)); mp = new MapData(); // we'll at least put up something; but it won't be right } float scale = mp.GetScale(Layout.PlotArea.Width, Layout.PlotArea.Height); for (int iRow = 1; iRow <= CategoryCount; iRow++) { for (int iCol = 1; iCol <= SeriesCount; iCol++) { string sv = GetSeriesValue(rpt, iCol); string c = this.GetDataValueString(rpt, iRow, iCol); List<MapPolygon> pl = mp.GetPolygon(sv); if (pl == null) continue; Brush br = new SolidBrush(XmlUtil.ColorFromHtml(c, Color.Transparent)); foreach (MapPolygon mpoly in pl) { PointF[] polygon = mpoly.Polygon; PointF[] drawpoly = new PointF[polygon.Length]; // make points relative to plotarea --- need to scale this as well for (int ip = 0; ip < drawpoly.Length; ip++) { drawpoly[ip] = new PointF(Layout.PlotArea.X + (polygon[ip].X * scale), Layout.PlotArea.Y + (polygon[ip].Y * scale)); } g.FillPolygon(br, drawpoly); if (_showToolTips) { StringBuilder sb = new StringBuilder(); sb.Append("PolyToolTip:"); sb.Append(sv.Replace('|', '/')); // we treat '|' as a separator character; don't allow in string sb.Append(' '); sb.Append(c.Replace('|', '/')); foreach (PointF pf in drawpoly) sb.AppendFormat(NumberFormatInfo.InvariantInfo, "|{0}|{1}", pf.X, pf.Y); g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(sb.ToString())); } } br.Dispose(); } } // draw the outline of the map foreach (MapObject mo in mp.MapObjects) { mo.Draw(g, scale, Layout.PlotArea.X, Layout.PlotArea.Y); } }
/// <summary> /// Given a file name constructs a MapData /// </summary> /// <param name="file"></param> /// <returns></returns> static public MapData Create(string file) { lock (_MapCache) { DateTime filetime = File.GetLastWriteTimeUtc(file); MapData mp = null; if (_MapCache.TryGetValue(file, out mp)) { if (mp._TimeStamp.Ticks == filetime.Ticks) return mp; _MapCache.Remove(file); mp = null; } XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; settings.IgnoreWhitespace = true; settings.IgnoreComments = true; XmlReader reader = XmlReader.Create(file, settings); try { mp = new MapData(reader); mp._TimeStamp = filetime; _MapCache.Add(file, mp); // add this to the cache } finally { reader.Close(); } return mp; } }