From 168d7c4f171b44b0e3cd4ef78bc4e6b5e8181953 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 6 May 2015 15:22:43 +0300 Subject: Add style change functionality to the Linux test app Makes the life of people using Linux as development environment way easier. Just press 's' to cycle through 3 different styles. --- linux/main.cpp | 19 ++++++++++++++++++- linux/mapboxgl-app.gypi | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'linux') diff --git a/linux/main.cpp b/linux/main.cpp index 738bbfb0aa..2361c996d6 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -1,4 +1,5 @@ #include +#include "../platform/default/default_styles.hpp" #include #include #include @@ -13,9 +14,12 @@ #include #include +namespace { std::unique_ptr view; +} + void quit_handler(int) { if (view) { mbgl::Log::Info(mbgl::Event::Setup, "waiting for quit..."); @@ -75,6 +79,19 @@ int main(int argc, char *argv[]) { map.setBearing(settings.bearing); map.setDebug(settings.debug); + view->setChangeStyleCallback([&map] () { + static uint8_t currentStyleIndex; + + if (++currentStyleIndex == mbgl::util::defaultStyles.size()) { + currentStyleIndex = 0; + } + + const auto& newStyle = mbgl::util::defaultStyles[currentStyleIndex]; + map.setStyleURL(newStyle.first); + + mbgl::Log::Info(mbgl::Event::Setup, std::string("Changed style to: ") + newStyle.first); + }); + // Set access token if present const char *token = getenv("MAPBOX_ACCESS_TOKEN"); if (token == nullptr) { @@ -85,7 +102,7 @@ int main(int argc, char *argv[]) { // Load style if (style.empty()) { - style = std::string("asset://") + std::string("styles/bright-v7.json"); + style = mbgl::util::defaultStyles.front().first; } map.setStyleURL(style); diff --git a/linux/mapboxgl-app.gypi b/linux/mapboxgl-app.gypi index ec3c5d5fec..35ca322e29 100644 --- a/linux/mapboxgl-app.gypi +++ b/linux/mapboxgl-app.gypi @@ -20,8 +20,11 @@ 'sources': [ 'main.cpp', '../platform/default/settings_json.cpp', + '../platform/default/glfw_view.hpp', '../platform/default/glfw_view.cpp', '../platform/default/log_stderr.cpp', + '../platform/default/default_styles.hpp', + '../platform/default/default_styles.cpp', ], 'variables' : { -- cgit v1.2.1