internal static ImageSource GetImage(TileID tid) { if (!dic.ContainsKey(tid)) { var image = MyImageDownloaderAsync.GetImageS(tid); dic.Add(tid, image); } return(dic[tid]); }
private void AddTiles(Rect newvp) { //если зум новый то добавить тайлы double vpX = newvp.X; var firstTileXIndex = (int)Math.Floor(-1 * vpX / Constants.TileSize); var firstTileYIndex = (int)Math.Floor(-1 * newvp.Y / Constants.TileSize); var coordX = vpX + firstTileXIndex * Constants.TileSize; var coordY = newvp.Y + firstTileYIndex * Constants.TileSize; while (firstTileYIndex < 0) { firstTileYIndex++; coordY += Constants.TileSize; } while (firstTileXIndex < 0) { firstTileXIndex++; coordX += Constants.TileSize; } int currentXIndex = 0; int currentYIndex = 0; var currentCoordX = coordX; var currentCoordY = coordY; #if DEBUG int querypiccounter = 0; #endif do { do { var tp = new TilePosition { X = currentXIndex + firstTileXIndex, Y = currentYIndex + firstTileYIndex }; TileID tid = new TileID { Pos = tp, Zoom = Zoom }; Tile tile = new Tile(tid); try { #if DEBUG querypiccounter++; #endif tile.SetImage(); } catch (TileIndexOutOfRangeException) { } _map.Children.Add(tile); Panel.SetZIndex(tile, 0); Canvas.SetLeft(tile, currentCoordX); Canvas.SetTop(tile, currentCoordY); currentCoordX += Constants.TileSize; currentXIndex++; var contX = MyImageDownloaderAsync.IsIndexCorrect(currentXIndex, Zoom); if (!contX) { break; } } while (currentCoordX <= _map.ActualWidth); currentCoordY += Constants.TileSize; currentYIndex++; currentCoordX = coordX; currentXIndex = 0; var contY = MyImageDownloaderAsync.IsIndexCorrect(currentYIndex, Zoom); if (!contY) { break; } } while (currentCoordY <= _map.ActualHeight); #if DEBUG // Debug.Print("qpc {0}",querypiccounter); #endif }