read access token from environment

This commit is contained in:
Konstantin Käfer
2014-07-10 11:27:03 -07:00
parent 795496053b
commit 0d7b3462e9
5 changed files with 17 additions and 7 deletions

1
.gitignore vendored
View File

@@ -16,5 +16,4 @@
/src/shader/shaders_gl.cpp
/src/shader/shaders_gles2.cpp
/bin/style.bin.js
access_token.hpp
/test/fixtures/styles/index.html

View File

@@ -1 +0,0 @@
const char *mapbox_access_token = "<your access token here>";

View File

@@ -8,7 +8,6 @@
#include "../common/settings_json.hpp"
#include "../common/glfw_view.hpp"
#include "../access_token.hpp"
GLFWView *view = nullptr;
@@ -61,8 +60,15 @@ int main(int argc, char *argv[]) {
map.setAngle(settings.angle);
map.setDebug(settings.debug);
// Set access token if present
const char *token = getenv("MAPBOX_ACCESS_TOKEN");
if (token == nullptr) {
fprintf(stderr, "[WARNING] no access token set. mapbox.com tiles won't work.\n");
} else {
map.setAccessToken(std::string(token));
}
// Load style
map.setAccessToken(mapbox_access_token);
map.setStyleJSON(stylejson.str());
int ret = view->run();

View File

@@ -1,6 +1,5 @@
#include "../common/settings_nsuserdefaults.hpp"
#include "../common/glfw_view.hpp"
#include "../access_token.hpp"
#import <Foundation/Foundation.h>
@@ -14,8 +13,15 @@ int main() {
map.setAngle(settings.angle);
map.setDebug(settings.debug);
// Set access token if present
const char *token = getenv("MAPBOX_ACCESS_TOKEN");
if (token == nullptr) {
fprintf(stderr, "[WARNING] no access token set. mapbox.com tiles won't work.\n");
} else {
map.setAccessToken(std::string(token));
}
// Load style
map.setAccessToken(mapbox_access_token);
NSString *path = [[NSBundle mainBundle] pathForResource:@"style.min" ofType:@"js"];
NSString *json = [NSString stringWithContentsOfFile:path
encoding:[NSString defaultCStringEncoding]