summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp10
-rw-r--r--include/mbgl/util/constants.hpp1
-rw-r--r--linux/main.cpp19
-rw-r--r--linux/mapboxgl-app.gypi3
-rw-r--r--platform/default/default_styles.cpp18
-rw-r--r--platform/default/default_styles.hpp17
-rw-r--r--platform/default/glfw_view.cpp8
7 files changed, 73 insertions, 3 deletions
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index 46baa70023..87710ff434 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -25,10 +25,16 @@ public:
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
static void onMouseMove(GLFWwindow *window, double x, double y);
+ // Callback called when the user presses the key mapped to style change.
+ // The expected action is to set a new style, different to the current one.
+ void setChangeStyleCallback(std::function<void()> callback);
+
void run();
void fps();
-public:
+ GLFWwindow *window = nullptr;
+
+private:
bool fullscreen = false;
double lastX = 0, lastY = 0;
@@ -38,7 +44,7 @@ public:
double lastClick = -1;
- GLFWwindow *window = nullptr;
+ std::function<void()> changeStyleCallback;
};
#endif
diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp
index e598806c20..bb5aad2af3 100644
--- a/include/mbgl/util/constants.hpp
+++ b/include/mbgl/util/constants.hpp
@@ -3,6 +3,7 @@
#include <cmath>
#include <string>
+#include <vector>
namespace mbgl {
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' : {
diff --git a/platform/default/default_styles.cpp b/platform/default/default_styles.cpp
new file mode 100644
index 0000000000..727636b3c4
--- /dev/null
+++ b/platform/default/default_styles.cpp
@@ -0,0 +1,18 @@
+#include "default_styles.hpp"
+
+namespace mbgl {
+namespace util {
+
+const std::vector<std::pair<std::string, std::string>> defaultStyles = {
+ { "asset://styles/mapbox-streets-v7.json", "Mapbox Streets" },
+ { "asset://styles/emerald-v7.json", "Emerald" },
+ { "asset://styles/light-v7.json", "Light" },
+ { "asset://styles/dark-v7.json", "Dark" },
+ { "asset://styles/bright-v7.json", "Bright" },
+ { "asset://styles/basic-v7.json", "Basic" },
+ { "asset://styles/outdoors-v7.json", "Outdoors" },
+ { "asset://styles/satellite-v7.json", "Satellite" },
+};
+
+} // end namespace util
+} // end namespace mbgl
diff --git a/platform/default/default_styles.hpp b/platform/default/default_styles.hpp
new file mode 100644
index 0000000000..dc10009305
--- /dev/null
+++ b/platform/default/default_styles.hpp
@@ -0,0 +1,17 @@
+#ifndef MBGL_PLATFORM_DEFAULT_STYLES
+#define MBGL_PLATFORM_DEFAULT_STYLES
+
+#include <vector>
+#include <string>
+
+namespace mbgl {
+namespace util {
+
+// A list of default styles, with the first string being the URL
+// and the second being the user-visible name.
+extern const std::vector<std::pair<std::string, std::string>> defaultStyles;
+
+} // end namespace util
+} // end namespace mbgl
+
+#endif
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 56aeaf30a3..bfe1882608 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -179,6 +179,10 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
if (!mods)
view->map->resetPosition();
break;
+ case GLFW_KEY_S:
+ if (view->changeStyleCallback)
+ view->changeStyleCallback();
+ break;
case GLFW_KEY_R:
if (!mods) {
view->map->setDefaultTransitionDuration(std::chrono::milliseconds(300));
@@ -306,6 +310,10 @@ void GLFWView::fps() {
}
}
+void GLFWView::setChangeStyleCallback(std::function<void()> callback) {
+ changeStyleCallback = callback;
+}
+
namespace mbgl {
namespace platform {