Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tileReplace"></param>
        public static void JoinTilesToOneImageAndSave(TileReplace tileReplace, string xyzInPathFormat, string outTileFilePath)
        {
            switch (tileReplace.NeedTileIndex.Count)
            {
            case 1:                                                     //just copy.
                var needTile = tileReplace.NeedTileIndex.First();
                TouchFile(outTileFilePath);
                File.Copy(string.Format(xyzInPathFormat, needTile.X, needTile.Y, tileReplace.Zoom), outTileFilePath);
                break;

            case 2:
                CreateAndSaveFrom2tiles(tileReplace, xyzInPathFormat, outTileFilePath);
                break;

            case 4:
                CreateAndSaveFrom4tiles(tileReplace, xyzInPathFormat, outTileFilePath);
                break;
            }
        }
Example #2
0
        /// <summary>
        /// top and bottom pics.
        /// </summary>
        /// <param name="tileReplace"></param>
        /// <param name="xyzInPathFormat"></param>
        /// <param name="outTileFilePath"></param>
        private static void CreateAndSaveFrom2tiles(TileReplace tileReplace, string xyzInPathFormat, string outTileFilePath)
        {
            var joinTiles         = new Bitmap(TileMathBase.TileSize, TileMathBase.TileSize);
            var joinTilesGraphics = Graphics.FromImage(joinTiles);

            var needTile0 = tileReplace.NeedTileIndex.First();
            var image0    = GetImageFrom(string.Format(xyzInPathFormat, needTile0.X, needTile0.Y, tileReplace.Zoom));
            var needTile1 = tileReplace.NeedTileIndex.Last();
            var image1    = GetImageFrom(string.Format(xyzInPathFormat, needTile1.X, needTile1.Y, tileReplace.Zoom));

            if (image0 != null && image1 != null)
            {
                joinTilesGraphics.DrawImage(image0, 0, 0 - TileMathBase.TileSize + tileReplace.Shift.Y, TileMathBase.TileSize, TileMathBase.TileSize);
                joinTilesGraphics.DrawImage(image1, 0, TileMathBase.TileSize - TileMathBase.TileSize + tileReplace.Shift.Y, TileMathBase.TileSize, TileMathBase.TileSize);

                TouchFile(outTileFilePath);
                joinTiles.Save(outTileFilePath);
            }
        }
Example #3
0
        /// <summary>
        /// TopLeft-BottomLeft-TopRight-BottomRight.
        /// </summary>
        /// <param name="tileReplace"></param>
        /// <param name="xyzInPathFormat"></param>
        /// <param name="outTileFilePath"></param>
        private static void CreateAndSaveFrom4tiles(TileReplace tileReplace, string xyzInPathFormat, string outTileFilePath)
        {
            var joinTiles         = new Bitmap(TileMathBase.TileSize, TileMathBase.TileSize);
            var joinTilesGraphics = Graphics.FromImage(joinTiles);

            var arr     = tileReplace.NeedTileIndex.ToArray();
            var image00 = GetImageFrom(string.Format(xyzInPathFormat, arr[0].X, arr[0].Y, tileReplace.Zoom));
            var image01 = GetImageFrom(string.Format(xyzInPathFormat, arr[1].X, arr[1].Y, tileReplace.Zoom));
            var image10 = GetImageFrom(string.Format(xyzInPathFormat, arr[2].X, arr[2].Y, tileReplace.Zoom));
            var image11 = GetImageFrom(string.Format(xyzInPathFormat, arr[3].X, arr[3].Y, tileReplace.Zoom));

            if (image00 != null && image01 != null && image10 != null && image11 != null)
            {
                joinTilesGraphics.DrawImage(image00, 0 - tileReplace.Shift.X, 0 - tileReplace.Shift.Y, TileMathBase.TileSize, TileMathBase.TileSize);
                joinTilesGraphics.DrawImage(image01, 0 - tileReplace.Shift.X, TileMathBase.TileSize - tileReplace.Shift.Y, TileMathBase.TileSize, TileMathBase.TileSize);
                joinTilesGraphics.DrawImage(image10, TileMathBase.TileSize - tileReplace.Shift.X, 0 - tileReplace.Shift.Y, TileMathBase.TileSize, TileMathBase.TileSize);
                joinTilesGraphics.DrawImage(image11, TileMathBase.TileSize - tileReplace.Shift.X, TileMathBase.TileSize - tileReplace.Shift.Y, TileMathBase.TileSize, TileMathBase.TileSize);

                TouchFile(outTileFilePath);
                joinTiles.Save(outTileFilePath);
            }
        }
Example #4
0
        private TileReplace FindReplace(int sphericalTileIndexX, int sphericalTileIndexY, int zoom, Point resultXY)
        {
            var tileXYindex = TileMathBase.PixelXY2TileXY(resultXY.X, resultXY.Y);

            var xShift = resultXY.X % TileMathBase.TileSize;
            var yShift = resultXY.Y % TileMathBase.TileSize;

            if (xShift == 0 && yShift == 0)
            {
                //just copy.
                var result1 = new TileReplace(tileXYindex.X, tileXYindex.Y, zoom);
                result1.NeedTileIndex.Add(new Point(sphericalTileIndexX, sphericalTileIndexY));
                result1.Shift = new Point(0, 0);
                return(result1);
            }
            else if (xShift == 0 && yShift != 0)
            {
                //can try to create Y+1 tile.
                var result2 = new TileReplace(tileXYindex.X, tileXYindex.Y + 1, zoom);
                result2.NeedTileIndex.Add(new Point(sphericalTileIndexX, sphericalTileIndexY));
                result2.NeedTileIndex.Add(new Point(sphericalTileIndexX, sphericalTileIndexY + 1));
                result2.Shift = new Point(0, yShift);
                return(result2);
            }
            else
            {
                //need 4 tiles to create a one new.
                var result3 = new TileReplace(tileXYindex.X + 1, tileXYindex.Y + 1, zoom);
                result3.NeedTileIndex.Add(new Point(sphericalTileIndexX, sphericalTileIndexY));
                result3.NeedTileIndex.Add(new Point(sphericalTileIndexX, sphericalTileIndexY + 1));
                result3.NeedTileIndex.Add(new Point(sphericalTileIndexX + 1, sphericalTileIndexY));
                result3.NeedTileIndex.Add(new Point(sphericalTileIndexX + 1, sphericalTileIndexY + 1));
                result3.Shift = new Point(xShift, yShift);
                return(result3);
            }
        }