Skip to content

Commit

Permalink
add support for bing map url quadkey in ros1 branch (#126)
Browse files Browse the repository at this point in the history
* add support for bing map url quadkey

* Update tile_id.cpp

* Update tile_id.h

* Update tile_id.h

* Update tile_id.cpp

---------

Co-authored-by: Peixuan Shu <[email protected]>
  • Loading branch information
shupx and Peixuan Shu authored Jan 11, 2025
1 parent 65bae6b commit 538ab12
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/tile_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ std::string tileURL(TileId const& tile_id)
boost::replace_all(url, "{x}", std::to_string(tile_id.coord.x));
boost::replace_all(url, "{y}", std::to_string(tile_id.coord.y));
boost::replace_all(url, "{z}", std::to_string(tile_id.zoom));

/* Added by Peixuan Shu to handle bing map */
boost::replace_all(url, "{quadkey}", TilesToQuadkey(tile_id.coord.x,
tile_id.coord.y,
tile_id.zoom));

return url;
}
Expand All @@ -58,3 +63,23 @@ size_t std::hash<TileId>::operator()(TileId const& tile_id) const
boost::hash_combine(seed, tile_id.zoom);
return seed;
}

std::string TilesToQuadkey(int x, int y, int z)
{
std::stringstream quadkey;
for (int i = z; i > 0; i--) {
char b = '0';
int mask = 1 << (i - 1);
if ((x & mask) != 0)
{
b++;
}
if ((y & mask) != 0)
{
b++;
b++;
}
quadkey << b;
}
return quadkey.str();
}
6 changes: 6 additions & 0 deletions src/tile_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ Q_DECLARE_METATYPE(TileId)
* Generate the URL to download a tile from
*/
std::string tileURL(TileId const& tile_id);

/**
* Get the quadkey from the tile x,y,zoom
* refer to https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
*/
std::string TilesToQuadkey(int x, int y, int z);

0 comments on commit 538ab12

Please sign in to comment.