/// <summary>
    /// use for bing map
    /// </summary>
    /// <param name="mapPixel"></param>
    /// <param name="zoom"></param>
    /// <returns></returns>
    public static GetTerrain.Latlong pixelToLatlong(GetTerrain.Mappixel mapPixel, double zoom)
    {
        mapPixel = clipPixel(mapPixel, zoom);
        double pi      = 3.14159265358979323846264338327950288419716939937510;
        double mapSize = 256.0 * Math.Pow(2.0, zoom);
        double x       = (mapPixel.x / mapSize) - 0.5;
        double y       = 0.5 - (mapPixel.y / mapSize);

        GetTerrain.Latlong latlong = new GetTerrain.Latlong();
        latlong.lati   = 90.0 - 360.0 * Math.Atan(Math.Exp(-y * 2.0 * pi)) / pi;
        latlong.longti = 360.0 * x;
        return(latlong);
    }
    /// <summary>
    /// use for bing map
    /// </summary>
    /// <param name="latlong"></param>
    /// <param name="zoom"></param>
    /// <returns></returns>
    public static GetTerrain.Mappixel latlongToPixel(GetTerrain.Latlong latlong, double zoom)
    {
        latlong = clipLatlong(latlong);
        double pi          = 3.14159265358979323846264338327950288419716939937510;
        double x           = (latlong.longti + 180.0) / 360.0;
        double sinLatitude = Math.Sin(latlong.lati * pi / 180.0);
        double y           = 0.5 - Math.Log((1.0 + sinLatitude) / (1.0 - sinLatitude)) / (4.0 * pi);

        x *= 256.0 * Math.Pow(2.0, zoom);
        y *= 256.0 * Math.Pow(2.0, zoom);
        GetTerrain.Mappixel mapPixel = new GetTerrain.Mappixel();
        mapPixel.x = x;
        mapPixel.y = y;
        return(mapPixel);
    }
    public static GetTerrain.Latlong pixelToLatlong(Vector2 offset, GetTerrain.Latlong latlongCenter, double zoom)
    {
        double pi      = 3.14159265358979323846264338327950288419716939937510;
        double mapSize = 256.0 * Math.Pow(2.0, zoom);

        GetTerrain.Mappixel mapPixelCenter = latlongToPixel(latlongCenter, zoom);
        GetTerrain.Mappixel mapPixel       = new GetTerrain.Mappixel();
        mapPixel.x = mapPixelCenter.x + offset.x;
        mapPixel.y = mapPixelCenter.y + offset.y;
        double x = (mapPixel.x / mapSize) - 0.5;
        double y = 0.5 - (mapPixel.y / mapSize);

        GetTerrain.Latlong latlong = new GetTerrain.Latlong();
        latlong.lati   = 90 - 360 * Math.Atan(Math.Exp(-y * 2 * pi)) / pi;
        latlong.longti = 360 * x;
        latlong        = clipLatlong(latlong);
        return(latlong);
    }
    /// <summary>
    /// use for bing map
    /// </summary>
    /// <param name="mapPixel"></param>
    /// <param name="zoom"></param>
    /// <returns></returns>
    public static GetTerrain.Mappixel clipPixel(GetTerrain.Mappixel mapPixel, double zoom)
    {
        double mapSize = 256 * Math.Pow(2, zoom);

        if (mapPixel.x > mapSize - 1)
        {
            mapPixel.x -= mapSize - 1;
        }
        else if (mapPixel.x < 0)
        {
            mapPixel.x = mapSize - 1 - mapPixel.x;
        }

        if (mapPixel.y > mapSize - 1)
        {
            mapPixel.y -= mapSize - 1;
        }
        else if (mapPixel.y < 0)
        {
            mapPixel.y = mapSize - 1 - mapPixel.y;
        }

        return(mapPixel);
    }