summaryrefslogtreecommitdiff
path: root/linux
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-05-06 15:22:43 +0300
committerKonstantin Käfer <mail@kkaefer.com>2015-05-07 11:01:15 +0200
commit168d7c4f171b44b0e3cd4ef78bc4e6b5e8181953 (patch)
tree9e3af3663f12a58071151e9405c37d04a6ab7976 /linux
parent0d16110733a38b4e1510dce15d29c0244e7b69b6 (diff)
downloadqtlocation-mapboxgl-168d7c4f171b44b0e3cd4ef78bc4e6b5e8181953.tar.gz
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.
Diffstat (limited to 'linux')
-rw-r--r--linux/main.cpp19
-rw-r--r--linux/mapboxgl-app.gypi3
2 files changed, 21 insertions, 1 deletions
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 <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);
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' : {