Support for Mapbox fontstack API

This commit is contained in:
John Firebaugh
2014-08-22 15:31:57 -07:00
parent 3b43c4ddf2
commit 3d9a293258
9 changed files with 112 additions and 23 deletions

44
src/util/mapbox.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include <mbgl/util/mapbox.hpp>
#include <stdexcept>
namespace mbgl {
namespace util {
namespace mapbox {
const std::string mapbox = "mapbox://";
std::string normalizeURL(const std::string& url, 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/")
+ url.substr(mapbox.length())
+ "?access_token="
+ accessToken;
}
std::string normalizeSourceURL(const std::string& url, const std::string& accessToken) {
if (url.compare(0, mapbox.length(), mapbox) != 0)
return url;
std::string result = normalizeURL(url + ".json", accessToken);
// TileJSON requests need a secure flag appended to their URLs so
// that the server knows to send SSL-ified resource references.
if (url.compare(0, 5, "https") == 0)
result += "&secure";
return result;
}
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);
}
}
}
}