summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2014-07-09 17:18:36 -0700
committerJustin R. Miller <incanus@codesorcery.net>2014-07-09 17:18:36 -0700
commit98a415416a35bb4a2c834361391b8855a0bca644 (patch)
tree9bd2dc4251258a213a162c3a77dad61630c62b1e /src/map
parente66ed8fea417ae3d81c676264e09e4526c018ebf (diff)
downloadqtlocation-mapboxgl-98a415416a35bb4a2c834361391b8855a0bca644.tar.gz
move to per-map access token
Diffstat (limited to 'src/map')
-rw-r--r--src/map/map.cpp10
-rw-r--r--src/map/source.cpp20
2 files changed, 16 insertions, 14 deletions
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 516e8fe03f..b1f22235bb 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -22,7 +22,7 @@ using namespace llmr;
Map::Map(View& view)
: view(view),
transform(),
- style(std::make_shared<Style>()),
+ style(std::make_shared<Style>(*this)),
glyphAtlas(std::make_shared<GlyphAtlas>(1024, 1024)),
spriteAtlas(std::make_shared<SpriteAtlas>(512, 512)),
texturepool(std::make_shared<Texturepool>()),
@@ -183,6 +183,14 @@ std::string Map::getStyleJSON() const {
return styleJSON;
}
+void Map::setAccessToken( std::string access_token) {
+ accessToken.swap(access_token);
+}
+
+std::string Map::getAccessToken() const {
+ return accessToken;
+}
+
#pragma mark - Size
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
diff --git a/src/map/source.cpp b/src/map/source.cpp
index d52cfe9837..da963272da 100644
--- a/src/map/source.cpp
+++ b/src/map/source.cpp
@@ -17,33 +17,27 @@
namespace llmr {
-static std::string mapboxAccessToken;
-
-void setMapboxAccessToken(const std::string& token) {
- mapboxAccessToken = token;
-}
-
Source::Source(SourceType type, const std::string &url,
- uint32_t tile_size, uint32_t min_zoom, uint32_t max_zoom)
+ uint32_t tile_size, uint32_t min_zoom, uint32_t max_zoom,
+ const std::string &access_token)
: type(type),
- url(normalizeSourceURL(url)),
+ url(normalizeSourceURL(url, access_token)),
tile_size(tile_size),
min_zoom(min_zoom),
max_zoom(max_zoom) {}
-std::string Source::normalizeSourceURL(const std::string &url) {
+std::string Source::normalizeSourceURL(const std::string &url, const std::string &access_token) {
const std::string t = "mapbox://";
if (url.compare(0, t.length(), t) == 0) {
- if (mapboxAccessToken.empty()) {
- throw std::runtime_error("You must provide a Mapbox API access token via llmr::setMapboxAccessToken()");
+ if (access_token.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(t.length()) + "/%d/%d/%d.vector.pbf?access_token=" + mapboxAccessToken;
+ return "https://api.tiles.mapbox.com/v4/" + url.substr(t.length()) + "/%d/%d/%d.vector.pbf?access_token=" + access_token;
} else {
return url;
}
}
-
bool Source::update(Map &map) {
if (map.getTime() > updated) {
return updateTiles(map);