summaryrefslogtreecommitdiff
path: root/src/mbgl/util/mapbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/util/mapbox.cpp')
-rw-r--r--src/mbgl/util/mapbox.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp
index 5d9c630c11..a8da81d1fd 100644
--- a/src/mbgl/util/mapbox.cpp
+++ b/src/mbgl/util/mapbox.cpp
@@ -8,11 +8,12 @@ namespace mapbox {
const std::string mapbox = "mapbox://";
-std::string normalizeURL(const std::string& url, const std::string& accessToken) {
+std::string normalizeURL(const std::string& url, const std::string& pathPrefix, const std::string& accessToken) {
if (accessToken.empty())
throw std::runtime_error("You must provide a Mapbox API access token for Mapbox tile sources");
- return std::string("https://api.tiles.mapbox.com/v4/")
+ return std::string("https://api.tiles.mapbox.com")
+ + pathPrefix
+ url.substr(mapbox.length())
+ "?access_token="
+ accessToken;
@@ -22,7 +23,7 @@ std::string normalizeSourceURL(const std::string& url, const std::string& access
if (url.compare(0, mapbox.length(), mapbox) != 0)
return url;
- std::string result = normalizeURL(url + ".json", accessToken);
+ std::string result = normalizeURL(url + ".json", "/v4/", accessToken);
// TileJSON requests need a secure flag appended to their URLs so
// that the server knows to send SSL-ified resource references.
@@ -31,11 +32,20 @@ std::string normalizeSourceURL(const std::string& url, const std::string& access
return result;
}
+std::string normalizeStyleURL(const std::string& url, const std::string& accessToken) {
+ if (url.compare(0, mapbox.length(), mapbox) != 0)
+ return url;
+
+ const std::string user = url.substr(mapbox.length(), url.find('.') - mapbox.length());
+
+ return normalizeURL(url, "/styles/v1/" + user + "/", accessToken);
+}
+
std::string normalizeGlyphsURL(const std::string& url, const std::string& accessToken) {
if (url.compare(0, mapbox.length(), mapbox) != 0)
return url;
- return normalizeURL(url, accessToken);
+ return normalizeURL(url, "/v4/", accessToken);
}
std::string normalizeTileURL(const std::string& url, const std::string& sourceURL, SourceType sourceType) {