diff options
Diffstat (limited to 'platform/glfw/main.cpp')
-rw-r--r-- | platform/glfw/main.cpp | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index 38a41cbf18..fb7c2b4ffb 100644 --- a/platform/glfw/main.cpp +++ b/platform/glfw/main.cpp @@ -10,7 +10,7 @@ #include <mbgl/style/style.hpp> #include <mbgl/renderer/renderer.hpp> -#include <args/args.hxx> +#include <args.hxx> #include <csignal> #include <fstream> @@ -93,23 +93,26 @@ int main(int argc, char *argv[]) { GLFWView backend(fullscreen, benchmark); view = &backend; - mbgl::DefaultFileSource fileSource(cacheDB, "."); - 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"); - if (token == nullptr) { + std::string token(getenv("MAPBOX_ACCESS_TOKEN") ?: ""); + if (token.empty()) { mbgl::Log::Warning(mbgl::Event::Setup, "no access token set. mapbox.com tiles won't work."); - } else { - fileSource.setAccessToken(std::string(token)); + } + + mbgl::ResourceOptions resourceOptions; + resourceOptions.withCachePath(cacheDB).withAccessToken(token); + + auto fileSource = std::static_pointer_cast<mbgl::DefaultFileSource>(mbgl::FileSource::getSharedFileSource(resourceOptions)); + if (!settings.online) { + fileSource->setOnlineStatus(false); + mbgl::Log::Warning(mbgl::Event::Setup, "Application is offline. Press `O` to toggle online status."); } mbgl::ThreadPool threadPool(4); GLFWRendererFrontend rendererFrontend { std::make_unique<mbgl::Renderer>(backend, view->getPixelRatio(), threadPool), backend }; - mbgl::Map map(rendererFrontend, backend, view->getSize(), view->getPixelRatio(), fileSource, threadPool, mbgl::MapOptions()); + + mbgl::Map map(rendererFrontend, backend, threadPool, + mbgl::MapOptions().withSize(view->getSize()).withPixelRatio(view->getPixelRatio()), resourceOptions); backend.setMap(&map); @@ -124,9 +127,9 @@ int main(int argc, char *argv[]) { .withPitch(settings.pitch)); map.setDebug(mbgl::MapDebugOptions(settings.debug)); - view->setOnlineStatusCallback([&settings, &fileSource]() { + view->setOnlineStatusCallback([&settings, fileSource]() { settings.online = !settings.online; - fileSource.setOnlineStatus(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"); }); @@ -144,13 +147,13 @@ int main(int argc, char *argv[]) { mbgl::Log::Info(mbgl::Event::Setup, "Changed style to: %s", newStyle.name); }); - view->setPauseResumeCallback([&fileSource] () { + view->setPauseResumeCallback([fileSource] () { static bool isPaused = false; if (isPaused) { - fileSource.resume(); + fileSource->resume(); } else { - fileSource.pause(); + fileSource->pause(); } isPaused = !isPaused; |