summaryrefslogtreecommitdiff
path: root/platform/glfw/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/glfw/main.cpp')
-rw-r--r--platform/glfw/main.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 38a41cbf18..8288a009f2 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -93,23 +93,22 @@ 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) {
mbgl::Log::Warning(mbgl::Event::Setup, "no access token set. mapbox.com tiles won't work.");
- } else {
- fileSource.setAccessToken(std::string(token));
+ }
+
+ auto resourceOptions = mbgl::ResourceOptions().withCachePath(cacheDB).withAssetPath(".").withAccessToken(std::string(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, view->getSize(), view->getPixelRatio(), threadPool, mbgl::MapOptions(), resourceOptions);
backend.setMap(&map);
@@ -124,9 +123,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 +143,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;