diff --git a/.travis.yml b/.travis.yml index 62f185b2c..ec877eb68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ env: global: - secure: "bG4YYWMfl9API0MSRgmOaJrlGLv06tRg9KJNawBieZvBJbITPpxVGJZT3/l/SEJ+Rl15e2dRex4k+MGQlmT2SqPQxTEYWv1qxNigKPPcla7IWeNmWWqW8uVvFjdglojgBOK2k/xErVQtA4zDfi3mwSXH4DKwquXWsoEKmX2SV7M=" - secure: "Cbvap9ubVKgjPe3hUhI6JGeDZzBXHpOG9RaYKh+SdoIPhKnlJiNOYm1egomi+e4uqJInlFKuVHTw7Ng9Cun6Zm0jIxpkSchv1GpsR7hmB3UGnGed19Dw8121FwuUaktN+4YnbVlsyd+u8EHD3+h58t4eELrLrZolM4rS7DL6caA=" + - secure: "RiBIBfVhhaMjU5ksuwJO3shdvG9FpinBjdSv4co9jg9171SR8edNriedHjVKSIeBhSGNmZmX+twS3dJS/By6tl/LKh9sTynA+ZAYYljkE7jn881B/gMrlYvdAA6og5KvkhV1/0iJWlhuZrMTkhpDR200iLgg3EWBhWjltzmDW/I=" before_install: - ./scripts/setup_travis.sh diff --git a/README.md b/README.md index 4ca8960be..e642468a3 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,18 @@ First off: if you hit problems during development try: This will clear cached build data and update to the latest versions of dependencies. +### Mapbox API access tokens + +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/). + ## OS X -First run: +in the Xcode project, click on the Target icon next to the Run/Stop button, and then "Edit Scheme". In the screen, add an environment variable with the name `MAPBOX_ACCESS_TOKEN` to the targets you want to run. + +![Setting the access token](https://cloud.githubusercontent.com/assets/52399/3543326/9e7cfbb8-0860-11e4-8def-3684a9028b61.png) + + +Run: make setup @@ -52,6 +61,8 @@ First, pull down the submodule(s): git submodule init git submodule update +Insert your access token into `MBXViewController.h`. + Then run: make setup @@ -64,6 +75,8 @@ Target devices: iPhone 4 and above (4S, 5, 5c, 5s) and iPad 2 and above (3, 4, m ## Ubuntu +Set the environment variable `MAPBOX_ACCESS_TOKEN` to your token. + Ensure you have git and other build essentials: sudo apt-get update diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index 1af6b3c54..defc1bef1 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 2937a8f69..f74624925 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, 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 getIDs() const; void updateClipIDs(const std::map &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 37a50485b..cfaba1898 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 ↦ std::set> 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 10cd3d2e8..27dfd4757 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 getLayers() { @@ -92,6 +95,8 @@ private: std::forward_list parseValues(JSVal values); private: + Map ↦ + std::unordered_map constants; std::unordered_map> sources; diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index 93615fe8a..565299b7a 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit 93615fe8a3123332d608eaae0a9b804059bd8581 +Subproject commit 565299b7a18286802f0c49560f34b36835cf06de diff --git a/linux/main.cpp b/linux/main.cpp index 25898fab2..889a246c2 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -60,6 +60,14 @@ 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.setStyleJSON(stylejson.str()); diff --git a/macosx/main.mm b/macosx/main.mm index 4c5da2f32..3b01df04e 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -13,6 +13,14 @@ 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 NSString *path = [[NSBundle mainBundle] pathForResource:@"style.min" ofType:@"js"]; NSString *json = [NSString stringWithContentsOfFile:path diff --git a/src/map/map.cpp b/src/map/map.cpp index fd13c340f..4b695fdfc 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