diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-07-12 10:57:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-12 10:57:18 -0700 |
commit | 08d0a9a0e2e771b87018bcb3d4d124c52fed1689 (patch) | |
tree | 98432ab1ef18401c7988c9d133181c3b6131e88f /src/mbgl/storage | |
parent | 63298066b1508a9546dbf61b86de718c5cbf57cf (diff) | |
download | qtlocation-mapboxgl-08d0a9a0e2e771b87018bcb3d4d124c52fed1689.tar.gz |
Quadkey tokens in tile URL templates, limited WMS support (#5628)
* [core] Quadkey tokens in tile URL templates
Fixes #5485.
* [core] WMS tokens in tile URL templates
Fixes #822.
* [macos] Added WMS debug style
Added a style to the macosapp resource bundle that can be used to test WMS support. To use it, zoom in to somewhere in New Jersey, then go to View ‣ Custom Style and enter “wms.json”.
Diffstat (limited to 'src/mbgl/storage')
-rw-r--r-- | src/mbgl/storage/resource.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mbgl/storage/resource.cpp b/src/mbgl/storage/resource.cpp index 8019e4aeb7..bb587dcc33 100644 --- a/src/mbgl/storage/resource.cpp +++ b/src/mbgl/storage/resource.cpp @@ -1,10 +1,44 @@ +#include <mapbox/geometry/box.hpp> #include <mbgl/storage/resource.hpp> +#include <mbgl/util/constants.hpp> #include <mbgl/util/string.hpp> #include <mbgl/util/token.hpp> #include <mbgl/util/url.hpp> +#include <cmath> + namespace mbgl { +static std::string getQuadKey(int32_t x, int32_t y, int8_t z) { + std::string quadKey; + quadKey.reserve(z); + int32_t mask; + for (int8_t i = z; i > 0; i--) { + mask = 1 << (i - 1); + quadKey += '0' + ((x & mask ? 1 : 0) + (y & mask ? 2 : 0)); + } + return quadKey; +} + +static mapbox::geometry::point<double> getMercCoord(int32_t x, int32_t y, int8_t z) { + double resolution = (util::M2PI * util::EARTH_RADIUS_M / 256) / std::pow(2.0f, z); + return { + x * resolution - util::M2PI * util::EARTH_RADIUS_M / 2, + y * resolution - util::M2PI * util::EARTH_RADIUS_M / 2, + }; +} + +static std::string getTileBBox(int32_t x, int32_t y, int8_t z) { + // Alter the y for the Google/OSM tile scheme. + y = std::pow(2.0f, z) - y - 1; + + auto min = getMercCoord(x * 256, y * 256, z); + auto max = getMercCoord((x + 1) * 256, (y + 1) * 256, z); + + return (util::toString(min.x) + "," + util::toString(min.y) + "," + + util::toString(max.x) + "," + util::toString(max.y)); +} + Resource Resource::style(const std::string& url) { return Resource { Resource::Kind::Style, @@ -64,6 +98,10 @@ Resource Resource::tile(const std::string& urlTemplate, return util::toString(x); } else if (token == "y") { return util::toString(y); + } else if (token == "quadkey") { + return getQuadKey(x, y, z); + } else if (token == "bbox-epsg-3857") { + return getTileBBox(x, y, z); } else if (token == "prefix") { std::string prefix{ 2 }; prefix[0] = "0123456789abcdef"[x % 16]; |