Use API v4 and access tokens
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@
|
||||
/src/shader/shaders_gl.cpp
|
||||
/src/shader/shaders_gles2.cpp
|
||||
/bin/style.bin.js
|
||||
access_token.hpp
|
||||
|
||||
@@ -27,6 +27,8 @@ First off: if you hit problems during development try:
|
||||
|
||||
This will clear cached build data and update to the latest versions of dependencies.
|
||||
|
||||
The demo applications use Mapbox vector tiles, which require a Mapbox account and API access token. Obtain an access token on the [Mapbox account page](https://www.mapbox.com/account/apps/) and paste it in the `access_token.hpp` file before building the demo projects.
|
||||
|
||||
## OS X
|
||||
|
||||
First run:
|
||||
|
||||
1
access_token.hpp
Normal file
1
access_token.hpp
Normal file
@@ -0,0 +1 @@
|
||||
const char *mapbox_access_token = "<your access token here>";
|
||||
@@ -4,4 +4,10 @@
|
||||
#include "map/map.hpp"
|
||||
#include "map/view.hpp"
|
||||
|
||||
namespace llmr {
|
||||
|
||||
void setMapboxAccessToken(const std::string& token);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "../common/settings_json.hpp"
|
||||
#include "../common/glfw_view.hpp"
|
||||
#include "../access_token.hpp"
|
||||
|
||||
GLFWView *view = nullptr;
|
||||
|
||||
@@ -51,6 +52,8 @@ int main(int argc, char *argv[]) {
|
||||
std::stringstream stylejson;
|
||||
stylejson << stylefile.rdbuf();
|
||||
|
||||
llmr::setMapboxAccessToken(mapbox_access_token);
|
||||
|
||||
view = new GLFWView();
|
||||
llmr::Map map(*view);
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "../common/settings_nsuserdefaults.hpp"
|
||||
#include "../common/glfw_view.hpp"
|
||||
#include "../access_token.hpp"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
int main() {
|
||||
llmr::setMapboxAccessToken(mapbox_access_token);
|
||||
|
||||
GLFWView view;
|
||||
llmr::Map map(view);
|
||||
|
||||
|
||||
@@ -17,6 +17,12 @@
|
||||
|
||||
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)
|
||||
: type(type),
|
||||
@@ -28,7 +34,10 @@ Source::Source(SourceType type, const std::string &url,
|
||||
std::string Source::normalizeSourceURL(const std::string &url) {
|
||||
const std::string t = "mapbox://";
|
||||
if (url.compare(0, t.length(), t) == 0) {
|
||||
return std::string("http://api.tiles.mapbox.com/v3/") + url.substr(t.length()) + "/%d/%d/%d.vector.pbf";
|
||||
if (mapboxAccessToken.empty()) {
|
||||
throw std::runtime_error("You must provide a Mapbox API access token via llmr::setMapboxAccessToken()");
|
||||
}
|
||||
return std::string("https://api.tiles.mapbox.com/v4/") + url.substr(t.length()) + "/%d/%d/%d.vector.pbf?access_token=" + mapboxAccessToken;
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user