From 648b5879599f6587eb7df36b4e951ec761c6437a Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 24 Aug 2015 13:37:59 -0700 Subject: [PATCH] Fixed missing labels and icons --- src/mbgl/util/mapbox.cpp | 13 +++++++++++-- test/miscellaneous/mapbox.cpp | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index dee0e0f8f..70587ac5a 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace mbgl { namespace util { @@ -19,7 +20,12 @@ std::vector getMapboxURLPathname(const std::string& url) { std::size_t startIndex = protocol.length(); while (startIndex < url.length()) { std::size_t endIndex = url.find("/", startIndex); - if (endIndex == std::string::npos) endIndex = url.length(); + if (endIndex == std::string::npos) { + endIndex = url.find_first_of("?#"); + } + if (endIndex == std::string::npos) { + endIndex = url.length(); + } pathname.push_back(url.substr(startIndex, endIndex - startIndex)); startIndex = endIndex + 1; } @@ -80,7 +86,10 @@ std::string normalizeGlyphsURL(const std::string& url, const std::string& access std::vector pathname = getMapboxURLPathname(url); std::string user = pathname[1]; - return baseURL + "fonts/v1/" + user + "/{fontstack}/{range}.pbf?access_token=" + accessToken; + std::string fontstack = pathname[2]; + std::string range = pathname[3]; + + return baseURL + "fonts/v1/" + user + "/" + fontstack + "/" + range + "?access_token=" + accessToken; } std::string normalizeTileURL(const std::string& url, const std::string& sourceURL, SourceType sourceType) { diff --git a/test/miscellaneous/mapbox.cpp b/test/miscellaneous/mapbox.cpp index f1febd729..a0f920829 100644 --- a/test/miscellaneous/mapbox.cpp +++ b/test/miscellaneous/mapbox.cpp @@ -14,6 +14,7 @@ TEST(Mapbox, SourceURL) { } TEST(Mapbox, GlyphsURL) { + EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fonts/boxmap/Comic%20Sans/0-255.pbf", "key"), "https://api.mapbox.com/fonts/v1/boxmap/Comic%20Sans/0-255.pbf?access_token=key"); EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fonts/boxmap/{fontstack}/{range}.pbf", "key"), "https://api.mapbox.com/fonts/v1/boxmap/{fontstack}/{range}.pbf?access_token=key"); EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("http://path", "key"), "http://path"); }