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

add support for bing map url quadkey in ros1 branch #126

Open
wants to merge 3 commits into
base: ros1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "{q}", TilesToQuadkey(tile_id.coord.x,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes {q} from the url. Doesn't this break all other providers except bing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No influence on other map providers as there is no '{q}' in their urls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, good point.

Would you mind naming it {quadkey} in the url? Because {q} is often used for quaternion in the context of coordinate systems and ROS.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very magical function. Do you have a source for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how quadkey converted to tile xyz defined by Microsoft bing map team. Please refer to https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, would you mind adding that link in the function description for future reference?

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

std::string TilesToQuadkey(int x, int y, int z);