summaryrefslogtreecommitdiff
path: root/src/mbgl/util/mapbox.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-12-04 18:29:42 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-12-04 20:02:50 +0100
commitabafb52f37beb5659efc2105ccd1568e1f754898 (patch)
tree6a60636d3497560ca61e5aae5f6d7061c4f18553 /src/mbgl/util/mapbox.cpp
parentbff6aeb4da41dee1f5f1cfa0be81b6c257257253 (diff)
downloadqtlocation-mapboxgl-abafb52f37beb5659efc2105ccd1568e1f754898.tar.gz
make most headers private
Diffstat (limited to 'src/mbgl/util/mapbox.cpp')
-rw-r--r--src/mbgl/util/mapbox.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp
new file mode 100644
index 0000000000..277b647f34
--- /dev/null
+++ b/src/mbgl/util/mapbox.cpp
@@ -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);
+}
+
+}
+}
+}