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.
This commit is contained in:
Thiago Marcos P. Santos
2015-05-06 15:22:43 +03:00
committed by Konstantin Käfer
parent 0d16110733
commit 168d7c4f17
7 changed files with 73 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
#include <mbgl/mbgl.hpp>
#include "../platform/default/default_styles.hpp"
#include <mbgl/util/std.hpp>
#include <mbgl/util/uv.hpp>
#include <mbgl/platform/log.hpp>
@@ -13,9 +14,12 @@
#include <fstream>
#include <sstream>
namespace {
std::unique_ptr<GLFWView> 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);