From 52689796dfed796a1e949d39be411ccca3041933 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 1 Feb 2016 20:25:55 -0800 Subject: [PATCH] [core] Normalize only raster source tile URLs --- src/mbgl/map/source.cpp | 2 +- src/mbgl/style/style_parser.cpp | 4 +-- src/mbgl/style/style_parser.hpp | 2 +- .../style_parser/tilejson.raster.json | 8 ++++++ .../style_parser/tilejson.vector.json | 8 ++++++ test/miscellaneous/style_parser.cpp | 28 +++++++++++++++++++ 6 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/style_parser/tilejson.raster.json create mode 100644 test/fixtures/style_parser/tilejson.vector.json diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index b142a8471..7f9b47440 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -109,7 +109,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); + newInfo = StyleParser::parseTileJSON(*res.data, url, type); } 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 1b088bd38..7d53d603e 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -255,7 +255,7 @@ std::unique_ptr StyleParser::parseGeoJSON(const JS } } -std::unique_ptr StyleParser::parseTileJSON(const std::string& json, const std::string& sourceURL) { +std::unique_ptr StyleParser::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type) { rapidjson::GenericDocument, rapidjson::CrtAllocator> document; document.Parse<0>(json.c_str()); @@ -268,7 +268,7 @@ std::unique_ptr StyleParser::parseTileJSON(const std::string& json, std::unique_ptr result = StyleParser::parseTileJSON(document); // TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with. - if (util::mapbox::isMapboxURL(sourceURL)) { + if (type == SourceType::Raster && util::mapbox::isMapboxURL(sourceURL)) { std::transform(result->tiles.begin(), result->tiles.end(), result->tiles.begin(), diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 3a0d0fb6b..69bd8a3bf 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -28,7 +28,7 @@ public: std::vector> sources; std::vector> layers; - static std::unique_ptr parseTileJSON(const std::string& json, const std::string& sourceURL); + static std::unique_ptr parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType); static std::unique_ptr parseTileJSON(const JSValue&); static std::unique_ptr parseGeoJSON(const JSValue&); diff --git a/test/fixtures/style_parser/tilejson.raster.json b/test/fixtures/style_parser/tilejson.raster.json new file mode 100644 index 000000000..2eb0971a0 --- /dev/null +++ b/test/fixtures/style_parser/tilejson.raster.json @@ -0,0 +1,8 @@ +{ + "minzoom": 0, + "maxzoom": 15, + "center": [ 1, 2, 3 ], + "bounds": [ 4, 5, 6, 7 ], + "attribution": "attribution", + "tiles": [ "http://a.tiles.mapbox.com/mapbox.satellite/{z}-{x}-{y}.png?access_token=key" ] +} diff --git a/test/fixtures/style_parser/tilejson.vector.json b/test/fixtures/style_parser/tilejson.vector.json new file mode 100644 index 000000000..ea7d4bc35 --- /dev/null +++ b/test/fixtures/style_parser/tilejson.vector.json @@ -0,0 +1,8 @@ +{ + "minzoom": 0, + "maxzoom": 15, + "center": [ 1, 2, 3 ], + "bounds": [ 4, 5, 6, 7 ], + "attribution": "attribution", + "tiles": [ "http://a.tiles.mapbox.com/mapbox.streets/{z}-{x}-{y}.vector.pbf?access_token=key" ] +} diff --git a/test/miscellaneous/style_parser.cpp b/test/miscellaneous/style_parser.cpp index 46d0dab5d..22b5acb12 100644 --- a/test/miscellaneous/style_parser.cpp +++ b/test/miscellaneous/style_parser.cpp @@ -85,3 +85,31 @@ INSTANTIATE_TEST_CASE_P(StyleParser, StyleParserTest, ::testing::ValuesIn([] { EXPECT_GT(names.size(), 0ul); return names; }())); + +TEST(StyleParser, ParseTileJSONRaster) { + auto result = StyleParser::parseTileJSON( + util::read_file("test/fixtures/style_parser/tilejson.raster.json"), + "mapbox://mapbox.satellite", + SourceType::Raster); + + EXPECT_EQ(0, result->minZoom); + EXPECT_EQ(15, result->maxZoom); + EXPECT_EQ("attribution", result->attribution); +#if !defined(__ANDROID__) && !defined(__APPLE__) + EXPECT_EQ("http://a.tiles.mapbox.com/mapbox.satellite/{z}-{x}-{y}{ratio}.webp?access_token=key", result->tiles[0]); +#else + EXPECT_EQ("http://a.tiles.mapbox.com/mapbox.satellite/{z}-{x}-{y}{ratio}.png?access_token=key", result->tiles[0]); +#endif +} + +TEST(StyleParser, ParseTileJSONVector) { + auto result = StyleParser::parseTileJSON( + util::read_file("test/fixtures/style_parser/tilejson.vector.json"), + "mapbox://mapbox.streets", + SourceType::Vector); + + EXPECT_EQ(0, result->minZoom); + EXPECT_EQ(15, result->maxZoom); + EXPECT_EQ("attribution", result->attribution); + EXPECT_EQ("http://a.tiles.mapbox.com/mapbox.streets/{z}-{x}-{y}.vector.pbf?access_token=key", result->tiles[0]); +}