Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swapped North/South and West/East coordinates in Tile Id To Bounds? #1911

Open
spatialsparks opened this issue Aug 15, 2023 · 0 comments
Open

Comments

@spatialsparks
Copy link

I am building a location-based game and have been having a closer look at the Mapbox SDK (I am building an own light-weight version of a simple slippy map tile provider for Unity taking major inspiration from this SDK). I was wondering if there is a little (conceptual, not sure it has an impact) error in the calculation of the Slippy Tile bounds here:

https://github.com/mapbox/mapbox-unity-sdk/blob/78fdee9c7a06c94a6ef493d78d6cf696e44fd4eb/sdkproject/Assets/Mapbox/Unity/Utilities/Conversions.cs#L300C1-L305C4

The formula taken from here: https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#C# calculated the North West corner coord. So the North-West (top left) coord would be using the tile X and Y. The South-East (bottom right) coord would however use X+1 and Y+1 seeing the tile naming convention starts at the Top-Left of the world (https://wiki.openstreetmap.org/wiki/File:Tiled_web_map_numbering.png). This means, the higher X is the more East we are and the higher Y is, the more South we are. This would mean, the adding for the tiles should be swapped:

		public static Vector2dBounds TileIdToBounds(int x, int y, int zoom)
		{
			var sw = new Vector2d(TileYToNWLatitude(y+1, zoom), TileXToNWLongitude(x, zoom));
			var ne = new Vector2d(TileYToNWLatitude(y, zoom), TileXToNWLongitude(x+1, zoom));
			return new Vector2dBounds(sw, ne);
		}

Or did I miss something?

Ps. This is a great SDK for Unity, thanks for the amazing work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant