/// <summary> /// 画单个图层方法 /// </summary> /// <param name="g"></param> /// <param name="layer"></param> /// <param name="start"></param> /// <param name="scale"></param> /// <returns></returns> private Point LegendOfLayer(Graphics g, Map.MyLayer layer, Point start, double resizescale) { int layerdis = (int)(20 * resizescale); int leftdis = (int)(resizescale * 8); int columdis = (int)(resizescale * 12); int rowdis = (int)(resizescale * 10); Point nowstart = new Point(start.X + leftdis, start.Y + layerdis); g.DrawString(layer.LayerName, new Font("黑体", (float)(resizescale * 10)), Brushes.Black, nowstart); nowstart.Y += ((int)(resizescale * 10) + rowdis); Font regularfont = new Font("宋体", (float)(resizescale * 9)); int symbolcount = layer.Renderer.SymbolCount; switch (layer.rendertype) { case MyRenderer.RendererType.UniqueValueRenderer: UniqueValueRenderer urenderer = (UniqueValueRenderer)layer.Renderer; for (int i = 0; i < symbolcount; i++) { Bitmap autoubit = urenderer.FindSymbolByIndex(i).GetBitmap(); Image uimg = new Bitmap(autoubit, new Size((int)(resizescale * autoubit.Width), (int)(resizescale * autoubit.Height))); g.DrawImage(uimg, nowstart); g.DrawString(urenderer.FindValue(i), regularfont, Brushes.Black, new Point(nowstart.X + (int)(resizescale * 42) + columdis, nowstart.Y + (int)(resizescale * 6))); nowstart.Y += (int)(resizescale * 24) + rowdis; } break; case MyRenderer.RendererType.ClassBreakRenderer: ClassBreakRenderer crenderer = (ClassBreakRenderer)layer.Renderer; for (int i = 0; i < symbolcount; i++) { Bitmap autocbit = crenderer.FindSymbolByIndex(i).GetBitmap(); Image cimg = new Bitmap(autocbit, new Size((int)(resizescale * autocbit.Width), (int)(resizescale * autocbit.Height))); g.DrawImage(cimg, nowstart); string value; if (i == 0) { value = crenderer.MinValue.ToString() + " - " + crenderer.Breaks[i].ToString(); } else if (i != crenderer.BreakCount) { value = crenderer.Breaks[i - 1].ToString() + " - " + crenderer.Breaks[i].ToString(); } else { value = crenderer.Breaks[i - 1].ToString() + " - " + crenderer.MaxValue.ToString(); } g.DrawString(value, regularfont, Brushes.Black, new Point((nowstart.X + (int)(resizescale * 42) + columdis), (nowstart.Y + (int)(resizescale * 6)))); nowstart.Y += (int)(resizescale * 24) + rowdis; } break; default: SimpleRenderer srenderer = (SimpleRenderer)layer.Renderer; Bitmap autosbit = srenderer.SymbolStyle.GetBitmap(); Image simg = new Bitmap(autosbit, new Size((int)(resizescale * autosbit.Width), (int)(resizescale * autosbit.Height))); g.DrawImage(simg, nowstart); g.DrawString(layer.LayerName, regularfont, Brushes.Black, new Point((nowstart.X + (int)(resizescale * 42) + columdis), (nowstart.Y + (int)(resizescale * 6)))); nowstart.Y += ((int)(resizescale * 24) + rowdis); break; } return(nowstart); }
public void Open() { FileStream fs = new FileStream(_filepath, FileMode.Open); StreamReader sr = new StreamReader(fs); string line = sr.ReadLine(); string[] words = line.Split(' '); _Geocoordinate = Map.MyCoordinates.WGS1984; //由于不存在null选项 _Procoordinate = Map.MyCoordinates.WGS1984; //由于不存在null选项 //记录地理坐标系 switch (words[1]) { case "WGS1984": _Geocoordinate = Map.MyCoordinates.WGS1984; break; } //记录投影坐标系 switch (words[2]) { case "WGS1984": _Geocoordinate = Map.MyCoordinates.WGS1984; break; } //生成地图 _map = new Map.MyMap(words[0], _Geocoordinate, Convert.ToDouble(words[3])); _ratio = Convert.ToDouble(words[3]); _scaleindex = Convert.ToInt32(words[4]); //显示中心点位 _centerpos = new PointF((float)Convert.ToDouble(words[5]), (float)Convert.ToDouble(words[6])); //图层数量 int layercount = Convert.ToInt32(words[7]); for (int i = 0; i < layercount; i++) { string layerpath = sr.ReadLine(); Map.MyLayer newlayer = null; if (Path.GetExtension(layerpath) == ".shp") { //TODO先只可读SHP Shapefile newshp = new Shapefile(layerpath); newlayer = new MyLayer(newshp); } else { CosmosGisVector newcgv = new CosmosGisVector(layerpath); newlayer = new MyLayer(newcgv); } newlayer.FilePath = layerpath; //设置是否可见 string visible = sr.ReadLine(); if (visible == "True") { newlayer.Visible = true; } else { newlayer.Visible = false; } //获取渲染方式 string layerline = sr.ReadLine(); RendererType newrendertyppe = new GetType().RendererType(layerline.Split(' ')[0]); newlayer.rendertype = newrendertyppe; switch (newrendertyppe) { //唯一值渲染 case RendererType.UniqueValueRenderer: string field_uvr = layerline.Split(' ')[1]; //TODO 获得属性唯一值 DataTable dt_uvr = newlayer.SpaceData.Property.SqlQuery("Select Distinct " + field_uvr + " From " + newlayer.LayerName); List <string> values_uvr = new List <string>(); for (int j = 0; j < dt_uvr.Rows.Count; j++) { values_uvr.Add(dt_uvr.Rows[j][field_uvr].ToString()); } //List<string> values = new List<string>() { "1", "2", "3", "3" ,"3","3","7"}; newlayer.Renderer = new UniqueValueRenderer(newlayer.DataType, field_uvr, values_uvr); break; //分级渲染 case RendererType.ClassBreakRenderer: string field_cbr = layerline.Split(' ')[1]; DataTable dt_cbr = newlayer.SpaceData.Property.SqlQuery("Select Distinct " + field_cbr + " From " + newlayer.LayerName); List <double> values_cbr = new List <double>(); for (int j = 0; j < dt_cbr.Rows.Count; j++) { values_cbr.Add(Convert.ToDouble(dt_cbr.Rows[j][field_cbr])); } //List<double> breaks = new List<double>() { 1, 2, 3 }; newlayer.Renderer = new ClassBreakRenderer(newlayer.DataType, field_cbr, values_cbr); break; //简单渲染 default: newlayer.Renderer = new SimpleRenderer(newlayer.DataType); break; } //判断是否有注记信息 string hastext = sr.ReadLine(); if (hastext == "True") { newlayer.HasText = true; newlayer.Textrender = new TextRenderer(sr.ReadLine()); } else { newlayer.HasText = false; } _map.AddLayer(newlayer); } sr.Close(); fs.Close(); }