diff options
-rw-r--r-- | platform/glfw/glfw_view.cpp | 4 | ||||
-rw-r--r-- | platform/glfw/glfw_view.hpp | 5 | ||||
-rw-r--r-- | platform/glfw/main.cpp | 13 | ||||
-rw-r--r-- | platform/glfw/settings_json.cpp | 3 | ||||
-rw-r--r-- | platform/glfw/settings_json.hpp | 1 |
5 files changed, 26 insertions, 0 deletions
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 784e908878..d591f897e0 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -110,6 +110,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_) printf("- Press `N` to reset north\n"); printf("- Press `R` to enable the route demo\n"); printf("- Press `E` to insert an example building extrusion layer\n"); + printf("- Press `O` to toggle online connectivity\n"); printf("- Press `Z` to cycle through north orientations\n"); printf("- Prezz `X` to cycle through the viewport modes\n"); printf("- Press `A` to cycle through Mapbox offices in the world + dateline monument\n"); @@ -176,6 +177,9 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, if (!mods) view->map->resetPosition(); break; + case GLFW_KEY_O: + view->onlineStatusCallback(); + break; case GLFW_KEY_S: if (view->changeStyleCallback) view->changeStyleCallback(); diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp index 42d287142d..d3257f6b9a 100644 --- a/platform/glfw/glfw_view.hpp +++ b/platform/glfw/glfw_view.hpp @@ -28,6 +28,10 @@ public: pauseResumeCallback = callback; }; + void setOnlineStatusCallback(std::function<void()> callback) { + onlineStatusCallback = callback; + } + void setShouldClose(); void setWindowTitle(const std::string&); @@ -111,6 +115,7 @@ private: std::function<void()> changeStyleCallback; std::function<void()> pauseResumeCallback; + std::function<void()> onlineStatusCallback; std::function<void(mbgl::Map*)> animateRouteCallback; mbgl::util::RunLoop runLoop; diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index 76c843c953..dadd88c705 100644 --- a/platform/glfw/main.cpp +++ b/platform/glfw/main.cpp @@ -44,6 +44,7 @@ int main(int argc, char *argv[]) { const struct option long_options[] = { {"fullscreen", no_argument, nullptr, 'f'}, {"benchmark", no_argument, nullptr, 'b'}, + {"offline", no_argument, nullptr, 'o'}, {"style", required_argument, nullptr, 's'}, {"lon", required_argument, nullptr, 'x'}, {"lat", required_argument, nullptr, 'y'}, @@ -65,6 +66,9 @@ int main(int argc, char *argv[]) { case 'b': benchmark = true; break; + case 'o': + settings.online = false; + break; case 's': style = std::string(optarg); break; @@ -104,6 +108,10 @@ int main(int argc, char *argv[]) { view = &backend; mbgl::DefaultFileSource fileSource("/tmp/mbgl-cache.db", "."); + if (!settings.online) { + fileSource.setOnlineStatus(false); + mbgl::Log::Warning(mbgl::Event::Setup, "Application is offline. Press `O` to toggle online status."); + } // Set access token if present const char *token = getenv("MAPBOX_ACCESS_TOKEN"); @@ -128,6 +136,11 @@ int main(int argc, char *argv[]) { map.setPitch(settings.pitch); map.setDebug(mbgl::MapDebugOptions(settings.debug)); + view->setOnlineStatusCallback([&settings, &fileSource]() { + settings.online = !settings.online; + fileSource.setOnlineStatus(settings.online); + mbgl::Log::Info(mbgl::Event::Setup, "Application is %s. Press `O` to toggle online status.", settings.online ? "online" : "offline"); + }); view->setChangeStyleCallback([&map] () { static uint8_t currentStyleIndex; diff --git a/platform/glfw/settings_json.cpp b/platform/glfw/settings_json.cpp index 2ba1038dc7..5b6aa4e0da 100644 --- a/platform/glfw/settings_json.cpp +++ b/platform/glfw/settings_json.cpp @@ -14,6 +14,7 @@ void Settings_JSON::load() { file >> bearing; file >> pitch; file >> debug; + file >> online; } } @@ -26,6 +27,7 @@ void Settings_JSON::save() { file << bearing << std::endl; file << pitch << std::endl; file << debug << std::endl; + file << online << std::endl; } } @@ -36,6 +38,7 @@ void Settings_JSON::clear() { bearing = 0; pitch = 0; debug = 0; + online = true; } } // namespace mbgl diff --git a/platform/glfw/settings_json.hpp b/platform/glfw/settings_json.hpp index eb23b28bc8..49ea00e3e1 100644 --- a/platform/glfw/settings_json.hpp +++ b/platform/glfw/settings_json.hpp @@ -19,6 +19,7 @@ public: double pitch = 0; EnumType debug = 0; + bool online = true; }; } // namespace mbgl |