summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llmr/map/map.hpp3
-rw-r--r--include/llmr/map/source.hpp5
-rw-r--r--include/llmr/style/style.hpp4
-rw-r--r--include/llmr/style/style_parser.hpp5
-rw-r--r--src/map/map.cpp10
-rw-r--r--src/map/source.cpp20
-rw-r--r--src/style/style.cpp6
-rw-r--r--src/style/style_parser.cpp7
8 files changed, 40 insertions, 20 deletions
diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp
index 1af6b3c540..defc1bef1f 100644
--- a/include/llmr/map/map.hpp
+++ b/include/llmr/map/map.hpp
@@ -59,6 +59,8 @@ public:
void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0);
void setStyleJSON(std::string newStyleJSON);
std::string getStyleJSON() const;
+ void setAccessToken(std::string access_token);
+ std::string getAccessToken() const;
// Transition
void cancelTransitions();
@@ -166,6 +168,7 @@ private:
Painter painter;
std::string styleJSON = "";
+ std::string accessToken = "";
bool debug = false;
timestamp animationTime = 0;
diff --git a/include/llmr/map/source.hpp b/include/llmr/map/source.hpp
index 2937a8f690..f746249252 100644
--- a/include/llmr/map/source.hpp
+++ b/include/llmr/map/source.hpp
@@ -23,7 +23,8 @@ class Texturepool;
class Source : public std::enable_shared_from_this<Source>, private util::noncopyable {
public:
Source(SourceType type = SourceType::Vector, const std::string &url = "",
- uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 22);
+ uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 22,
+ const std::string &access_token = "");
bool update(Map &map);
void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
@@ -35,7 +36,7 @@ public:
std::forward_list<Tile::ID> getIDs() const;
void updateClipIDs(const std::map<Tile::ID, ClipID> &mapping);
- static std::string normalizeSourceURL(const std::string &url);
+ static std::string normalizeSourceURL(const std::string &url, const std::string &access_token);
public:
const SourceType type;
diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp
index 37a50485ba..cfaba1898c 100644
--- a/include/llmr/style/style.hpp
+++ b/include/llmr/style/style.hpp
@@ -16,6 +16,7 @@
namespace llmr {
+class Map;
class Sprite;
class Source;
class StyleLayer;
@@ -27,7 +28,7 @@ public:
struct exception : std::runtime_error { exception(const char *msg) : std::runtime_error(msg) {} };
public:
- Style();
+ Style(Map &map);
void loadJSON(const uint8_t *const data);
@@ -63,6 +64,7 @@ private:
private:
+ Map &map;
std::set<std::shared_ptr<Source>> activeSources;
PropertyTransition defaultTransition;
bool initial_render_complete = false;
diff --git a/include/llmr/style/style_parser.hpp b/include/llmr/style/style_parser.hpp
index 10cd3d2e88..27dfd47579 100644
--- a/include/llmr/style/style_parser.hpp
+++ b/include/llmr/style/style_parser.hpp
@@ -17,6 +17,7 @@ namespace llmr {
enum class ClassID : uint32_t;
+class Map;
class StyleLayer;
class StyleLayerGroup;
@@ -24,6 +25,8 @@ class StyleParser {
public:
using JSVal = const rapidjson::Value&;
+ StyleParser(Map &map);
+
void parse(JSVal document);
std::shared_ptr<StyleLayerGroup> getLayers() {
@@ -92,6 +95,8 @@ private:
std::forward_list<Value> parseValues(JSVal values);
private:
+ Map &map;
+
std::unordered_map<std::string, const rapidjson::Value *> constants;
std::unordered_map<std::string, const std::shared_ptr<Source>> sources;
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);
diff --git a/src/style/style.cpp b/src/style/style.cpp
index 006376172c..2914489a1f 100644
--- a/src/style/style.cpp
+++ b/src/style/style.cpp
@@ -1,3 +1,4 @@
+#include <llmr/map/map.hpp>
#include <llmr/style/style.hpp>
#include <llmr/style/style_layer_group.hpp>
#include <llmr/style/style_parser.hpp>
@@ -12,7 +13,8 @@
namespace llmr {
-Style::Style() {
+Style::Style(Map &map)
+ : map(map) {
}
void Style::updateSources() {
@@ -107,7 +109,7 @@ void Style::loadJSON(const uint8_t *const data) {
throw error::style_parse(doc.GetErrorOffset(), doc.GetParseError());
}
- StyleParser parser;
+ StyleParser parser(map);
parser.parse(const_cast<const rapidjson::Document &>(doc));
layers = parser.getLayers();
diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp
index e33db355e8..e55c34808a 100644
--- a/src/style/style_parser.cpp
+++ b/src/style/style_parser.cpp
@@ -1,3 +1,4 @@
+#include <llmr/map/map.hpp>
#include <llmr/style/style_parser.hpp>
#include <llmr/style/style_layer_group.hpp>
#include <llmr/util/constants.hpp>
@@ -8,6 +9,10 @@ namespace llmr {
using JSVal = const rapidjson::Value&;
+StyleParser::StyleParser(Map &map)
+ : map(map) {
+}
+
void StyleParser::parse(JSVal document) {
if (document.HasMember("constants")) {
parseConstants(document["constants"]);
@@ -169,7 +174,7 @@ void StyleParser::parseSources(JSVal value) {
parseRenderProperty(itr->value, min_zoom, "minZoom");
parseRenderProperty(itr->value, max_zoom, "maxZoom");
- sources.emplace(std::move(name), std::make_shared<Source>(type, url, tile_size, min_zoom, max_zoom));
+ sources.emplace(std::move(name), std::make_shared<Source>(type, url, tile_size, min_zoom, max_zoom, map.getAccessToken()));
}
} else {
throw Style::exception("sources must be an object");