public Bitmap GetMap(BoundingBox box, Size sizePicMain, int intMapLevel) { Bitmap bmpResult = new Bitmap(sizePicMain.Width, sizePicMain.Height); Graphics g = Graphics.FromImage(bmpResult); g.Clear(Color.White); #region 绘制图片 ArrayList list = GetAllmapPieceInfo(box, intMapLevel); for (int i = 0; i < list.Count; i++) { MapPieceInfo mpi = list[i] as MapPieceInfo; byte[] file = Getpic(mpi.filename); if (file != null && file.Length > 0) { Bitmap itemMap = new Bitmap(new MemoryStream(file)); g.DrawImage(itemMap, mpi.destRect, mpi.srcRect, GraphicsUnit.Pixel); } } #endregion g.Dispose(); return(bmpResult); }
/// <summary> /// 调整下载图片顺序,以中心向四周下载 /// </summary> public ArrayList RePrioritymapPiece(ArrayList list) { if (list.Count < 2) { return(list); } MapPieceInfo temp = null; for (int i = 0; i < list.Count; i++) { for (int j = i + 1; j < list.Count; j++) { MapPieceInfo m1 = list[i] as MapPieceInfo; MapPieceInfo m2 = list[j] as MapPieceInfo; if (m1.Priority > m2.Priority) { temp = m1; m1 = m2; m2 = temp; list[i] = m1; list[j] = m2; } } } return(list); }
/// <summary> /// 获取地图块拼接信息 /// </summary> /// <param name="box"></param> /// <param name="size"></param> /// <param name="level"></param> /// <returns></returns> public ArrayList GetAllmapPieceInfo(BoundingBox box, int level) { ArrayList list = new ArrayList(); PauseMapViewInfo PI = new PauseMapViewInfo(box, level); SogouMapInfo maptypeinfo = new SogouMapInfo(); //计算第一个图片块的左上角所处图像位置 PointD p = maptypeinfo.PixelToImage(PI.topPoint, new PointD(box.Min.X, box.Max.Y), level); #region 计算图片 int Width = PI.maxColIndex - PI.minColIndex + 1; int Height = PI.maxRowIndex - PI.minRowIndex + 1; int centerX = (Width - 1) / 2; int centerY = (Height - 1) / 2; int intTest = 0; for (int rowIndex = PI.minRowIndex; rowIndex <= PI.maxRowIndex; rowIndex++) { for (int colIndex = PI.minColIndex; colIndex <= PI.maxColIndex; colIndex++) { intTest++; Rectangle destRect = new Rectangle((colIndex - PI.minColIndex) * maptypeinfo.tileSize + (int)Math.Round(p.X), (rowIndex - PI.minRowIndex) * maptypeinfo.tileSize + (int)Math.Round(p.Y), maptypeinfo.tileSize, maptypeinfo.tileSize); string filename = ZYB.GIS.GoogleMapType.GetFileName(colIndex, rowIndex, level); Rectangle srcRect = new Rectangle(0, 0, maptypeinfo.tileSize, maptypeinfo.tileSize); MapPieceInfo mp = new MapPieceInfo(); int x = colIndex - PI.minColIndex; int y = rowIndex - PI.minRowIndex; mp.Priority = (x - centerX) * (x - centerX) + (y - centerY) * (y - centerY); mp.filename = filename; mp.destRect = destRect; mp.srcRect = srcRect; list.Add(mp); } } string ww = intTest.ToString(); #endregion return(RePrioritymapPiece(list)); }