diff options
author | Young Hahn <young@mapbox.com> | 2016-02-02 04:29:27 -0500 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-11 11:28:35 -0800 |
commit | 43c44eccdc56c50e41e8efbe5f7a34b57eed756f (patch) | |
tree | 65d39c01c1e3281a8d292049029fffa75e912cbc /src | |
parent | 7ca602b7394160a472f143a13f9ee2b725098e51 (diff) | |
download | qtlocation-mapboxgl-43c44eccdc56c50e41e8efbe5f7a34b57eed756f.tar.gz |
Allow using tileSize: 512 as a switch to trade retina support for 512px raster tiles
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/source.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.cpp | 9 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/mapbox.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/util/mapbox.hpp | 2 |
5 files changed, 16 insertions, 11 deletions
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 1a7933f53e..96af8c3cba 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -104,7 +104,7 @@ void Source::load() { // from the stylesheet. Then merge in the values parsed from the TileJSON we retrieved // via the URL. try { - newInfo = StyleParser::parseTileJSON(*res.data, url, type); + newInfo = StyleParser::parseTileJSON(*res.data, url, type, tileSize); } catch (...) { observer->onSourceError(*this, std::current_exception()); return; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 50276c8f5b..7c2a94b206 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -256,7 +256,7 @@ std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> StyleParser::parseGeoJSON(const JS } } -std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type) { +std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) { rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document; document.Parse<0>(json.c_str()); @@ -270,10 +270,9 @@ std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const std::string& json, // TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with. if (util::mapbox::isMapboxURL(sourceURL)) { - std::transform(result->tiles.begin(), - result->tiles.end(), - result->tiles.begin(), - std::bind(util::mapbox::canonicalizeTileURL, std::placeholders::_1, type)); + for (auto& url : result->tiles) { + url = util::mapbox::canonicalizeTileURL(url, type, tileSize); + } } return result; diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 162a10c87c..6b7c3fefbb 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -31,7 +31,7 @@ public: // Statically evaluate layer properties to determine what font stacks are used. std::vector<std::string> fontStacks() const; - static std::unique_ptr<SourceInfo> parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType); + static std::unique_ptr<SourceInfo> parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize); static std::unique_ptr<SourceInfo> parseTileJSON(const JSValue&); static std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> parseGeoJSON(const JSValue&); diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index 93b2b8521c..7ee0f279b6 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -119,7 +119,7 @@ std::string normalizeTileURL(const std::string& url, const std::string& accessTo return baseURL + "v4/" + url.substr(sizeof("mapbox://tiles/") - 1) + "?access_token=" + accessToken; } -std::string canonicalizeTileURL(const std::string& url, SourceType type) { +std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_t tileSize) { auto tilesetStartIdx = url.find("/v4/"); if (tilesetStartIdx == std::string::npos) { return url; @@ -159,8 +159,14 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type) { } #endif // !defined(__ANDROID__) && !defined(__APPLE__) - return "mapbox://tiles/" + tileset + "/{z}/{x}/{y}" + - (type == SourceType::Raster ? "{ratio}" : "") + "." + extension; + std::string result = "mapbox://tiles/" + tileset + "/{z}/{x}/{y}"; + + if (type == SourceType::Raster) { + result += tileSize == 512 ? "@2x" : "{ratio}"; + } + + result += "." + extension; + return result; } } // end namespace mapbox diff --git a/src/mbgl/util/mapbox.hpp b/src/mbgl/util/mapbox.hpp index c03916ff63..bb0536cfa2 100644 --- a/src/mbgl/util/mapbox.hpp +++ b/src/mbgl/util/mapbox.hpp @@ -17,7 +17,7 @@ std::string normalizeGlyphsURL(const std::string& url, const std::string& access std::string normalizeTileURL(const std::string& url, const std::string& accessToken); // Return a "mapbox://tiles/..." URL (suitable for normalizeTileURL) for the given Mapbox tile URL. -std::string canonicalizeTileURL(const std::string& url, SourceType); +std::string canonicalizeTileURL(const std::string& url, SourceType, uint16_t tileSize); } // namespace mapbox } // namespace util |