Exemplo n.º 1
0
        /// <summary>
        /// Calculates the tile id of the tile at position (0, 0) for the given zoom.
        /// </summary>
        /// <param name="zoom"></param>
        /// <returns></returns>
        private static ulong CalculateTileId(int zoom)
        {
            if (zoom == 0)
            { // zoom level 0: {0}.
                return(0);
            }
            //else if (zoom == 1)
            //{ // zoom level 1: {1, 2, 3, 4}.
            //    return 1;
            //}
            //else if (zoom == 2)
            //{ // zoom level 2: {5, 6, 7, 8, 9, 10, 11, 12}.
            //    return 5;
            //}

            ulong size = (ulong)System.Math.Pow(2, 2 * (zoom - 1));

            return(Tile.CalculateTileId(zoom - 1) + size);
        }
Exemplo n.º 2
0
        private static Tile CalculateTile(ulong id)
        {
            int zoom = 0;

            if (id > 0UL)
            {
                while (id >= Tile.CalculateTileId(zoom))
                {
                    ++zoom;
                }
                --zoom;
            }
            long  num1 = (long)id - (long)Tile.CalculateTileId(zoom);
            ulong num2 = (ulong)System.Math.Pow(2.0, (double)zoom);
            long  num3 = (long)num2;
            int   x    = (int)((ulong)num1 % (ulong)num3);
            long  num4 = (long)num2;
            int   y    = (int)((ulong)num1 / (ulong)num4);

            return(new Tile(x, y, zoom));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculate the tile given the id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private static Tile CalculateTile(ulong id)
        {
            // find out the zoom level first.
            int zoom = 0;
            if (id > 0)
            { // only if the id is at least at zoom level 1.
                while (id >= Tile.CalculateTileId(zoom))
                {
                    // move to the next zoom level and keep searching.
                    zoom++;
                }
                zoom--;
            }

            // calculate the x-y.
            ulong local = id - Tile.CalculateTileId(zoom);
            ulong width = (ulong)System.Math.Pow(2, zoom);
            int x = (int)(local % width);
            int y = (int)(local / width);

            return new Tile(x, y, zoom);
        }
Exemplo n.º 4
0
        private static ulong CalculateTileId(int zoom)
        {
            if (zoom == 0)
            {
                return(0);
            }
            if (zoom == 1)
            {
                return(1);
            }
            if (zoom == 2)
            {
                return(5);
            }
            if (zoom == 3)
            {
                return(21);
            }
            if (zoom == 4)
            {
                return(85);
            }
            if (zoom == 5)
            {
                return(341);
            }
            if (zoom == 6)
            {
                return(1365);
            }
            if (zoom == 7)
            {
                return(5461);
            }
            if (zoom == 8)
            {
                return(21845);
            }
            if (zoom == 9)
            {
                return(87381);
            }
            if (zoom == 10)
            {
                return(349525);
            }
            if (zoom == 11)
            {
                return(1398101);
            }
            if (zoom == 12)
            {
                return(5592405);
            }
            if (zoom == 13)
            {
                return(22369621);
            }
            if (zoom == 14)
            {
                return(89478485);
            }
            if (zoom == 15)
            {
                return(357913941);
            }
            if (zoom == 16)
            {
                return(1431655765);
            }
            if (zoom == 17)
            {
                return(5726623061);
            }
            if (zoom == 18)
            {
                return(22906492245);
            }
            ulong num = (ulong)System.Math.Pow(2.0, (double)(2 * (zoom - 1)));

            return(Tile.CalculateTileId(zoom - 1) + num);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Calculates the tile id of the tile at position (0, 0) for the given zoom.
        /// </summary>
        /// <param name="zoom"></param>
        /// <returns></returns>
        private static ulong CalculateTileId(int zoom)
        {
            if (zoom == 0)
            { // zoom level 0: {0}.
                return(0);
            }
            else if (zoom == 1)
            {
                return(1);
            }
            else if (zoom == 2)
            {
                return(5);
            }
            else if (zoom == 3)
            {
                return(21);
            }
            else if (zoom == 4)
            {
                return(85);
            }
            else if (zoom == 5)
            {
                return(341);
            }
            else if (zoom == 6)
            {
                return(1365);
            }
            else if (zoom == 7)
            {
                return(5461);
            }
            else if (zoom == 8)
            {
                return(21845);
            }
            else if (zoom == 9)
            {
                return(87381);
            }
            else if (zoom == 10)
            {
                return(349525);
            }
            else if (zoom == 11)
            {
                return(1398101);
            }
            else if (zoom == 12)
            {
                return(5592405);
            }
            else if (zoom == 13)
            {
                return(22369621);
            }
            else if (zoom == 14)
            {
                return(89478485);
            }
            else if (zoom == 15)
            {
                return(357913941);
            }
            else if (zoom == 16)
            {
                return(1431655765);
            }
            else if (zoom == 17)
            {
                return(5726623061);
            }
            else if (zoom == 18)
            {
                return(22906492245);
            }

            ulong size   = (ulong)System.Math.Pow(2, 2 * (zoom - 1));
            var   tileId = Tile.CalculateTileId(zoom - 1) + size;

            return(tileId);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Calculates the tile id of the tile at position (x, y) for the given zoom.
 /// </summary>
 /// <param name="zoom"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 private static ulong CalculateTileId(int zoom, int x, int y)
 {
     ulong id = Tile.CalculateTileId(zoom);
     long width = (long)System.Math.Pow(2, zoom);
     return id + (ulong)x + (ulong)(y * width);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Calculates the tile id of the tile at position (0, 0) for the given zoom.
        /// </summary>
        /// <param name="zoom"></param>
        /// <returns></returns>
        private static ulong CalculateTileId(int zoom)
        {
            if (zoom == 0)
            { // zoom level 0: {0}.
                return 0;
            }
            else if (zoom == 1)
            {
                return 1;
            }
            else if (zoom == 2)
            {
                return 5;
            }
            else if(zoom == 3)
            {
                return 21;
            }
            else if (zoom == 4)
            {
                return 85;
            }
            else if (zoom == 5)
            {
                return 341;
            }
            else if (zoom == 6)
            {
                return 1365;
            }
            else if (zoom == 7)
            {
                return 5461;
            }
            else if (zoom == 8)
            {
                return 21845;
            }
            else if (zoom == 9)
            {
                return 87381;
            }
            else if (zoom == 10)
            {
                return 349525;
            }
            else if (zoom == 11)
            {
                return 1398101;
            }
            else if (zoom == 12)
            {
                return 5592405;
            }
            else if (zoom == 13)
            {
                return 22369621;
            }
            else if (zoom == 14)
            {
                return 89478485;
            }
            else if (zoom == 15)
            {
                return 357913941;
            }
            else if (zoom == 16)
            {
                return 1431655765;
            }
            else if (zoom == 17)
            {
                return 5726623061;
            }
            else if (zoom == 18)
            {
                return 22906492245;
            }

            ulong size = (ulong)System.Math.Pow(2, 2 * (zoom - 1));
            var tileId = Tile.CalculateTileId(zoom - 1) + size;
            return tileId;
        }