1. A concise explanation of the problem you’re experiencing.
2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
4. The Cesium version you’re using, your operating system and browser.
I want to convert an XYZ tile to a bounding box of Lat Long positions and found a website with examples
https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Lon..2Flat._to_tile_numbers_2
and created the code below from this.
This code correctly outputs (-180,-85.05) - (0,85.05) for tile Z0, X,0, Y0.
However when I looked at the South Island of New Zealand in debug mode the tile coordinate says L5X62Y23 or (X62,Y23,Z5)
Approx North -39, South -44 and West 168, East 174
If I then run that XYZ coordinate through the code below it returns the correct longitude but latitude is approx 20 degrees south (North -61, South -66)
What have I done wrong?
Default cesiumContainer used
public static BoundingBox GetLatLonBoundsForCesiumTile(int zoom, int x, int y)
{
BoundingBox bb = new BoundingBox();
bb.North = tile2lat(y, zoom);
bb.South = tile2lat(y + 1, zoom);
bb.West = tile2lon(x, zoom + 1);
bb.East = tile2lon(x + 1, zoom + 1);
return bb;
}
public static double tile2lon(int x, int zoom)
{
return x / Math.Pow(2, zoom) * 360.0 - 180;
}
public static double tile2lat(int y, int zoom)
{
double n = Math.PI - (2.0 * Math.PI * y) / Math.Pow(2.0, zoom);
return (180.0 / Math.PI) * (Math.Atan(Math.Sinh(n)));
}