move to per-map access token
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 ↦
|
||||
std::set<std::shared_ptr<Source>> activeSources;
|
||||
PropertyTransition defaultTransition;
|
||||
bool initial_render_complete = false;
|
||||
|
||||
@@ -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 ↦
|
||||
|
||||
std::unordered_map<std::string, const rapidjson::Value *> constants;
|
||||
|
||||
std::unordered_map<std::string, const std::shared_ptr<Source>> sources;
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user